Getting rid of virbr0/virbr1 interface in Ubuntu Server 9.10

After a fresh install of Ubuntu 9.04,  you might have a network interface virbr0 if you’ve selected to install a virtual machine emulator.  During the CD install, selecting vm, it will install kvm and xen.  It will create a network interface virbr0 or virbr1 to perform host networking.

Later, if you decide to install VMWare, VirtualBox or decide you really didn’t want a virtual machine server, you can remove the applications easily.  Just do a (sudo):

apt-get purge kvm

apt-get purge libxen3

Installation and configuration of a headless Ubuntu Server

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

           auto eth0

           iface eth0 inet manual

           auto br0

           iface br0 inet dhcp

               bridge_ports eth0 vbox0

           # The loopback network interface

           auto lo

           iface lo inet loopback

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

        auto eth0

        iface eth0 inet manual

        auto br0

        iface br0 inet static

             address xxx.xxx.xxx.xxx

             netmask xxx.xxx.xxx.xxx

             gateway xxx.xxx.xxx.xxx

             bridge_ports eth0 vbox0 vbox1

        # The loopback network interface

             auto lo

             iface lo inet loopback

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:-

vbox root br0

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.

       All rights reserved.

       Listening on port 3389

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

OR 

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:-

rdesktop 192.168.0.157

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

VBoxManage showvminfo

How to show the VM Harddrive info

VBoxManage showhdinfo

How to list running VM

VBoxManage list runningvms

How to list available VM

VBoxManage list vms

How to list available VM Harddrives

VBoxManage list hdds

How to list available ISO’s

VBoxManage list dvds

                                                                                                               
How to control the vm

How to pause VM

VBoxManage controlvm pause

How to resume VM

VBoxManage controlvm resume

How to reset VM

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