CentOS v5.2 paravirtualised

Overview

How to add paravirtualisation to CentOS v5.2.

Problem

In order to replicate a customer environment, we have some CentOS 5.2 virtual machines for development. However CentOS 5.2 does not feature any paravirtualisation and thus the performance of both the guest and host machines suffers.

Solution

By creating a custom Linux kernel with paravirtualisation support and making some adjustments to the initial ramdisk used for booting, we created a paravirtualised CentOS 5.2 machine.

Howto

First of all we must build the kernel:

  • download an appropriate kernel from kernel.org (I used 2.6.28)
  • unpack this kernel in /usr/src/linux
  • uncompress the current /boot/config*gz file to /usr/src/linux/.config
  • enable all the VIRTIO facilities
    • make oldconfig
    • this prompts for all new configuration options
    • use "make menuconfig" initially then "grep VIRTIO .config" to check
    • I suggest ensuring at least these are selected:
    • CONFIG_VIRTIO=m
    • CONFIG_VIRTIO_BALOON=m
    • CONFIG_VIRTIO_BLK=m
    • CONFIG_VIRTIO_CONSOLE=m
    • CONFIG_VIRTIO_NET=m
    • CONFIG_VIRTIO_PCI=m
    • CONFIG_VIRTIO_RING=m
    • CONFIG_HW_RANDOM_VIRTIO was not set
  • sudo make binrpm-pkg
    • ensure you have write access to /usr/src/redhat
  • rpm -i /usr/src/redhat/x86_64/kernel*.rpm

Now we need to tweak the initial ramdisk:

  • edit /etc/modprobe.conf:
    • alias scsi_hostadapter virtio_blk
  • mkinitrd /boot/initrd-2.6.28.img 2.6.28
  • mkdir /tmp/initrd
  • cd /tmp/initrd
  • gunzip -c /boot/initrd-2.6.28.img | cpio -i
  • cp /lib/modules/2.6.28/kernel/drivers/{virtio/,net/virtio,block/virtio*} lib/
    • mkinitrd will have done virtio_blk but not all the dependencies
  • vi init inserting:
    • insmod virtio.ko
    • insmod virtio_ring.ko
    • insmod virtio_net.ko
    • insmod virtio_pci.ko
    • insmod virtio_blk.ko
  • vi etc/lvm/lvm.conf to add:
    • types = [ "virtblk", 16 ]
  • find . | cpio -o -H newc | gzip -c > /boot/initrd-2.6.28.img
  • edit /boot/grub/menu.lst to add a new entry

Finally, don't forget to edit /etc/libvirt/qemu/machinename.xml (or however you start KVM)

Closing thoughts

You may be able to short cut some of this by using a mkinitrd package from CentOS 5.3 instead, however we wished to stick with a stock installation as far as possible.