VirtualBox - An x86 and AMD64/Intel64 virtualization product for enterprise as well as home use

Mouse click lost in guest

Situation :

Details :

Solution :

  1. ps aux | grep [d]raganddrop
    kevin    31488  0.0  0.0  50364   332 ?        S    08:53   0:00 /usr/bin/VBoxClient --draganddrop
    kevin    31489  0.1  0.0 117064  2184 ?        Sl   08:53   0:15 /usr/bin/VBoxClient --draganddrop
  2. kill -1 31489
    • I don't know which one of both should be killed : the first or the other ?
    • Anyway, after that, both processes disappeared.
  3. The mouse click is back

How to connect a virtual machine to the Internet using a smartphone as a USB modem ?

Situation :

On a physical Debian machine, this is very easy :
  1. plug the USB cable
  2. configure the smartphone as a USB modem
  3. NetworkManager will do the rest of the job
  4. after a few seconds, ip a will list a new network interface
  5. enjoy !!!
But on a virtual machine, this is different : each time I try to "virtually" plug the USB cable to the virtual machine with the Devices | USB devices menu, I get an error. Even trying to fiddle with the USB filter rules has not succeeded so far .

Details :

Since it is (apparently) no possible to plug a USB modem to a VM, let's workaround this by plugin the USB modem to the host, and share that connection to the guest.

Solution :

  1. plug the USB cable
  2. configure the smartphone as a USB modem
  3. in its Network connections page, Windows should list a Remote NDIS based Internet Sharing Device
  4. if not already enabled : enable it
  5. configure the VM with a NAT network connection type
  6. enjoy !!!

How to start a headless guest ?

To do so :
from the command line :
"C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" startvm "C:\Users\bob\VirtualBox VMs\myVm\myVm.vbox" --type headless
from the VirtualBox virtual machines manager :
  1. in the list of available VMs, select the one you wish to start
  2. in the top row (with big icons), you'll see a little black "down arrow" next to the Start button (green right arrow)
  3. pick the startup mode you want
Screenshots of the console contents will still be visible in the VirtualBox virtual machines manager.

Can't mount shared directories + modprobe vboxsf failed

Situation :

This is a weird situation where, after starting my guest Debian VM, I don't have access to the shared directories anymore. I've not been able to find the root cause, but in the process of trying to fix this, I ended up upgrading
  1. VirtualBox itself
  2. the Extension Pack
  3. the Guest Additions. This is where I got this modprobe vboxsf failed error message.

Solution :

Long story short, if you've upgraded everything, you've already done most of the work. The modprobe vboxsf failed error message is said to be mostly cosmetic, and can be ignored and "solved" by a reboot.

How to delete + purge a virtual disk ?

Situation :

An obvious preliminary to all this is to shut down the virtual machine using the virtual disk you're about to remove.

Unplugging a virtual disk from a virtual machine is easily done within the virtual machine Configuration | Storage screens but :

Solution :

Proper way to delete + purge a virtual disk image file (source) :

This is performed on the host side.
  1. cd "C:\Program Files\Oracle\VirtualBox"
  2. vboxmanage list hdds
    UUID:		dfea5b73-2683-4d6a-9965-a34a51235162
    Parent UUID:	base
    State:		created
    Type:		normal (base)
    Location:	C:\Users\kevin\VirtualBox VMs\myVirtualMachine\NewVirtualDisk1.vdi
    Storage format:	VDI
    Capacity:	100 MBytes
    Encryption:	disabled
    Note the UUID of the disk you want to purge
  3. vboxmanage closemedium disk dfea5b73-2683-4d6a-9965-a34a51235162 --delete

Alternate solution :

  1. open the VirtualBox GUI
  2. File | Media manager
  3. pick the virtual disk to remove then Delete

How to create a new virtual disk ?

After you have stopped the target virtual machine, it all takes place in the VirtualBox GUI :
  1. open the virtual machine Configuration panel
  2. select the Storage category
  3. select the IDE or SATA controller, depending on the type of disk you want to create
  4. click the + hard drive icon
  5. follow the on-screen instructions

