Howto: Xen+LVM guest OS to VMWare guest conversion
I have several virtual machines (including this webserver) hosted on a Xen Linux host. I wanted to be able to use the same linux configuration in my VMWare player on my desktop for testing.
Here are the rough steps that I went through to convert a linux guest that was on a LVM partition to a raw file on my Windows Desktop that the VMWare player could use.
Software: Redhat Fedora Core 6, Xen, LVM, VMWare Player 2.0.0
1. The Xen guest is a running a paravirtualized kernel, hopefully I will upgrade the cpu soon. So, if you are running a Xen specific kernel like I am, you must install the regular, non-paravirutalized kernel. Login as root onto the guest and run:
[root@xen-guest ~]# yum install kernel.i686
2. Restart the guest and confirm that the new kernel is in the grub startup menu and that the default kernel is still the paravirtualized kernel (don’t want to mess up the existing system). Once confirmed, halt the guest.
3. Map the LVM partition. As root on the Xen Host type:
[root@xen-host ~]# kpartx -av /dev/VolGroup00/ImageData00
add map ImageData00p1 : 0 6281352 linear /dev/VolGroup00/ImageData00 63
(I have always done the mapping, I am not sure if this is required.)
4. Using dd, copy the partition to an image file. As root on the Xen Host type:
[root@xen-host ~]# dd if=/dev/VolGroup00/ImageData00 of=/some/path/ImageData00.img bs=512
6291456+0 records in
6291456+0 records out
3221225472 bytes (3.2 GB) copied, 276.703 seconds, 11.6 MB/s
This step will take a while, the of should be somewhere with lots of space.
Note: copy down the number of records in/out, this is needed later.
5. Unmap the LVM partition. As root on the Xen Host type:
[root@xen ~]# kpartx -dv /dev/VolGroup00/ImageData00
del devmap : ImageData00p1
6. Run fdisk on the image file to get the disk geometery. As root on the Xen Host type:
[root@xen FileBackedHosts]# fdisk /dev/VolGroup00/ImageData00
Command (m for help): p
Disk /dev/VolGroup00/ImageData00: 3221 MB, 3221225472 bytes 255 heads, 63 sectors/track, 391 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/VolGroup00/ImageData00p1 * 1 391 3140676 83 Linux
Note: copy down the head, sectors/track and cylinders values.
7. Copy the image file to the Windows desktop, I used pscp to move it over.
8. Grab a copy of an empty VMWare virtual machine (here is mine). Edit the *.vmdk file to:
version=1
CID=e37454cd
parentCID=ffffffff
createType="monolithicFlat"
# Extent description RW 6281352 FLAT "ImageData00.img" 0
# The Disk Data Base #DDB
ddb.adapterType = "ide" ddb.geometry.sectors = "63" ddb.geometry.heads = "255" ddb.geometry.cylinders = "391" ddb.virtualHWVersion = "3" ddb.toolsVersion = "0"
Replace your sectors, heads and cylinders with your values from earlier. Replace “6281352″ with your records in/out number.
9. Start the VMWare image. On first boot, choose the regular kernel in the grub startup menu, edit it to remove the “console=…” and add “single” to boot into single user mode.
10. Once booted in single user mode, edit the /etc/inittab to comment out “co:2345:respawn…” and uncomment other “1:2345:respawn…” consoles. Reboot and choose the regular kernel again.
11. Once booted, edit the /boot/grub/grub.conf and change “default=1″ to “default=0″, this should be the regular kernel. From now on, the regular kernel should boot with no problems.