Converting a PV vm back into an HVM vm

I have been doing some Oracle VM benchmark stuff in the last week or 2 in my off hours and yesterday I wanted to convert one of my VMs that was based on a paravirt kernel into a vm that just boots as a regular hardware virt VM with a standard x86-64 kernel.

It took me a little while to figure out the fastest way so now that I have it pretty much down I wanted to share the steps.

A PV kernel uses pygrub and a paravirt kernel image that lives on the vm image virtual disk. since this disk image does not have to be bootable it doesn't contain a boot sector and if you just restart the VM in hvm mode the virtual bios will just not do much as it can't start the boot process from disk

The first thing I do is make a backup of my vm.cfg file :-) and then edit it as follows :

the original file contains :

bootloader = '/usr/bin/pygrub'

I replace that with :

acpi = 1
apic = 1
builder = 'hvm'
device_model = '/usr/lib/xen/bin/qemu-dm'
kernel = '/usr/lib/xen/boot/hvmloader'

then changing the disk files.

I change my xvd disks to hd disks and I copy over the iso image of my instal lDVD. In the case of my VM template it was based on OL5U4 So I downloaded Enterprise-R5-U4-Server-x86_64-dvd.iso and added it as a cd device.

disk = ['file:/ovs/OVM_EL5U4_X86_64_11202RAC_PVM/System.img,xvda,w',
'file:/ovs/OVM_EL5U4_X86_64_11202RAC_PVM/Oracle11202RAC_x86_64-xvdb.img,xvdb,w',
]

to

disk = ['file:/ovs/OVM_EL5U4_X86_64_11202RAC_PVM/System.img,hda,w',
'file:/ovs/OVM_EL5U4_X86_64_11202RAC_PVM/Oracle11202RAC_x86_64-xvdb.img,hdb,w',
'file:/ovs/OVM_EL5U4_X86_64_11202RAC_PVM/Enterprise-R5-U4-Server-x86_64-dvd.iso,
hdc:cdrom,r',
]
boot='d'

for the network devices (vifs) I change :

vif = ['bridge=xenbr2,type=netfront']

to

vif = ['bridge=xenbr2,type=ioemu']

That should do it.

Next, inside the VM, I copy over the regular kernel rpm that I want to end up running in hvm mode. In this example case it was : kernel-2.6.18-164.0.0.0.1.el5.x8664.rpm. I will use that later on in the process. I put this kernel simply in /root

At this point I just start the vm with xm create vm.cfg and start my vnc console to the vm console. Oracle Linux will boot from the iso image, I just go through the install steps and click on UPgrade existing (not re-install). Because the VM is the same as the ISO the install won't actually do anything and it will run through instantly.

When the "Reboot" button pops up, don't reboot. Switch to the command prompt console. hi alt-f2 to go to the shell prompt. Now it's easy :

umount /mnt/sysimage/boot
cd /mnt/sysimage
chroot .
mount /dev/hda1 (if that was your /boot partition)
export PATH=/sbin:$PATH (just to clean that up)

edit /etc/modprobe.conf and comment out the xen modules (just put a # in front)

Install grub. if your /boot is hda1 then that is (hd0,0)
$ grub
root (hd0,0)
setup (hd0)

exit grub

now you have a good bootsector, grub installed and you have your grub.conf file

Install the new kernel
cd root (this is your old /root in your pv image)
rpm -ivh

remove (or comment out) boot='d' in your vm.cfg

restart the VM and you should be good to go, regular grub should start and load your environment.

Caveats : this assumes you used labels for your filesystems. if /etc/fstab were to have devices listed then you would have to rename these device before rebooting as well. If you had a /dev/xvda disk then this would be /dev/hda or /dev/sda.

All in all it is a relatively short and simple process.


Comments:

Wim,

Great post. If I want to convert the Xen kernel for a VM with OVM 3.0.3 to a normal kernel that can be exported to another hypervisor such as VMware, would I follow this same process? I cannot find any documentation from Oracle on how to do this.

Thanks
Ben Prusinski, Oracle ACE

Posted by Ben Prusinski on March 31, 2012 at 04:10 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Wim Coekaerts is the Senior Vice President of Linux and Virtualization Engineering for Oracle. He is responsible for Oracle's complete desktop to data center virtualization product line and the Oracle Linux support program.

You can follow him on Twitter at @wimcoekaerts

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
9
10
11
12
13
14
15
16
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today