Paravirtualize an Ubuntu VM using XenServer

Paravirtualize an Ubuntu VM using XenServer

Convert a Ubuntu 11.10 DomU from HVM to PV using XenServer 6.0 is not trivial

In the ComodIT project, every ways to boot virtual machines using OpenStack are tested. It happens that one of these methods is only available using VMs hypervised with XenServer. A documentation explains how to install and configure OpenStack in a Ubuntu DomU to control a Dom0 XenServer. However, this DomU have to run in paravirtualized (PV) mode rather than in hardware virtualization (HVM) mode.
Such a conversion from HVM to PV isn’t trivial, especially for the Oneiric release. This article explains how to convert a Ubuntu 11.10 DomU to PV using XenServer 6.0.

Date: 30 November 2011

Expertises:

Engineering of complex IT systems 

About project: ComodIT 

1. Create and install the VM in HVM mode

  1. create the VM from the "Other install media" template. The VM name shouldn’t contain whitespace.
  2. attach the Ubuntu 11.10 ISO image to the VM DVD drive
  3. boot the VM
  4. while partitioning the hard drive, choose Ext3 rather than Ext4, because ’pygrub’, the XenServer bootloader for the PV mode, can’t read Ext4. If you wish to benefit from Ext4 advantages anyway, then you’ll have to create a /boot partition in Ext3 and the / partition in Ext4
  5. finish install and reboot VM

2. Preparing VM conversion

  1. connect to VM console through XenCenter and install an SSH server
    sudo apt-get install openssh-server
  2. create a new console for Xen and replace all ’tty1’ occurences by ’hvc0’
    sudo cp /etc/init/tty1.conf /etc/init/hvc0.conf
    sudo vi /etc/init/hvc0.conf
  3. identify grub2 default entry and copy it
    cat /boot/grub/grub.cfg
    [...]
    menuentry 'Ubuntu, avec Linux 3.0.0-12-generic' --class ubuntu --class gnu-linux --class gnu --class os {
            recordfail
            set gfxpayload=$linux_gfx_mode
            insmod gzio
            insmod part_msdos
            insmod ext2
            set root='(hd0,msdos1)'
            search --no-floppy --fs-uuid --set=root 51a2ba97-2521-44d7-9b08-316b7059db89
            linux        /boot/vmlinuz-3.0.0-12-generic root=UUID=51a2ba97-2521-44d7-9b08-316b7059db89 ro   quiet splash vt.handoff=7
            initrd        /boot/initrd.img-3.0.0-12-generic
    }
    [...]
  4. because of a regression since Ubuntu Natty release, the xen module doesn’t seem to be loaded anymore into the initramfs. That can be corrected like this:
    sudo echo "xen-blkfront" >> /etc/initramfs-tools/modules
    sudo update-initramfs -u
  5. shutdown the VM
  6. create a snapshot so that you can fallback to a stable version in case of trouble later on

3. Conversion using makepv.sh

  1. ssh on the XenServer host and identify the name of the VM you wish to convert to PV mode
    ssh root@<XenServer>
    xe vm-list
  2. download the makepv.sh. It will:
    • change the bootloader from HVM to PV mode
    • prompt for kernel path (/boot/vmlinuz-3.0.0-12-generic),
    • prompt for kernel parameters (root=UUID=51a2ba97-2521-44d7-9b08-316b7059db89 ro   quiet splash vt.handoff=7)
    • prompt for initrd path (/boot/initrd.img-3.0.0-12-generic)
    • convert VM hard drive
      chmod +x makepv.sh
      ./makepv.sh <vm name> # sans espace

4. Install XenServer tools

  1. empty the DVD drive in order to avoid an error related to two bootable drives detected, then boot the VM
  2. from XenCenter, attach xs-tools.iso to the DVD drive
  3. mount the image and install guest tools
    ssh <vm ip address>
    sudo mount /dev/cdrom1 /media/cdrom
    cd /media/cdrom/Linux
    sudo dpkg -i xe-guest-utilities_6.0.0-743_amd64.deb
  4. unmount the volume and reboot
    sudo umount /media/cdrom
    sudo init 6
  5. ssh on the VM and define runlevels of the services
    ssh <vm ip address>
    sudo update-rc.d -f xe-linux-distribution remove
    sudo update-rc.d xe-linux-distribution defaults
  6. reboot for the last time. You can now enjoy your Ubuntu Oneiric Ocelot 11.10 paravirtualized virtual machine. The console in XenCenter is available again. However, the X server will complain that it doesn’t find a driver and Xorg will fail launching. This is the dark side of paravirtualization. If you ever happen to figure out how to run Xorg in PV mode, I’ll be happy to update this article.

References