Once the new disk has been created, you can boot the virtual machine, log in, and confirm the disk is here with lsblk.

How to fix the audio in Debian guest ?

Situation :

Debian Stretch guest in Windows 7 host, both running together for months. I get crackling sound from the Debian guest whatever application I play sound with.

Details :

There's been a VirtualBox update, lately...

Solution :

Here are a few things to check (from obvious to technical ) :
  1. have you considered playing medias directly in the host system ? This is more a workaround than a solution (when possible), but it may do the trick and save hours of Googling
  2. make sure the volume is not muted on the host side
  3. make sure the volume is not muted on the guest side
  4. play a dummy sound on the guest : aplay /usr/share/sounds/alsa/Front_Center.wav
    1. shutdown the guest machine
    2. open the VirtualBox VM manager
    3. pick the VM | Configuration | Sound tab
    4. toggle the Audio controller from Intel audio HD to ICH AC97
    5. start the guest machine
    6. should be better now
  5. if still not ok (experimental) :
    kill -15 $(pgrep pulseaudio) && systemctl restart alsa-state.service; systemctl restart alsa-restore.service
    	==> :-/
    I'm afraid everything is fine on guest side, and things go wrong between guest/host :-(
    on host side, give higher priority to 'VboxSVC.exe' process
    	==> testing...
    	==> Virtualbox crashed 1 hour after that :-D (at least, that was expected!!!)
    after rebooting host + guest : untick "enable audio input" in VM settings
    	==> nope :-(

Can not start VirtualBox on Debian Stretch : Kernel driver not installed (rc=-1908)

Situation :

When trying to start a VM, I get the error message :
Kernel driver not installed (rc=-1908)

The VirtualBox Linux kernel driver (vboxdrv) is either not loaded or there is a permission problem with /dev/vboxdrv. Please reinstall the kernel module by executing

'/etc/init.d/vboxdrv setup'

as root. If it is available in your distribution, you should install the DKMS package first. This package keeps track of Linux kernel changes and recompiles the vboxdrv kernel module if necessary.

Details :

This happened after upgrading Debian from Jessie (8) (where everything worked fine) to Stretch (9).

Solution :

Basically, all you have to do is to install an updated version of VirtualBox. To do so, as root :
  1. Define a new software source :
    echo 'deb stretch contrib' >> /etc/apt/sources.list.d/virtualbox.list
  2. Get the Oracle VirtualBox public key :
    curl -O
  3. Register it :
    apt-key add oracle_vbox_2016.asc
  4. Install the new version :
    apt update && apt install virtualbox-5.1
After this, when trying to start one of my VMs, I got an error message saying it couldn't be started because of the "USB 2 subsystem" which was part of the snapshot, but currently not available and blah blah blah (can't remember the full error message and didn't note it).
What I did (now it works) :
  1. start the VirtualBox manager (the GUI listing existing VMs, not a VM)
  2. it offered to download + install an upgrade of the "VirtualBox guest additions" (4.3.x to 5.1.x). Accept + install
  3. now the VMs can start \o/

The VirtualBox kernel service is not running

Situation :

When booting my Debian virtual machine, I get a desktop notification :
The VirtualBox kernel service is not running. Exiting.

Details :

Not sure if / how this is related, but I had a kernel update lately...

Solution :

The quick (magic!) solution is to boot the virtual machine with the VirtualBox Guest Additions CD inserted in the virtual CD drive.

But since the VirtualBox Guest Additions CD is there, why not seize the opportunity of upgrading ?

  1. shutdown the virtual machine
  2. eject any CD found in the virtual CD drive
  3. get the latest version of the VirtualBox Guest Additions CD :
    1. browse to the latest version directory
    2. download VBoxGuestAdditions_x.y.z.iso
  4. insert the VirtualBox Guest Additions CD into the virtual machine's CD drive
  5. boot the virtual machine (at this step, for an unknown reason, the error message should already not appear)
  6. make sure you have installed the kernel headers
  7. as root :
    1. mount the CD :
      mount /media/cdrom
    2. launch install :
      cd /media/cdrom && sh
      This will pop a new terminal window :
      Verifying archive integrity... All good.
      Uncompressing VirtualBox 5.2.18 Guest Additions for Linux........
      VirtualBox Guest Additions installer
      Removing installed version 5.2.16 of VirtualBox Guest Additions...
      Copying additional installer modules ...
      Installing additional modules ...
      VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while.
      VirtualBox Guest Additions: Running kernel modules will not be replaced until the system is restarted
      VirtualBox Guest Additions: Starting.
      VirtualBox Guest Additions: modprobe vboxsf failed		if you see this, read that
      Press Return to close this window...
    3. unmount the CD :
      cd && umount /media/cdrom
  8. eject the disk image from the virtual CD drive
  9. enjoy

How to enlarge a virtual machine disk ?

The concept :

The solution described below is basically to :
  1. put the VM in a clean state (stopped, merge snapshots, backup image file(s))
  2. enlarge the virtual disk with VirtualBox commands
  3. boot the VM, create a new partition on the added storage space
  4. change this partition into a physical volume
  5. extend the volume group onto this new physical volume
  6. extend logical volume(s) as needed
  7. extend filesystem(s)
An alternate solution (not tested, not described here) would be to :
  1. create a new virtual disk with VirtualBox commands
  2. plug it into the VM. This would become /dev/sdb
  3. add this disk to a volume group
  4. extend volume group(s) + logical volume(s) + filesystem(s)

Description :

  1. on the guest side :
    1. the "before" status :
      df -h | grep '/dev/mapper'
      /dev/mapper/caramba--vg-root	8.2G	5.4G	2.4G	70%	/		this is getting tight
      /dev/mapper/caramba--vg-home	24G	1014M	22G	5%	/home
      /dev/mapper/caramba--vg-tmp	360M	2.1M	335M	1%	/tmp
      /dev/mapper/caramba--vg-var	2.7G	549M	2.0G	22%	/var
      PV		VG		Fmt	Attr	PSize	PFree
      /dev/sda5	caramba-vg	lvm2	a--	39.76g	0
      fdisk -l
      Disk /dev/sda: 40 GiB, 53687091200 bytes, 104857600 sectors
      Units: sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disklabel type: dos
      Disk identifier: 0x26504200
      Device		Boot	Start	End		Sectors		Size	Id	Type
      /dev/sda1	*	2048	499711		497664		243M	83	Linux
      /dev/sda2		501758	83884031	83382274	39.8G	5	Extended
      /dev/sda5		501760	83884031	83382272	39.8G	8e	Linux LVM	this is the one I'd like to enlarge
    2. Turn the guest system completely OFF (no hibernate / suspend / whatever mode)
  2. on the host side :
    1. backup vdi + snapshots (paranoid mode=activated)
    2. merge all snapshots (not sure this is required but just in case...)
    3. backup the vdi that has the snapshots merged (paranoid level=maximum)
    4. Enlarge the virtual machine storage (source) :
      "C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" modifyhd "C:\Users\kevin\VirtualBox VMs\Debian\Debian.vdi" --resize totalStorageSizeInMb
      This should be done in only a few seconds.
    5. At this point, this is over regarding VirtualBox, the remaining tasks are all guest-related.
  3. on the guest side :
    1. Some extra space should be visible to root :
      fdisk -l /dev/sda
      Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 sectors
    2. Then check for unpartitioned space :
      fdisk /dev/sda + F
      Unpartitioned space /dev/sda: 40 GiB, 42950721536 bytes, 83888128 sectors
      Units: sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      Start		End		Sectors		Size
      83884032	167772159	83888128	40G
    3. Without leaving fdisk, create new partition on this new space. On my specific/particular (?) case, I had to create a primary partition, and specify start/end sectors :
      Command (m for help): n
      Partition type
      	p	primary (1 primary, 1 extended, 2 free)
      	l	logical (numbered from 5)
      Select (default p): p
      Partition number (3,4, default 3):
      First sector (499712-167772159, default 499712): 83884032
      Last sector, +sectors or +size{K,M,G,T,P} (83884032-167772159, default 167772159): 
      Created a new partition 3 of type 'Linux' and of size 40 GiB.
    4. Check :
      Command (m for help): p
      Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 sectors
      Units: sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disklabel type: dos
      Disk identifier: 0x26504200
      Device	Boot	Start		End		Sectors		Size	Id	Type
      /dev/sda1	*	2048	499711		497664		243M	83	Linux
      /dev/sda2	501758		83884031	83382274	39.8G	5	Extended
      /dev/sda3	83884032	167772159	83888128	40G	83	Linux
      /dev/sda5	501760		83884031	83382272	39.8G	8e	Linux LVM
      Partition table entries are not in disk order.		true, but mainly cosmetic. Can be left as-is.
    5. Write the altered partition table and make the kernel aware of it :
      Command (m for help): w
      The partition table has been altered.
      Calling ioctl() to re-read partition table.
      Re-reading the partition table failed.: Device or resource busy
      The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).
    6. So now, I have /dev/sda3, with 40GB available. Let's make this a physical volume :
      pvcreate /dev/sda3
      Physical volume "/dev/sda3" successfully created.
    7. Check :
      PV		VG		Fmt	Attr	PSize	PFree
      /dev/sda3			lvm2	---	40.00g	40.00g	here it is!
      /dev/sda5	caramba-vg	lvm2	a--	39.76g	0
    8. We'll have to append it to an existing volume group. Which one ?
      VG		#PV	#LV	#SN	Attr	VSize	VFree
      caramba-vg	1	5	0	wz--n-	39.76g	0	only 1 VG, so no big trouble
    9. Time to enlarge things (using all of the 40 extra GiB) :
      vgextend caramba-vg /dev/sda3
      Volume group "caramba-vg" successfully extended
    10. Check :
      VG		#PV	#LV	#SN	Attr	VSize	VFree
      caramba-vg	2	5	0	wz--n-	79.76g	40.00g
    11. Now we can extend the logical volume in need for GB :
      df -h | grep '/dev/mapper'
      /dev/mapper/caramba--vg-root		8.2G	5.4G	2.4G	70%	/		this one
      /dev/mapper/caramba--vg-home		24G	1014M	22G	5%	/home
      /dev/mapper/caramba--vg-tmp		360M	2.1M	335M	1%	/tmp
      /dev/mapper/caramba--vg-var		2.7G	549M	2.0G	22%	/var
    12. Let's enlarge things (again!) :
      lvextend -L 20G -r /dev/mapper/caramba--vg-root
      Size of logical volume caramba-vg/root changed from 8.38 GiB (2145 extents) to 20.00 GiB (5120 extents).
      Logical volume caramba-vg/root successfully resized.
      resize2fs 1.43.3 (04-Sep-2016)
      Filesystem at /dev/mapper/caramba--vg-root is mounted on /; on-line resizing required
      old_desc_blocks = 1, new_desc_blocks = 2
      The filesystem on /dev/mapper/caramba--vg-root is now 5242880 (4k) blocks long.
    13. Check :
      df -h | grep '/dev/mapper'
      /dev/mapper/caramba--vg-root	20G	5.4G	14G	29%	/
      /dev/mapper/caramba--vg-home	24G 1017M	22G	5%	/home
      /dev/mapper/caramba--vg-tmp	360M	2.1M	335M	1%	/tmp
      /dev/mapper/caramba--vg-var	2.7G	549M	2.0G	22%	/var
    14. I love it when a plan comes together

