VirtualBox

VirtualBox is virtualization software which allows a computer system to run one or more "guest" operating systems on top of its main OS. Some common uses for this technology are: VirtualBox is not an emulator; it cannot run guest operating systems with different hardware architectures (e.g. x86, powerpc, sparc, etc).
 * Testing - Observing the performance of software in development on multiple platforms.
 * Compatibility - Running software native to one operating system on another.
 * Virtual Servers - Running multiple server applications within their own environments on the same hardware for security, reliability, and cost-effectiveness.

Installation
Prior to version 4.0, VirtualBox is installed either from the closed source binaries or directly from the sources. The closed source version contains some features that the open source edition lacks (see Licensing), but its use is restricted to personal use and evaluation. The open source edition is published under the GPL. For more details on the features and license terms of each edition, have a look at: http://www.virtualbox.org/wiki/Editions.

Since version 4.0, VirtualBox is installed from the open source. All closed-source components have been moved to a separate extension pack (see Editions).

OpenSource distribution (OSE)
The VirtualBox ebuild provides the following USE flags:
 * - Install Guest System Tools ISO. These speed up video, allow you to have a seamless mouse between the host and the window that the guest OS resides in, and shared folders access between the host and the guest OS.
 * - enable ALSA support
 * - enable the extensions from the closed source components
 * - Build without any graphic frontend
 * - Adds support/bindings for the Python language
 * - Build qt4 frontend
 * - Adds support for PulseAudio sound server
 * - Enable building of SDK
 * - enable the VirtualBox web server. A handy thing for a headless deployment

After you have enabled/disabled required USE flags, install the package:

Binary distribution
The binary distribution provides the following additions to the OSE version:
 * USB 2.0 (EHCI) support for the guest OSes
 * Remote Desktop (RDP) access to the virtual machine
 * Direct access / raw access to a hard disk (partition) (NOTE: You may also use the binary edition to create VMDK files that point to hard disks and partitions, and subsequently these can be used with the OSE version)

Usage of binary distribution is limited to personal or evaluation usage. A more complete list of differences between the binary edition & OSE is available at http://www.virtualbox.org/wiki/Editions

Installing masked versions of VirtualBox
If you wish to install a version of VirtualBox newer than that listed as stable in the Portage tree, you must unmask it by adding the following lines to your package.keywords file.

You may need to authorise portage to accept the restrictive non-GPL licence:

Don't blindly authorise all PUEL packages
Since the above will automatically authorise ALL packages masked as PUEL and hence cause portage to install proprietory packages without your being aware of the license ( or even the fact that it is non GPL !), it may be more sensible to just authorise any required licenses on a one by one basis as follows:

Run
Users that run VirtualBox must be a member of the "vboxusers" group. The user you added will not be able to access VirtualBox until they relogin.

Also the vboxdrv module should be loaded prior to starting VirtualBox.

You may also need to change the group ownership of /dev/vboxdrv like so:

To make the module load at boot, run following commands:

For baselayout-2:

For baselayout-1:

And to finally start VirtualBox, you can either click the menu entry (Sun xVM VirtualBox) or via the terminal using:

Service
To run VirtualBox in headless mode as a service you will need to add the following scripts to your system.

VM_SHUTDOWN="keyboardputscancode 1d 38 53" .
 * 1) To send Ctrl-Alt-Del to the VM

To add a new virtual machine to startup you will need to create a conf.d file and symbolic link for the virtual machine.

Now modify the newly created /etc/conf.d/virtualbox.NEW_VM file. Be sure the VM_USER is in the vboxusers group and that VM_NAME is the correct case.

Networking
VirtualBox supports networking via NAT and via bridges. NAT networking is very simple and works out of box.

NAT
Works perfectly when you set NAT and keep "Cable connected" checked on. VirtualBox then uses internal DHCP and NAT. Disadvantages are that ICMP doesn't work (no ping - #1247) and you can't connect to virtual machine unless you set up port-forwarding rules.

However your virtual machine will be able to connect to other machines on your LAN without any issues and LAN name resolution should work providing you have that functionality on your LAN.

Bridged
If you need your guest OS to have a different IP address in the same subnet on the same Ethernet interface, then you should use bridging.

Note: The following steps are not necessary for setting up Host Interface on VirtualBox >= 2.1.

VirtualBox Version >= 2.1
You no longer need the TUN/TAP and bridging support, as VirtualBox has built the bridging functionality directly into the software. However, for those of you have it already configured and recently upgraded from VirtualBox 2.0 to 2.1+, you may find that you get an error when you try to start your VM. The error, ERR_HOSTIF_INIT_FAILED, will prevent you from starting the VM.

In order to fix it, you will need to modprobe the new vboxnetflt kernel module. You can find it in: /lib/modules/ /misc/vboxnetflt.ko. Simply change into that directory and run modprobe on the module, then restart your VM.

VirtualBox Version < 2.1
Do only this:

Preparing
You should enable bridging support and tun/tap in kernel (or compile them as modules).

You can read about bridges here: Bridging

Configure network
Now create interface symlinks:

Configure virtual machine
Run virtualbox and click "Settings" for your virtual machine
 * Click Network
 * Set "Attached to" to "Host interface"
 * Set "Interface name" to "vbox0" (Don't forget this or you'll get a VERR_HOSTIF_INIT_FAILED)

