Bear in mind that at the time of this exercise I was installing a Ubuntu Server 9.10 on VirtualBox 3.0.10.
1. First install all necessary packages. Apt-get virtualbox from the ubuntu repositories:
sudo apt-get install virtualbox-ose
You can also download the deb and install it manually:-
e.g
sudo dpkg -i virtualbox-3.0_3.0.10-54097_Ubuntu_karmic_amd64.deb
To get the proprietary version:-
(/etc/apt/sources.list)
deb http://download.virtualbox.org/virtualbox/debian karmic non-free
Then download Sun’s public key:-
And finally:-
sudo aptitude install linux-headers-$(uname -r) build-essential virtualbox-3.0 dkms
dkms is optional. Its a package that ensures that the VirtualBox host kernel modules are properly updated if the Linux kernel version changes
The group vboxusers will be created during installation. Note that a user who is going to run VirtualBox must be member of that group:-
sudo usermod -a -G vboxusers username
2. Since we want to setup our network in such a way that we have network bridges, we need to install bridge-utils.
sudo apt-get install bridge-utils
3. The next step is to edit /etc/network/interfaces on the host machine and add the br0 interface with the same address as you primary interface, in this case eth0. Before you begin, backup your interfaces file since it is vital to your networking functionality.
sudo cp /etc/network/interfaces /etc/network/interfaces.`date +%F~%T`
This process varies depending on whether you’re host uses a static or dynamic IP address.
Dynamic
$ sudo nano /etc/network/interfaces
# The loopback network interface
eth0 is the name of your interface, it can be different depending on your machine.br0 is an arbitrary name for the bridge.vbox0 is an arbitrary name for the device VBox will use. If you want more devices , you can add them:- bridge_ports eth0 vbox0 vbox1 vbox2 vbox3 vbox4 blah..blah..blahh
Static
$ sudo nano /etc/network/interfaces
bridge_ports eth0 vbox0 vbox1
# The loopback network interface
4. Now restart your networking:-
sudo /etc/init.d/networking restart
Ignore the messages complaining about the vbox# interface
Afterwards, ifconfig and you should see your br0 interface
5. Now create a file/etc/vbox/interfaces and add the following:-
This file is used to declare the virtual interfaces needed by VirtualBox. Each line should be of the format [] . Declare as many interfaces as you want here for all your virtual machines. Just make sure they also exist in /etc/network/interfaces as shown earlier.
And now restart virtualbox to register the changes:-
/etc/init.d/vboxdrv restart
N/B
Most sources on the internet indicate that you should use /etc/init.d/virtualbox-ose restart for VirtualBox OSE and /etc/init.d/vboxnet restart and for the proprietary version. On my version, only vboxdrv existed in init.d so if any of the two are the ones that exist in yours, don’t hesitate.
6. The last thing in the host’s network configuration would be to set the permissions on /dev/net/tun
$ sudo chown root:vboxusers /dev/net/tun
$ sudo chmod g+rw /dev/net/tun
This file is created with the default permissions every time the system restarts, so the best option would be to run the vms everytime as root. At this point its safe to say that installation and host configuration is complete. It is advised to restart your system.
Creating A New VM
1. First Register the Virtualbox machine with the machine name, in this case ubuntu_server1 (think of it as a shell we’ll customize later) :-
VBoxManage createvm –name ubuntu_server_1 –register
2. Then now give the VirtualBox machine all its properties:-
VBoxManage modifyvm “ubuntu_server_1” –memory “256MB” –acpi on –boot1 dvd –nic1 bridged –bridgeadapter1 eth1
If you need to change any of the properties in future, do it the same way its done above e.g If I want to turn vrdp off at a later point, all I have to do is VBoxManage modifyvm ubuntu_server_1 –vrdp off
3. Tell VirtualBox to mount the install ISO you want to install as the OS:-
VBoxManage modifyvm ubuntu_server_1 –dvd /home/avallainafrica/images/ubuntu-9.10-server-i386.iso
4. Create a virtual hd for the virtual machine. In this case, the drive has been allocated 10GB :-
VBoxManage createhd –filename “ubuntuserver1.vdi” –size 10000 –remember
5. Tell the virtual machine to use the hard drive you just created:-
VBoxManage modifyvm “ubuntu_server_1” –hda “ubuntuserver1.vdi”
Your virtual machine is now good to go. VirtualBox comes with a front-end called
VBoxHeadless, which produces no visible output on the host at all, but instead only delivers VRDP data. To start the virtual machine in your host, do this :-
VBoxHeadless –startvm ubuntu_server_1
You should see such output when the machine is started:-
VirtualBox Headless Interface 3.0.10
(C) 2008-2009 Sun Microsystems, Inc.
If you want to start the machine headless and detached in it’s own screen session so it’ll keep running even after you close your terminal session or log out of your machine:-
screen -d -m -S ubuntu_server_1 VBoxHeadless –startvm ubuntu_server_1
nohup VBoxHeadless –startvm &
To access the machine remotely, all you need to do is use the remote desktop client of your choice. Rdesktop worked swell for me on Ubuntu (sudo apt-get install rdesktop) . In this case:-
Remember that the virtual machine needs to be running in the host/server.
You will see the OS image you mounted booting and the rest is just normal installation of the OS in this case, Ubuntu Server. After installation, one thing you’ll notice when you start the machine again and access it via VRDP is that it will still boot from the ISO image. This is because the –boot1 option is still on dvd which is the mounted drive. Here’s how to fix this:-
VBoxManage modifyvm ubuntu_server_1 –-dvd none
There are quite a number of things you can do to tweak the configuration of your existing Vboxserver using VBoxManage. The best source for the wide array of commands is the VirtualBox user manual(http://www.virtualbox.org/manual/UserManual.html#vboxmanage) but I’ve compiled some
useful ones here:-
How to list VM information.
How to show the VirtualBox VM info
How to show the VM Harddrive info
VBoxManage list runningvms
How to list available VM Harddrives
How to list available ISO’s
VBoxManage controlvm pause
VBoxManage controlvm resume
VBoxManage controlvm reset
How to poweroff VM (hard poweroff eg. pull the plug)
VBoxManage controlvm poweroff
How to send poweroff single to VM (tells VM OS to shutdown)
VBoxManage controlvm acpipowerbutton
How to attach a DVD / CD to a running vm
VBoxManage controlvm dvdattach
How to de-attach a DVD / CD from a running vm
VBoxManage controlvm dvdattach none