Convert a XenServer HVM domain to PV (paravirtual) and back again

After wading through complicated and poorly organized how-to’s for converting a XenServer HVM domain to PV (paravirtual), I wrote a quick and dirty tool to make the conversion in both directions. I was able to get Debian Lenny 5.0.8 paravirtual domain running without any issues. All memory, CPU, disk, and network stats shows up perfectly in XenCenter, too!

Usage:

[root@vps1a ~]# ./vmtool.pl
Usage: vmtool.pl --cmd (hvmtopv|pvtohvm) ([--vm name-label] or [--uuid uuid]) [--root partition_num]

Here’s an example of it running:

[root@vps1a ~]# ./vmtool.pl --cmd=hvmtopv --vm=c1068vm1
uuid = 7cf68fa6-3d07-0869-fa2d-40c89a724042
cmd = hvmtopv
Changing HVM-boot-policy
Changing PV-args
Setting disk boot flag
***Please update /etc/fstab, /etc/inittab. then reboot VM
Done.

If your root partition is anywhere except the 1st partition on the virtual disk, specify the partition number with the –root argument.

To reverse the process, change the –cmd argument from ‘hvmtopv’ to ‘pvtohvm’.

PV domains can be made into templates within XenCenter, so you don’t have to run the script all the time.

Here are steps to take on your domain after changingtour HVM domain to PV. Make sure to complete these steps (except 4) in HVM mode before rebooting. After the reboot, you can install the Xen tools and reboot again.

1. Install a Xen-aware kernel and make it the default boot option in grub.conf or menu.lst.
2. Update /etc/fstab entries – Example: replace /dev/hda1 with /dev/xvda1, /dev/hdd with /dev/xvdd, ect.
3. Update /etc/inittab – Example: replace tty1 with hvc0 so that the Console works properly
4. Make sure the /boot or / partition (depending on your partition layout) has the boot flag set. THIS IS IMPORTANT!
5. Install the Xen tools from the xs-tools CD so that memory, disk, and network usage appears properly in XenCenter

Get the script here:

Download Link

It’s a shame that XenServer still caters to the Windows crowd by making HVM domains the default, with no way to easily switch to PV. Hopefully this script makes life easier for someone.

7 Responses to Convert a XenServer HVM domain to PV (paravirtual) and back again

  1. Sanooj says:

    Cool.. you made that all complicated process to a single line.. 🙂

  2. nugrahadi says:

    does it work for xen 4?

    1. Randy says:

      it was originally made on Xen4, so yes it should work maybe with some minor change

  3. jamie says:

    think this would work with xcp?

  4. Dan says:

    Getting a “Caller not allowed to perform this operation” after converting a VM from HVM to PVM. Any ideas?

    -dan

    1. Randy says:

      For some reason the pv bootloader is not being set to pvgrub, and I haven’t had time to update the code. Compare the xe params between a working PV domain, you may find the bootloader is empty on the converted domain. Also compare grub.conf/menu.lst as sometimes that could be the problem if pvgrub can’t parse it or a non-PV kernel is set default.

  5. Dan says:

    Hi,

    Thanks for the script, just keep in mind that you might also have to update /boot/grub/menu.lst or grub.cfg with the same /dev/hd* => /dev/xvd* if Grub is not configured to use UUIDs!