Install VirtualBox on Ubuntu 8.04 (Hardy)
Installing VirtualBox on Hardy is easy. From a terminal session, run the following commands to install Virtualbox.
sudo apt-get install virtualbox-ose virtualbox-ose-source virtualbox-ose-modules-generic
Add yourself to the vboxusers group. You can add more usernames after “whoami” if you wish:
sudo gpasswd -a `whoami` vboxusers
or
sudo usermod -Gvboxusers -a `whoami`
You will now have to log out of your desktop session and log back in order to update your group membership.
Networking
To start, NAT is by far the easiest way to get your guests connected to the interweb, but you may want to use the guests as servers, for this you need Host Networking. You will need to install bridge-utils and uml-utilities so that you can make a tap device and add it to a bridge.
sudo apt-get install bridge-utils uml-utilities
Now make a bridge, and put your current interface into it:
sudo tunctl -t tap1 -u fred #where fred is the user you will be running vbox as sudo chown root.vboxusers /dev/net/tun sudo chmod g+rw /dev/net/tun
Set the permission to persist across reboots, by editing as root /etc/udev/rules.d/20-names.rules and changing:
KERNEL=="tun", NAME="net/%k"
to
KERNEL=="tun", NAME="net/%k", GROUP="vboxusers", MODE="0660"
Make a new bridge called br0:
sudo brctl addbr br0
Put your current interface (in this case eth0) into promiscuous mode, then add it to the bridge and give the bridge a dhcp address.
sudo ifconfig eth0 0.0.0.0 promisc sudo brctl addif br0 eth0
If you are using DHCP to automatically get an IP address, set the bridge to use DHCP.
sudo dhclient br0
If you are using a static IP, specify the IP address, netmask and add the default gateway route
#Where 192.168.1.105 is your static IP and 255.255.0.0 is your netmask
sudo ifconfig br0 192.168.1.105 netmask 255.255.0.0 #Where 192.168.1.1 is your default gateway sudo route add default gw 192.168.1.1 br0
Add the new tap1 device to the bridge and activate tap1 (the second line appears to be necessary)
sudo brctl addif br0 tap1 sudo ifconfig tap1 up
You should now be able to use host networking in vbox, just change “attached to” to “host interface” and add the interface name of tap1 in your networking settings. Read the manual as well, there are some other nifty ways to do this. Do not forget to use the root account when doing this. Also reboot your computer afterwords.
Wireless Networking
Setting up a normal bridged network generally doesn’t work if you’re bridging from a wireless card to VirtualBox. A simple script that utilises the parprouted tool will allow your VM full access to the wireless network.
You will require parprouted to do this:
sudo apt-get install parprouted
Next, using your favorite text editor, create and edit the script, for example:
sudo nano /etc/network/if-up.d/vbox_network
Then, enter the script (replacing $USER with your username (or whoever you intend to run virtualbox as)). Replace wlan0 with the name of your wireless interface. Use an available IP address on your network for tap0 (I have used 192.168.1.100 in this case):
#!/bin/bash sysctl net.ipv4.ip_forward=1 VBoxTunctl -b -u $USER ip link set tap0 up ip addr add 192.168.1.100/24 dev tap0 parprouted wlan0 tap0
Finally, make sure the new file is executable by root:
sudo chmod 700 /etc/network/if-up.d/vbox_network
Now your networking script is installed, the virtual interface tap0 will be available on boot for VirtualBox. Rather than reboot, let’s just run the script now:
sudo /etc/network/if-up.d/vbox_network
The final thing to do is tell VirtualBox to use the new virtual device tap0.
Open VirtualBox, highlight a VM and click Settings. Now choose the Network option and select Host Interface on the “attached to” drop-down menu. In the Interface Name text box, enter tap0.
Click OK and start your VM. The VM should now behave as though it was another physical machine on your network!!
Unfortunately, at the time of writing I don’t think DHCP auto configuration will work in the VM, so make sure you set a static IP in the virtual machine.
For more information, please visit http://home.nyc.rr.com/computertaijutsu/vboxbridge.html.
USB
To get USB support, you need the PUEL version. Via the GUI, there is an option to enable USB.
Furthermore, your user must be able to access /proc/bus/usb/* and the best way I’ve found to do this is to give run chown on /proc/bus/usb.
sudo chown -R root:vboxusers /proc/bus/usb
Now just make sure your user is part of the group [i:1ec32mpn]vboxusers[/i:1ec32mpn], and all is well. I’m assuming this solution doesn’t work when you restart your computer so we’ve got a fix for that as well.
sudo nano /etc/init.d/mountdevsubfs.sh
Append “,devgid=1003”, where 1003 is the number if your vboxusers group in /etc/group, to the end of the “domount usbfs …” line, and change the devmode to 0664.
Sharing Folders Between Host and Guest
Note: The client OS cannot be open when adding shares.
On the host (ubuntu) computer, run:
mkdir ~/VirtualBoxShare vboxmanage sharedfolder add "XP" -name "share" -hostpath ~/VirtualBoxShare/
On the Windows client, run:
net use x: \\vboxsvr\share
If the client is Linux, run
mount -t vboxsf share mountpoint
For the above command if you get error as
mount: unknown filesystem type 'vboxfs'
Then just change the vboxfs to vboxsf means the command will be
mount -t vboxfs share mountpoint
For the above command if you get error as
mount: unknown filesystem type 'vboxfs'
Then just change the vboxfs to vboxsf means the command will be
mount -t vboxsf share mountpoint
(See Section 4.4 Folder Sharing in the VirtualBox documentation.)