Switching from PV to HVM for a quick cd boot

Today I needed to boot a rescue system. Obviously all my virtual machines are running para-virtualized to allow live migration. So how can we switch a PV machine to HVM to allow CD booting?

First you will need to add a storage repository which hosts your ISO files. I just added a CIFS share and put my ISO onto it. Then use xe vm-list to determine the VM's UUID. Determine the name of the CD via xe cd-list. Attach the CD to the VM:

xe vm-cd-add vm=<vm_uuid> cd-name="<host_cd_drive_name_label>" device=3
xe vbd-list vm-uuid=<vm_uuid> type=CD params=uuid --minimal # get the cd uuid
xe vbd-param-set uuid=<cd_drive_uuid> bootable=true

The device number should be something like current vbd count + 1. Last thing we need to switch to HVM:

xe vm-param-set uuid=<vm_uuid> HVM-boot-params:order="dc"
xe vm-param-set uuid=<vm_uuid> HVM-boot-policy="BIOS order"

I am not sure if it's needed, but I did reset the PV-args (note them down if you want to switch back again) and set the CD as install method (I suppose that one isn't needed, since we are not installing):

xe vm-param-set uuid=<vm_uuid> PV-bootloader=""
xe vm-param-set uuid=<vm_uuid> other-config:install-repository=cdrom

Then fire up your machine and you are done!