intel_rapl: no valid rapl domains found in package 0 while booting a Debian VM

Situation :

While booting a Debian VM, I get intel_rapl: no valid rapl domains found in package 0 messages and the boot process stalls.

Details :

RAPL is related to power managment. It makes sense that it is not available on a virtual machine (source).

Solution :

Many different solutions are available on the Internet :
Disable 3D acceleration in VM configuration
No effect
Enable PAE/NX in VM configuration
No effect
echo 'blacklist intel_rapl' > /etc/modprobe.d/modprobe.conf, then reboot (source)
OK so far.

Read only file system when trying to create a symlink in a shared directory

Situation :

A Windows 7 host, running a Debian guest. A directory is shared between both and works fine : I can read and write there from both operating systems. But if, on the Debian side, I try to create a symlink within the shared directory, I get a Read only file system error. Which obviously is NOT read only since I can touch and rm there. So what's going on ?

Solution :

Well, I forgot the shared directory actually lives on the host operating system side, on a NTFS filesystem, which doesn't support ext4 symbolic links...

Can't log in my guest Debian despite having the right password

Situation :

A Windows 7 host, running a Debian guest. Debian boots normally, then displays the graphical login window. After I've input my login and password :
  1. I get no Wrong password message
  2. The screen turns black and flickers as if the graphical session was being opened normally
  3. Then I get the login window again

