In this article I would like to give a short instruction how to convert multipart vmdk images into single file (raw) images to use on a Xen host. My environment is a SLES11-SP4 Xen hosts, the instances I want to run are SLES12 VMs created with VMware.
So basically, you just have to convert all vmdk files into raw files, cat
them into a single file and make it bootable.
Okay, maybe it’s not that simple if you don’t have much experience, so I’ll break it down into single steps.
Convert vmdk to raw
I used qemu-img from qemu package to convert the vmdk files. It’s a single line command, you just have to know which files are relevant (I didn’t, so I had to find out first). After unzipping the provided WMware image you see a list like this:
server2-0-s001.vmdk server2-0-s002.vmdk server2-0-s003.vmdk server2-0-s004.vmdk server2-0-s005.vmdk server2-0.vmdk server2-1-s001.vmdk server2-1-s002.vmdk server2-1-s003.vmdk server2-1-s004.vmdk server2-1-s005.vmdk server2-1.vmdk server2.nvram server2-s001.vmdk server2-s002.vmdk server2-s003.vmdk server2-s004.vmdk server2-s005.vmdk server2.vmdk server2.vmsd server2.vmx server2.vmxf
You just need the files containing a “-s[001-005]” in the file name for conversion. To confirm that look into the file types, you’ll see this:
root@xen-host:~ # file server2.vmx server2.vmx: a /usr/bin/vmware script, ASCII text executable root@xen-host:~ # file server2.vmdk server2.vmdk: ASCII text root@xen-host:~ # file server2-s001.vmdk server2-s001.vmdk: VMware4 disk image
Note that in this case I have 3 hard disks I want to convert.
So as already stated, I’ll just convert the files “server2-s[001-005].vmdk” for the first disk, “server2-0-s[001-005].vmdk” for the second disk and “server2-1-s[001-005].vmdk” for the third disk by entering these commands, one for each disk:
for file in `ls server2-s*` ; do qemu-img convert -f vmdk $file -O raw ${file/.vmdk/.raw}; done for file in `ls server2-0-s*` ; do qemu-img convert -f vmdk $file -O raw ${file/.vmdk/.raw}; done for file in `ls server2-1-s*` ; do qemu-img convert -f vmdk $file -O raw ${file/.vmdk/.raw}; done
This may take a while, you can write a script to complete this task more elegant, of course.
A short explanation: the ls
commands list all files containing the “-s”, “-0-s” and “-1-s” in the file name, these are the only files I need. The selection automatically contains only .vmdk files. Every file in the selected list is converted by qemu-img, the “-f” flag reads the source’s disk image format (vmdk), “$file” is the selected file in this loop, “-O” specifies the output disk format (raw), and finally the file is renamed to “.raw”.
The converted vmdk files are now raw files:
server2-0-s001.raw server2-0-s002.raw server2-0-s003.raw server2-0-s004.raw server2-0-s005.raw server2-1-s001.raw server2-1-s002.raw server2-1-s003.raw server2-1-s004.raw server2-1-s005.raw server2-s001.raw server2-s002.raw server2-s003.raw server2-s004.raw server2-s005.raw
Make it one
Now you cat
the raw files:
cat "server2-s*.raw" > server2-hd0.img cat "server2-0-s*.raw" > server2-hd1.img cat "server2-1-s*.raw" > server2-hd2.img
This may also take some time, but in the end you have three disk images:
root@xen-host:~ # ls -1 3125_server2_hd0.img 3125_server2_hd1.img 3125_server2_hd2.img
Make it bootable
These images are not bootable yet as there is no xen-kernel installed. To make that happen you have to boot the image containing the partition table with a SLES12-DVD.iso.
You can run fdisk -l <IMAGE-FILE>
to check where the partition table is, usually it would be the first one, but just to be sure:
root@xen-host:~ # fdisk -l 3125_server2_hd2.img Disk 3125_server2_hd2.img: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk 3125_server2_hd2.img doesn't contain a valid partition table
root@xen-host:~ # fdisk -l 3125_server2_hd1.img Disk 3125_server2_hd1.img: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk 3125_server2_hd1.img doesn't contain a valid partition table
root@xen-host:~ # fdisk -l 3125_server2_hd0.img Disk 3125_server2_hd0.img: 53.7 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0005d896 Device Boot Start End Blocks Id System 3125_server2_hd0.img1 2048 4192255 2095104 82 Linux swap / Solaris 3125_server2_hd0.img2 * 4192256 83892223 39849984 83 Linux
Alright, now I have to boot “3125_server2_hd0.img” with an attached DVD. As there are many ways to accomplish that, I’ll leave that to you. Just a short description of my way:
I did it with virt-manager. I selected the converted “3125_server2_hd0.img” as the VM’s hard disk, but booted from DVD. During installation screen I switched from GUI to console to be able to perform chroot
on the VM and installed the missing xen-kernel from DVD. I had to practice it a couple of times, but meanwhile it can be completed quite fast. I won’t bother you with details on how to perform chroot
, I guess everyone who reads this knows more about that than me ;-) If there is anyone who would like to know the required steps in detail, please comment this post. I’d be glad to give more detailed instructions as I have been searching myself quite a while before I was able to manage that.
Anyway, if you have installed the xen-kernel, you can “destroy” that VM, modify the automatically created config file to use the right disks and/or DVDs and try to boot, it should work now.
Hope this helps!