Difference between revisions of "VirtualBox"

From ArchWiki
Jump to: navigation, search
(Hosts running a custom kernel: Be clearer about dkms and auto updates of VBox module at boot.)
(Reorganize introduction and be more complete)
Line 12: Line 12:
{{Article summary start}}
{{Article summary start}}
{{Article summary text|This article is about basic usage of VirtualBox, including running the VirtualBox software within an Arch ''host'', and running an Arch ''guest'' inside a VirtualBox virtual machine.}}
{{Article summary text|This article is about basic usage of VirtualBox, including running the VirtualBox software within an ArchLinux ''host'', and running an ArchLinux ''guest'' inside a VirtualBox virtual machine.}}
{{Article summary heading|Required software}}
{{Article summary heading|Required software}}
{{Article summary link|VirtualBox|https://www.virtualbox.org}}
{{Article summary link|VirtualBox|https://www.virtualbox.org}}
Line 23: Line 23:
{{Article summary end}}
{{Article summary end}}
'''VirtualBox''' is a virtual PC emulator like [[VMware]]. It is in constant development and new features are implemented all the time. e.g. version 2.2 introduced OpenGL 3D acceleration support for Linux and Solaris guests. It has a [[Qt]] GUI interface, as well as headless and [[Wikipedia:SDL|SDL]] command line tools for managing and running virtual machines. It includes ''guest additions'' for some guest operating systems, which integrate functions of the guest and host systems, including sharing files, the clipboard, video acceleration and a “seamless” window integration mode.
'''VirtualBox''' is a [[Wikipedia:Hypervisor|hypervisor]] used to run operating systems in a special environment, called virtual machine, on top of the existing operating system. It is in constant development and new features are implemented continuously. It comes with a [[Qt]] GUI interface, as well as headless and [[Wikipedia:SDL|SDL]] command line tools for managing and running virtual machines.
In order to integrate functions of the host system to the guests, including shared folders and clipboard, video acceleration and a "seamless" window integration mode, ''guest additions'' are provided for some guest operating systems.

Revision as of 16:33, 30 September 2013

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary link Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end

VirtualBox is a hypervisor used to run operating systems in a special environment, called virtual machine, on top of the existing operating system. It is in constant development and new features are implemented continuously. It comes with a Qt GUI interface, as well as headless and SDL command line tools for managing and running virtual machines.

In order to integrate functions of the host system to the guests, including shared folders and clipboard, video acceleration and a "seamless" window integration mode, guest additions are provided for some guest operating systems.


Installation on host

The basic GPL-licensed VirtualBox suite can be installed with the virtualbox package from the official repositories.

The virtualbox-host-modules package, which contains the precompiled modules for the stock archlinux kernel, should be installed with it. If you are using the linux-lts kernel you should also install the virtualbox-host-modules-lts package. For custom kernels, read the section below.

In order to use the graphical interface, based on Qt (VirtualBox command), you will also need to install the qt4 package. This is not required for the simpler SDL-only GUI (VBoxSDL command) nor for the VBoxHeadless command.

Hosts running a custom kernel

VirtualBox works fine with custom kernels such as Linux-ck without the need to keep any of the official ArchLinux kernel packages on the system. As these official kernel packages are dependencies of virtualbox-host-modules, if you want to prevent pacman from installing these unneeded packages, please install the virtualbox-host-dkms package instead. The latter comes bundled with the source of the VirtualBox kernel modules that will be used to generate these modules for your kernel.

Once virtualbox-host-dkms is installed, simply generate the kernel modules for your custom kernel by running the following command structure:

# dkms install vboxhost/<virtualbox-host-source version> -k <your custom kernel's version>/<your architecture>

or by using this all-in-one instead:

# dkms install vboxhost/$(pacman -Q virtualbox|awk {'print $2'}|sed 's/\-.\+//') -k $(uname -rm|sed 's/\ /\//')
Note: If you are getting an error like Your kernel headers for kernel <your custom kernel's version> cannot be found at/usr/lib/modules/<your custom kernel's version>/build or /usr/lib/modules/<your custom kernel's version>/source, you're probably missing linux-headers.

After the VirtualBox module has been created, load it with:

# modprobe vboxdrv

To automatically recompile/reload the VirtualBox module when your kernel got upgraded, you can enable the dkms.service with:

# systemctl enable dkms.service

If you don't have the dkms.service enabled while your Linux kernel (official or custom one) is being updated, your VirtualBox module won't be updated and might not work with your new kernel version any more. If you want to automatically recompile/update your VirtualBox module at boot time after a new version of the kernel has been installed, you can use an initramfs hook that will automatically call the dkms command described above.

To enable that feature, install the vboxhost-hookAUR package from the AUR and add vboxhost to your HOOKS array in /etc/mkinitcpio.conf. Then make sure your linux-headers are updated first with:

# pacman -Sy linux-headers && pacman -Su
Note: Like dkms, the vboxhost hook will tell you if anything goes wrong during the recompilation of the VirtualBox module.


Add usernames to the vboxusers group

Add the desired usernames to the vboxusers group. Everything may work fine without this step but shared folders and possibly some other optional stuffs require it to work. The new group does not automatically apply to existing sessions; the user has to log in again or start a new environment with a command like newgrp or sudo -u $USER -s.

# gpasswd -a $USER vboxusers

Loading Kernel Modules

VirtualBox running on Linux uses its own kernel modules, including a mandatory module named vboxdrv, which must be loaded before virtual machines can run. It can be automatically loaded when ArchLinux starts up, or it can be loaded manually when necessary.

To load the module manually:

# modprobe vboxdrv

To load the VirtualBox driver at startup, create a *.conf file (e.g. virtualbox.conf) in /etc/modules-load.d that contains all modules that should be loaded:

Note: In order to avoid no such file or directory error when loading vboxdrv, you may need to update the kernel modules db with depmod -a.

To start the VirtualBox graphical manager:

$ VirtualBox

To ensure full functionality of bridged networking, ensure that the vboxnetadp, vboxnetflt and vboxpci kernel modules are loaded as well as the net-tools package.

Guest additions disc

The virtualbox package also suggests installing virtualbox-guest-iso on the ArchLinux host running VirtualBox. It is a disc image that can be used to install the guest additions onto guest systems. Make it available to the running guest by going to Devices and clicking Install Guest Additions... Host+D, then run the guest additions installation from inside the guest.

Booting a live disc

Click the New button to create a new virtual environment. Name it appropriately and select Operating System type and version. Select base memory size (note: most operating systems will need at least 512 MB to function properly). Create a new hard disk image (a hard disk image is a file that will contain the operating system's filesystem and files).

When the new image has been created, click Settings, then CD/DVD-ROM, check Mount CD/DVD Drive then select an ISO image.

Starting virtual machines with a service

See Systemd/Services#VirtualBox virtual machines for details on how to setup a systemd service for each virtual machine.

Advanced setup

See VirtualBox Extras for advanced configuration.

Arch Linux as a guest in a Virtual Machine

Installing Arch under VirtualBox is straightforward, and additions should be installed through pacman (following the instructions below), and not through the "Install Guest Additions" menu item in VirtualBox on your host machine, nor from a mounted ISO image.

Install the Guest Additions

Install the virtualbox-guest-utils package. Manually load the modules with:

# modprobe -a vboxguest vboxsf vboxvideo

Create a *.conf file (e.g. virtualbox.conf) in /etc/modules-load.d/ with these lines:


Add the following line to the top of ~/.xinitrc above any exec options. (create a new file if it does not exist):

Note: If you are creating a new ~/.xinitrc file you must also include a window manager or desktop environment.

Automatic re-compilation of the VirtualBox guest modules with every update of any kernel

This is possible thanks to vboxguest-hookAUR from the AUR. In vboxguest-hook, the 'automatic re-compilation' functionality is done by a vboxguest hook on mkinitcpio after forcing to update the linux-headers package. You will need to add vboxguest to the HOOKS array in /etc/mkinitcpio.conf. You may need to manually recreate the initramfs after an upgrade of the linux-headers package.

The hook will call the dkms command to update the VirtualBox guest modules for the version of your new kernel.

Note: If you are using this functionality, it is important to look at the installation process of the linux (or any other kernel) package. vboxguest hook will tell you if anything goes wrong.

Start the sharing services

After installing virtualbox-guest-utils above, you should start VBoxClient-all to start services for sharing the clipboard, resizing the screen, etc.

  • If you are running something that launches /etc/xdg/autostart/vboxclient.desktop, such as GNOME or KDE, then nothing needs to be done.
  • If you use .xinitrc to launch things instead, you must add the following to your .xinitrc before launching your WM.
# VBoxClient-all &

Using USB webcam / microphone

Note: You will need to have VirtualBox extension pack installed before following the steps below. See VirtualBox_Extras#Extension_pack for details.
  1. Make sure the virtual machine is not running and your webcam / microphone is not being used.
  2. Bring up the main VirtualBox window and go to settings for Arch machine. Go to USB section.
  3. Make sure "Enable USB Controller" is selected. Also make sure that "Enable USB 2.0 (EHCI) Controller" is selected too.
  4. Click the "Add filter from device" button (the cable with the '+' icon).
  5. Select your USB webcam/microphone device from the list.
  6. Now click OK and start your VM.

Using Arch under Virtualbox EFI mode

My experience with this configuration was pretty terrible, but it does work.

UPD. Using efibootmgr has the same effect as using VirtualBox boot menu (see the note below): settings disappear after VM shutdown. First, efibootmgr does *not* work. It will appear to work, but all changes it makes appear to be overwritten on reboot. After performing a standard UEFI/GPT installation, reboot and you should get dumped to the EFI shell. Type exit and you will get a menu. Select the Boot Management Manager, Boot Options, Add Boot Option. Use the file browser to find the grub efi file and select it. Add a label if you want. Afterwards, select Change Boot Order from the menu, use arrow keys to select your Arch option, and + to move it up to the top. GRUB should boot by default now.

Other options are: 1) move your loader to \EFI\boot\bootx64.efi, 2) create \startup.nsh script, which executes desirable loader, like this:


Here I'm using consistent mapping name (HD16a0a1). It is probably a good idea, because they do survive configuration changes.

Note: Another useful way to get back to the EFI menu after autobooting is working is to press the C key inside GRUB and type exit. Obviously, this will only work with grub-efi, not grub-bios.

Regenerating the grub.cfg file may also be required to fix broken UUIDs. Check with the lsblk -f command that they match.

Yet another useful way to get to VirtualBox boot menu is pressing F12 right after starting virtual machine. It comes in handy when using rEFInd + EFISTUB, for example.

Synchronise guest date with host

To keep sync date and time, make sure you have virtualbox-guest-utils installed in your host (see above). Then run

# systemctl enable vboxservice.service

To enable the service for next boot. To start immediately, run

# systemctl start vboxservice.service

You also need run this daemon in order to use auto-mounting feature of shared folders that are mentioned above.

Enable shared folders

Shared folders are managed via the VirtualBox program on the host. They may be added, auto-mounted and made read-only from there.

If automounting is enabled, and the vboxservice is enabled, creating a shared folder from the VirtualBox program on the host will mount that folder in /media/sf_SHAREDFOLDERNAME on the guest. To have that folder created on the Arch Guest, after the Guest Additions have been installed, you need to add your username to the vboxsf group.

# groupadd vboxsf
# gpasswd -a $USER vboxsf
Note: For automounting to work, you have to enable the vboxservice service.

If you want a shared folder (e.g /media/sd_Dropbox) to be symlinked to another folder in your home directory for easy access, you can type on the guest:

$ ln -s /media/sf_Dropbox/* ~/dropbox

The VBoxLinuxAdditions.run script provided in the Guest Additions iso does this for you, however, Arch does not recommend using it.

If shared folders are not auto-mounted, try manually mount.

To prevent startup problems when you're using systemd, you should add comment=systemd.automount to your /etc/fstab. This way, they are mounted only when you access those mount points and not during startup. Otherwise your system might become unusable after a kernel upgrade (if you install your guest additions manually).

desktop   /media/desktop    vboxsf  uid=user,gid=group,rw,dmode=700,fmode=600,comment=systemd.automount 0 0

Don't waste your time to test the nofail option. mount.vboxsf is not able to handle this (2012-08-20).

desktop   /media/desktop    vboxsf  uid=user,gid=group,rw,dmode=700,fmode=600,nofail 0 0


modprobe Exec format error

Make sure your system is up-to-date:

pacman -Syu


This can occur if a VM is exited ungracefully. The solution to unlock the VM is trivial:

VBoxManage controlvm nArch poweroff

USB subsystem is not working on the host or guest

Sometimes the USB subsystem is not auto-detected resulting in an error (eg: Could not load the Host USB Proxy service: VERR_NOT_FOUND) or in a not visible USB drive on the host, even when the user is in the vboxusers group. See this topic [1] for details.

USB subsystem will work if you add


to ~/.bashrc and reboot your system or open a new bash instance.

Also make sure that your user is a member of the storage group.

Failed to create the host-only network interface

To be able to create a Host-Only Network Adapter or a Bridged Network Adapter the kernel modules vboxnetadp and vboxnetflt need to be loaded, you also need to make sure the net-tools package is installed. It's possible to load these kernel modules manually with

# modprobe -a vboxnetadp vboxnetflt

To load them automatically at boot, add a new line for each module to /etc/modules-load.d/virtualbox.conf:

Note: These used to be added to the MODULES array in /etc/rc.conf. This is now deprecated.

More information in this topic.

WinXP: Bit-depth cannot be greater than 16

If you are running at 16-bit color depth, then the icons may appear fuzzy/choppy. However, upon attempting to change the color depth to a higher level, the system may restrict you to a lower resolution or simply not enable you to change the depth at all. To fix this, run regedit add the following key to the Virtual Windows XP registry:

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services]

Then update the color depth in the desktop properties window. If nothing happens, force the screen to redraw through some method (i.e. Host+F to redraw/enter full screen).

Mounting .vdi Images

This just work with static size vdi images! Dynamic size won't be easy mountable! First we need one information from your .vdi image:

$ VBoxManage internalcommands dumphdinfo Arch_64min.vdi |grep offData
Header: offBlocks=4096 offData=69632

Now, add to your offData 32256. e.g. 32256 + 69632 = 101888

Now you can mount your vdi image:

# mount -t ext4 -o rw,noatime,noexec,loop,offset=101888 Arch_64min.vdi /mnt/

Startup problems because of mount failures

If you experience problems in a systemd setup after a kernel upgrade, you should start the system with init=/bin/bash (if the emergency shell does not work for you).

root=/dev/mapper/vg_main-lv_root ro vga=792 resume=/dev/mapper/vg_main-lv_swap init=/bin/bash

Then mount the root-filesystem with write access:

# mount / -o remount,rw

Change /etc/fstab according to #Shared Folders as Arch Linux Guest. Then exec systemd within the Bash shell:

# exec /bin/systemd

Copy&Paste not working on Arch Linux Guest

Since updating virtualbox-guest-additions to version 4.2.0-2 copy&paste from Host OS to Arch Linux Guest stopped working. It seems to be due to VBoxClient-all requiring root access. In previous versions adding VBoxClient-all & to ~/.xinitrc was sufficient to make copy&paste work. Update ~/.xinitrc to match sudo VBoxClient-all & and add the line , NOPASSWD: /usr/bin/VBoxClient-all to your username in the sudoers file and restart X. It should all work again. The line in the sudoers file should look similar to this:

 # Allow sudo for user 'you' and let him run VBoxClient-all without requiring a password
 you ALL = PASSWD: ALL, NOPASSWD: /usr/bin/VBoxClient-all
Note: Use visudo to edit the sudoers file. This will check for syntax errors when saving.

Use Serial port in guest OS

Check you permission in Serial port

$ /bin/ls -l /dev/ttyS*
crw-rw---- 1 root uucp 4, 64 Feb  3 09:12 /dev/ttyS0
crw-rw---- 1 root uucp 4, 65 Feb  3 09:12 /dev/ttyS1
crw-rw---- 1 root uucp 4, 66 Feb  3 09:12 /dev/ttyS2
crw-rw---- 1 root uucp 4, 67 Feb  3 09:12 /dev/ttyS3

Add you user in uucp group.

# gpasswd -a $USER uucp 

and relogin.

Abort on resume

There is a known bug that causes abort on resume: https://www.virtualbox.org/ticket/11289. The workaround is simple: always use Host+q or the menu to close the VM.

System Images in Btrfs

In 2010 there were reports that OS disk images would not start if they were attached via a virtual SATA device. It was reportedly fixed, and seemed to be. But as of around March 2013, that particular bug report has been repoened. This can be fixed by enabling the use of the host I/O cache, which is disabled by default with virtual SATA interfaces.

vagrant up Issue

With the latest version of Virtualbox(4.2.14-1) the vagrant up command end up in a failure:

Command: ["import", 
Stderr: 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Progress object failure: NS_ERROR_CALL_FAILED

Until the fix makes it into a release you will need to workaround or downgrade VirtualBox.

Workaround by creating manifests for each box in ~/.vagrant.d/boxes/BoxName/virtualbox:

openssl sha1 *.vmdk *.ovf > box.mf

You can downgrade Virtualbox. If you have the old package file inside your cache just downgrade it via:

sudo pacman -U /var/cache/pacman/pkg/virtualbox-4.2.12-3-x86_64.pkg.tar.xz

This error seems to appear on all platforms: http://www.marshut.com/pzisi/progress-object-failure-ns-error-call-failed-when-running-vagrant-up-in-getting-started-guide.html#qhihz

It's unclean for the moment. It could be regression inside Virtualbox or a issue inside Vagrant. When you delete the cache you can downgrade via ArchLinux downgrader (I didn't test it correctly, but I assume this works, else check the wiki page for downgrading: https://wiki.archlinux.org/index.php/Downgrading_Packages)

For more Information, check the issue page on github Clean install on OS X 10.8.4 w/ latest VirtualBox not working

According to the Vagrant creator on Twitter, this is a VirtualBox bug. On 2013-06-25, he said that they fixed the bug in SVN, and he's waiting on a release. Also, I can confirm that this is a multi-platform issue, 4.2.14 was broken for me on Win7.

This issue has been solved inside the virtualbox release virtualbox-4.2.16-1

Access to shared folders hangs

Access to a shared folder on the host from a guest running 3.11 kernel can hang. There is a fix upstream, but it has not yet (as of 26 Sept 2013) made its way to the guest additions package. Here's the fix:

Changeset 48529 in vbox

See also:

Mounted folders hang since last kernel upgrade

I was able to fix this by downgrading my kernel and modules:

# pacman -U /var/cache/pacman/pkg/linux-3.9.5-1-i686.pkg.tar.xz /var/cache/pacman/pkg/virtualbox-guest-modules-4.2.12-7-i686.pkg.tar.xz

Windows 8.x Error Code 0x000000C4

If you get this error code while booting even if you choose OS Type Win 8, try to enable CMPXCHG16B cpu instruction

vboxmanage setextradata [VMNAME] VBoxInternal/CPUM/CMPXCHG16B 1

External links