Solution :

There are several causes to this behaviour. In my case, ~/.Xauthority was owned by root (), so I just had to delete it. And enjoy .

It's even possible that this has nothing to do with VirtualBox...

Permission denied on a shared directory

Situation :

VirtualBox is installed on a Windows host box, and runs a Debian guest machine. Shared directories are configured and mounted as expected, except that only root is allowed in there .

Solution :

Add the non-root user willing to gain access to the share into the vboxsf group :
adduser bob vboxsf

New permissions will be effective only after opening a new shell (for CLI access) or after a new login (for GUI access).

How to update the virtual machines storage directory ?

When dealing with the virtual machines storage directory, we're talking about this :


To change it for the future machines you'll create, you just have to execute : File | Parameters | General | Default machines directory. This has no effect on existing machines.

To do so for the existing machines, there is the clean method, and the QnD one :

  1. Stop all virtual machines
  2. Exit VirtualBox
  3. Update paths in ~/.VirtualBox/VirtualBox.html
  4. Enjoy

USB unavailable, VirtualBox complains : Failed to access the USB subsystem; Could not load the Host USB Proxy Service

Situation :

VirtualBox complains :
Failed to access the USB subsystem
Could not load the Host USB Proxy Service (VERR_FILE_NOT_FOUND).
The service might not be installed on the host computer
Or :
Erreur d'accès au sous-système USB.
Le service de relais de périphériques USB n'a pas pû être activé (erreur VERR_FILE_NOT_FOUND).
Il se peut que le service ne soit pas installé sur l'ordinateur hôte.