Configure udev
In older versions of udev, the default permissions of /dev/net/tun do not allow all users to access the device, this is due to pre-capabilities period. Nowdays it is perfectly safe to allow all users to access the device, while only root is able to manipulate the device.

If you get other output of the following command you need to install an extra rule.

Refresh rules

Troubleshooting
This section contains some troubleshooting guides provided by other users.

Framebuffer in Guest OS: Missing Half the Screen
If you happen to want framebuffer support for a guest OS using either vesafb or the newer uvesafb you may notice that you can't see half of your screen. I am not entirely sure why this is a problem for VirtualBox, but you can use uvesafb or vesafb without any problems. Simply remove consolefont from the boot runlevel as follows:

This seems to fix the problem and doesn't cause any other side effects.

Another user: This did not help on my machine, but setting mtrr:4 and redraw instead of ywrap in grub.conf helped. So here's the complete video option string I'm using: video=uvesafb:800x600-16,mtrr:4,redraw I'm not sure about mtrr:4, but at least the kernel doesn't complain about invalid mtrr settings anymore. Using "redraw" instead of "ywrap" is slower according to the (u)vesavfb docs, but in VirtualBox it's flying.

Error: interface vbox0 does not exist!
You need to ensure you have the tun / tap module compiled into your kernel and modprobed. Also, ensure you have sys-apps/usermode-utilities which now provides the tunctl app.

Error: interface br0 does not exist!
emerge net-misc/bridge-utils

Virtual Windows XP Installation Crashes During Format of the Partition With 0% Progress
You might have a crash during formatting of the partition while installing your virtual Windows XP. If you get the error above, please check that the assigned amount of memory for the virtual machine is less than the real memory of your PC. The combination when you have 1GB of real memory and 2GB of memory assigned for your virtual machine will crash your Windows XP installation on the first access to the HDD, which is actually attempt to perform format during installation!

The problem also exists during the creation of Linux virtual machines. Behavior is the same: virtual machine crashes during first access to the HDD.

Guest Does Not Receive Packets In Bridge Mode
If the guest does not receive packets in bridge mode, check for bugs #150791 and #171356. The problem is because of the txqueuelen:0 setting in the assigned tap device.

If you followed this guide and still have some issues with bridged networking, then take a look at this forum thread

Stalling at "Spawning"
If your virtual machine never gets past 0% when you click "Start Machine", one way to fix it might be:

I thought I was being real smart when I put Virtual Machine Related support in my kernel. VirtualBox does not need anything in your kernel to run a machine. Once I took out that support, everything worked.

I had the same problem, however, I didn't have anything related to virtualization in my kernel. The last log messages were ALSA related, and switching the VirtualBox sound to OSS (although that's actually alsa's OSS emulation) got me to boot the machine :)

My virtual box used to work, but after accidental deletion of an image, VirtualBox refused to start a new machine and also stalled at spawning. After a simple "killall VBoxSVC" (which is a daemon process running in background), everything works well.

VirtualBox Constantly Uses CPU
When the guest is idle VirtualBox should consume very little CPU. This will vary by system but should generally be less than 10%. For example, on a quad core system the VirtualBox process consumes ~1% CPU with an idle WinXP guest. You can experience high VirtualBox CPU usage even when the guest XP session shows no activity via Task Manager. A possible remedy is to examine the WinXP applications and services. As stated in the VirtualBox built in help file, this behavior can be caused by anti-virus software and the recommendation given there is to disable anti-virus. Further examination of the services can be done to eliminate any unneeded processes. I found that a VNC server inside of the WinXP guest caused a constant load of 50% on one CPU core in a quad core system. Skype causes similar inactive cpu load issues. This issue can also arise from running the guest with an XP hardware profile copied from a native multicore ACPI system. Change the system type in the virtual profile to 'Standard PC' to reduce CPU overhead from BIOS ACPI calls.

USB Devices Grayed Out
If you can see your devices, but they are greyed out it is a permission problem:

VirtualBox Advice
The VirtualBox User FAQ specifies, "If USB doesn't work, check your usbfs permissions. See "Troubleshooting" -> "Linux hosts" in the User Manual for a solution."

The pertinent section of that section of the VirtualBox User Manual specifies:

If USB is not working on your Linux host, make sure that the current user has permission to access the USB filesystem (usbfs), which VirtualBox relies on to retrieve valid information about your host?s USB devices. As usbfs is a virtual filesystem, a chmod on /proc/bus/usb has no effect. The permissions for usbfs can therefore only be changed by editing the /etc/fstab file. For example, most Linux distributions have a user group called usb or similar, of which the current user must be a member. To give all users of that group access to usbfs, make sure the following line is present:

Replace 85 with the group ID that matches your system (search /etc/group for "usb" or similar).

How Gentoo does it specifically
Note that udev supports fstab settings. And the pertinent group to be added as the devgid is the plugdev group (ensure your user is a member of this group). Reference Chapter 11 of the Gentoo Handbook. So,

Use the number that is retrieved as the devgid=## in /etc/fstab line quoted above.

Log out and log back in.