Search:  
Gentoo Wiki

VirtualBox


Please improve it in any way that you see fit, and remove this notice {{Cleanup}} from the article. For tips on cleaning and formatting see Cleanup process


Contents

Install

VirtualBox can be 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 Propietary vs. Open Source), 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.

OpenSource distribution (OSE)

Note: Support for amd64 host systems was added in 1.4.0
Note: Both 1.4.0 and 1.5.0-r1 rely on multilib, yet neither is in package.mask for nomultilib profile

Virtualbox ebuild provides the following USE flags:

echo "app-emulation/virtualbox-ose additions alsa" >> /etc/portage/package.use

Then, just run

emerge -av virtualbox-ose

Portage may ask you to unmask various other unstable packages.

Remember to re-emerge virtualbox-modules each time you do a kernel-upgrade (sys-kernel/module-rebuild can do it for you):

emerge -av virtualbox-modules

Binary distribution

The binary distribution provides the following additions to the OSE version:

Usage of binary distribution is limited to personal or evaluation usage.

emerge -av virtualbox-bin

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.

gpasswd -a youruser vboxusers

Ebuild provides a wrapper to start virtualbox via graphical UI, type

modprobe vboxdrv
VirtualBox

You may also want to make vboxdrv load automatically at boot time:

Command: baselayout-2
echo 'modules="${modules} vboxdrv"' >> /etc/conf.d/modules
Command: baselayout-1
echo vboxdrv >> /etc/modules.autoload.d/kernel-2.6

To start a separate virtual machine from command line, type

VBoxManage startvm <machine_name>

By default VirtualBox stores all VM's in the users home directory. ~/.VirtualBox/, so you might consider changing these default paths if you intend on using VM's between multiple users.

Seamless Window Integration

A nice feature of VirtualBox is seamless window integration. If this is enabled you do not need to press the host key to change between your host and the local machine, etc.

To enable this feature you have to

  1. install virtualbox with the use flag "additions"
  2. start your windows guest machine and select "Install guest additions" from the VirtualBox menu

Network

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.

Bridge networking

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.

Preparing

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

Linux Kernel Configuration: 802.1d Support
Networking --->
    Networking Options --->
    <*> 802.1d Ethernet Bridging


Linux Kernel Configuration: TUN/TAP Support
Device Drivers  --->
    Network device support  --->
    <*> Universal TUN/TAP device driver support

You can read about bridges here: Bridging

To bring up your TAP-Device you need net-misc/openvpn or sys-apps/usermode-utilities.

Configure network

File: /etc/conf.d/net (baselayout-2)
# For every VM create an interface,
# set user to the one who going to use the
# interface.
tuntap_vbox0="tap"
tunctl_vbox0="-u <user>"
config_vbox0="null"
config_eth0="null"

# Add here all interfaces that you want to bridge
# eg eth0, but make sure to add config_eth0="null"
rc_need_br0="net.vbox0"
bridge_br0="vbox0 eth0"

# The following will be the host IP, it can be the default router
# for the VM in routing mode.
# You can use dhcp here if you like, it makes sense if you want
# to bridge your VM into the real network.
#config_br0="dhcp"
config_br0="192.168.151.1/24"

brctl_br0="setfd 0
sethello 0
stp off"
File: /etc/conf.d/net (baselayout-1)
#the interface is really replaced by br0 for outgoing, so if you had dhcp here, you'll use dhcp in br0
config_eth0=( "null" )

#this specifies that interface vbox0 will be a tap interface and use the tunctl command to generate itself
tuntap_vbox0="tap"

#ALL interfaces part of a bridge should be null, otherwise oddities may occur.
config_vbox0=( "null")

# you can specify an owner of the interface if you want to run virtual box as a non root user
# [COMMENT from a reader: VirtualBox should never be run as root]
#tunctl_vbox0=("-u adm")

#If you'd prefer a dynamic ip address for the machine, use
#config_br0=( "dhcp" )
config_br0=( "192.168.1.2 netmask 255.255.255" )
routes_br0=( "default via 192.168.1.1" ) 
#this specifies the bridging information
bridge_br0="eth0 vbox0"
#Make sure your baselayout is recent enough to support this
depend_br0() 
{
         need net.eth0
         need net.vbox0
}

brctl_br0=( "setfd 0")

Now create interface symlinks:

Command: Interfaces
ln -s net.lo /etc/init.d/net.vbox0
ln -s net.lo /etc/init.d/net.br0
rc-update add net.br0 default

Optionally enable firewall, routing and NAT between local bridge and network using firehol, so you can access the internet from the virtual machine without bridging all traffic and switch between ethX and pppX.

File: /etc/firehol/firehol.conf
standard_inet() {
        client  http            accept
        client  https           accept
        client  ftp             accept
        client  dns             accept
        client  icmp            accept
}

interface "eth+ ppp+" internet1
        policy  reject
        protection              strong  10/sec  10
        server  ident           reject  with tcp-reset

        standard_inet

interface "br0" local1
        policy  reject
        protection              strong  10/sec  10
        server  ident           reject  with tcp-reset


        standard_inet

router tun_nat  inface "eth+ ppp+" outface "br0"
        route   ident           reject with tcp-reset
        server  ident           reject with tcp-reset
        masquerade              reverse

        standard_inet

Optionally install dnsmasq so that the DNS of the virtual machine will always be the host.

Command: Install dnsmasq
# emerge dnsmasq

Configure virtual machine

Run virtualbox and click "Settings" for your virtual machine

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.


Command: Check permissions
# ls -l /dev/net/tun
crw-rw-rw- 1 root root 10, 200 2008-07-23 16:45 /dev/net/tun


File: /etc/udev/rules.d/60-tun.rules
KERNEL == "tun", MODE="0666"


Command: Refresh rules
# udevcontrol --reload_rules
# udevtrigger

Troubleshooting

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:

rc-update del consolefont boot

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

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.

Stalling at "Spawning"

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

sudo killall --verbose --signal KILL VBoxSVC

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", what's a daemon process running in background, everything works well.

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:

File: /etc/fstab
# 85 is the USB group
none /proc/bus/usb usbfs devgid=85,devmode=664 0 0

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

getent group usb

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,

getent group plugdev

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

Log out and log back in.

Retrieved from "http://www.gentoo-wiki.info/VirtualBox"

Last modified: Wed, 01 Oct 2008 00:38:00 +0000 Hits: 70,375