Solution :

  1. as root :
    usermod -aG vboxusers bob
  2. log out and in again to reload groups data

How to install the Extension Pack and Guest Additions ?

  • The Extension Pack is mandatory to enable extra features such as USB 2.0, dual screen, ...
  • When upgrading VirtualBox, there are 2 things to upgrade / reinstall :
    1. the Extension Pack on the host side
      • nothing prevents from installing this on the guest side, but it looks useless
      • After upgrading VirtualBox itself, the Extension Pack upgrade is generally offered at the next start of the application
    2. Guest Additions on the guest side

On the host side : the Extension Pack

As anybody having administrative rights on the host operating system (root / Administrator) :
  1. virtualboxVersion='5.1.6'; wget$virtualboxVersion/Oracle_VM_VirtualBox_Extension_Pack-${virtualboxVersion}.vbox-extpack
  2. It _may_ be possible to install it graphically :
    1. File | Preferences | Extensions | "Add" icon
    2. pick file | Ok | Upgrade | Agree
    3. Then you'll be prompted for the root / Administrator password, which will fail on GNU/Linux boxes with locked root account.
      Use the CLI install command below
    vboxmanage extpack install --replace Oracle_VM_VirtualBox_Extension_Pack-${virtualboxVersion}.vbox-extpack

On the guest side : Guest Additions

  1. download the .iso image :
  2. install !

How to clone a virtual machine ?

Solution :

  1. cd path/to/directory/containing/virtual/machines/images
  2. vboxmanage clonehd original.vdi clone.vdi
  3. Then some minor changes (?) to do in the GUI

Alternate solution :

In the GUI, find the machine to clone from the list, then Rclick | Clone.

How to perform a P2V ?

  1. dd if=/dev/sdc of=/path/to/diskImage.dd
  2. vboxmanage convertfromraw diskImage.dd diskImage.vdi --format VDI
  3. rm diskImage.dd