User Tools

Site Tools


This will document the steps necessary to convert a singe-partition image (a la Xen) to a full disk image suitable for use with KVM.

Essentially, we need to make a disk with the partitions laid out in such a way that the QEMU virtual device can find them. For this first iteration, we are only going to try to create a device with a root and swap partition.

First, create an empty disk (raw format)

qemu-img create -f raw 10G starworker.img

Next, perform a fresh install of the OS (in a VM) that you wish to migrate, taking care to make the root partition at least as big as the partition image.

Next we will need to mount the root partition of the VM offline. To do this, we will need to use fdisk on the disk image to find the start of the root partition.

fdisk -lu starworker.img

The start column contains the offset, but the units are not bytes. The fdisk output will contain the units.

Now mount the both the new and old filesystems and copy the files.

mount -o loop starworker_part.img /mnt/looppart/
mount -o loop,offset=$(( $START * $UNITS )) starworker.img /mnt/loopdisk/
cp -a /mnt/looppart/* /mnt/loopdisk

When copying the files, make sure that you don't overwrite the /boot/ directory on this disk image. This probably won't be an issue, because the partition image probably doesn't contain a /boot/ or if it does, it would be empty. (That's why we're going through this process in the first place!)

Now, you should be ready to boot the new image. It should be the same as the old image, only now we have a disk image with a bootloader, kernel, and initrd.

converting_a_partition_image_to_a_disk_image.txt · Last modified: 2011/09/10 17:37 (external edit)