Ubuntu 12.04 xen

The installation is based on the document https://help.ubuntu.com/community/XenProposed. Check the part called “Manually creating a PV Guest VM”

You will need a machine where xen is correctly configured, a bridge with internet connection and a public IP or a private IP with access to a router that can connecto the internet.

First we create an empty disk, in this case it will be 8 Gb:

<xterm> $ dd if=/dev/zero of=ubuntu.img bs=1 count=1 seek=8G </xterm>

Then we download netboot kernel and initrd compatible with Xen. We are using a mirror near to us but you can select one from this page https://launchpad.net/ubuntu/+archivemirrors:

<xterm> $ wget http://ftp.dat.etsit.upm.es/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/vmlinuz $ wget http://ftp.dat.etsit.upm.es/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/initrd.gz </xterm>

Now we can create a file describing the VM where the ubuntu will be installed:

name = "ubuntu"
 
memory = 256
 
disk = ['file:PATH/ubuntu.img,xvda,w']
vif = ['bridge=BRIDGE']
 
kernel = "PATH/vmlinuz"
ramdisk = "PATH/initrd.gz"

Change PATH to the path where the VM files are located and BRIDGE to the name of the network bridge you are going to use. After this we can start the VM:

<xterm> $ sudo xm create ubuntu.xen </xterm>

To connect to the VM console and proceed with the installation you can use xm console command:

<xterm> $ sudo xm console ubuntu </xterm>

Use the menus to configure your VM. Make sure that you configure the network correctly as this installation will use it to download packages.

After the installation is done it will reboot again into the installation. You can exit the console pressing <CTRL>+<]>. Now you should shutdown the machine:

<xterm> $ sudo xm shutdown ubuntu </xterm>

The system is now installed in the disk image and now we must start it to configure it so it plays nice with OpenNebula. The configuratio we are going to do is:

  • Disable udev network generation rules and clean any that could be saved
  • Add contextualization scripts

To start the VM we will need a new xen description file:

name = "ubuntu1204"
 
memory = 512
 
disk = ['file:PATH/ubuntu.img,xvda,w']
vif = ['bridge=BRIDGE']
 
bootloader = "pygrub"

It is pretty similar to the other one but notice that we no longer specify kernel nor initrd and we also add the bootloader option. This will make out VM use the kernel and initrd that reside inside out VM image.

We can start it using the same command as before:

<xterm> $ sudo xm create ubuntu-new.xen </xterm>

And the console also works the same as before:

<xterm> $ sudo xm console ubuntu </xterm>

We log and become root. To disable udev network rule generation we should edit the file /lib/udev/rules.d/75-persistent-net-generator.rules and comment the line that says:

DRIVERS=="?*", IMPORT{program}="write_net_rules"

Now to make sure that no network rules are saved we can empty the rules file:

<xcode> # echo '' > /etc/udev/rules.d/70-persistent-net.rules </xcode>

Copy the file located at https://github.com/OpenNebula/one/blob/master/share/scripts/ubuntu/net-vmcontext/vmcontext to /etc/init.d and give it write permissions. This is the script that will contextualize the VM on start.

Now we modify the file /etc/init/networking.conf and change the line:

pre-start exec mkdir -p /run/network

by

pre-start script
  mkdir -p /run/network
  /etc/init.d/vmcontext
end script

and also in /etc/init/network-interface.conf we add the line:

/etc/init.d/vmcontext

so it looks similar to:

pre-start script
    /etc/init.d/vmcontext
    if [ "$INTERFACE" = lo ]; then
        # bring this up even if /etc/network/interfaces is broken
        ifconfig lo 127.0.0.1 up || true
        initctl emit -n net-device-up \
            IFACE=lo LOGICAL=lo ADDRFAM=inet METHOD=loopback || true
    fi
    mkdir -p /run/network
    exec ifup --allow auto $INTERFACE
end script