VirtualBox
From Gentoo Linux Wiki
Contents |
[edit] 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 it's 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.
[edit] 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 following USE flags:
- additions - Install Guest System Tools ISO. These speed up video, allows you to have a seemless mouse between the host and the window that the guest OS resides in, and shared folders access between the host and the guest OS.
- alsa - Adds support for media-libs/alsa-lib
- pulseaudio - Adds support for PulseAudio sound server
- sdk - Enable building of SDK
echo "app-emulation/virtualbox additions alsa" >> /etc/portage/package.use
After then, just run
emerge -av virtualbox
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
[edit] Binary distribution
The binary distribution provides the following additions to the OSE version:
- Direct access to USB devices from guest operating system
- Remote Desktop 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.
emerge -av virtualbox-bin
[edit] Run
Add 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 automaticaly at boot time:
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.
[edit] 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
- install virtualbox with the use flag "additions"
- start your windows guest machine and select "Install guest additions" from the VirtualBox menu
[edit] Network
Virtualbox supports networking via NAT and via bridges. NAT networking is very simple and works out of box.
[edit] 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.
[edit] 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.
[edit] 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: HOWTO Setup a Gentoo Bridge
To bring up your TAP-Device you need net-misc/openvpn or sys-apps/usermode-utilities.
[edit] Configure network
Here's network configuration that works for me:
| File: /etc/conf.d/net |
#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:
cd /etc/init.d/ ln -s net.lo net.vbox0 ln -s net.lo net.br0
And then add them to default runlevel:
rc-update add net.vbox0 default rc-update add net.br0 default
I found the following useful as a working set: configuration file, some extra steps, and startup script.
| File: /etc/conf.d/net |
# summarizes what has been stated, but seems clearer)
# Make a tuntap_vbox(n) = "tap" and config_vbox(n)=( "null" ) line for each vbox(n) adapter needed.
# You can create up to 99 of them.
config_eth0=( "null" )
tuntap_vbox0="tap"
tuntap_vbox1="tap"
tuntap_vbox2="tap"
tuntap_vbox3="tap"
config_vbox0=( "null" )
config_vbox1=( "null" )
config_vbox2=( "null" )
config_vbox3=( "null" )
config_zbridge=( "dhcp" )
bridge_zbridge="eth0 vbox0 vbox1 vbox2 vbox3"
depend_zbridge()
{
need net.eth0
need net.vbox0
need net.vbox1
need net.vbox2
need net.vbox3
}
brctl_zbridge=( "setfd 0" )
|
Then I create my symlinks in the /etc/init.d/ dir as stated above. Then I do my rc-update as stated above for each vbox adapter. Then I use VBoxAddIf <vboxN> <user> <optional-bridge-name> to set the allocation in /etc/vbox/interfaces.
Next, I use this startup script to ensure the taps are owned by the assigned user on startup.
| File: /etc/init.d/vbox |
#!/sbin/runscript
#NB:
# You must first setup your bridge networking!
# See for details: http://gentoo-wiki.com/HOWTO:_VirtualBox#Bridge_networking
# awk usage by pr3d4t0r (Eugene Ciurana) - thanks :)
# VBoxTunctl usage by Innotek User Guide, and support from #vbox.freenode.net - thanks :)
source /etc/profile
PROXY_USED="";
depend() {
# depend() function:
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
need net
before netmount
if [ -n "$PROXY_USED" ];
then
after $PROXY_USED
fi;
};
start() {
ebegin "Establishing VirtualBox bridge taps"
awk '/vbox/ { system(sprintf("VBoxTunctl -u %s -t %s && ifconfig %s up", $2, $1, $1)); }' /etc/vbox/interfaces;
eend ${?}
};
stop() {
ebegin "Disposing VirtualBox bridge taps"
awk '/vbox/ { system(sprintf("VBoxTunctl -d %s", $1)); }' /etc/vbox/interfaces;
eend ${?}
};
|
Configure VirtualBox Neworking with the adapter(s) assigned to user(x) and Voila!
[edit] 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)
[edit] Configure udev
I found that editing the udev rules you can avoid the message asking to chmod 0666 /dev/net/tun. Look for the line below and edit as below: change from 0660 to 0666
| File: /etc/udev/rules.d/50-udev.rules |
# network devices KERNEL == "tun", NAME="net/%k", MODE="0666" |
I had to run the following to avoid the -3100 (VERR_HOSTIF_INIT_FAILED) error.
tunctl -t vbox0 -u <user_name>
It wouldn't run otherwise as a regular user (it would work for root only)
I still had the -3100 (VERR_HOSTIF_INIT_FAILED) error when applying the above to vbox0 I ran the same tunctl command but specified tap1 to get rid of the error.
tunctl -t tap1 -u <user_name>
[edit] Alternate udev configuration
If you do not wish to give everyone read-write access to /dev/net/tun, then the following setup will allow you to control which users have read-write access to the /dev/net/tun device.
[edit] Create the TUN/TAP group
# groupadd tuntap
[edit] Add a TUN/TAP user
With respect to VirtualBox use, the user you add to the tuntap group will be the same user you added to the vboxusers group.
# gpasswd -a <user> tuntap
[edit] Create the TUN/TAP udev rule
| File: /etc/udev/rules.d/10-local.rules |
KERNEL == "tun", NAME="net/%k", GROUP="tuntap", MODE="0660", OPTIONS+="ignore_remove" |
[edit] Apply the TUN/TAP udev rule
# udevstart
[edit] Troubleshooting
[edit] 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.
[edit] 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.
[edit] Stalling at "Spawning"
If your virtual machine never gets past 0% when you click "Start Machine", there's one way to fix it. 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.
[edit] USB Devices Grayed Out
If you can see your devices, but they are greyed out it is a permission problem:
[edit] 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).
# cat /etc/group | grep usb
[edit] 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. Reference Chapter 11 of the Gentoo Handbook. So,
# cat /etc/group | grep plugdev
Use the number that is retrieved as the devgid=## in /etc/fstab line quoted above.
Log out and log back in.
