Oct 4, 2009

P2V: Hassles Cloning a Linux Installation as a Virtual Machine

After some reading around, I settled on these tools to get the job done:

  • A Knoppix boot disc
  • An 8Gb USB pen drive
  • VirtualBox
  • dd, and fdisk
All free to use, all robust.

I took a look at my partition table on my physical Ubuntu box:
$ fdisk -l /dev/hda
Disk /dev/hda: 100.0 GB, 100030242816 bytes
255 heads, 63 sectors/track, 12161 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 1 522 4192933+ 83 Linux
Next, I copied the contents of hda1 to my pen drive:
$ dd if=/dev/hda1 of=/media/usb/hda1.raw bs=4096
I also copied the MBR:
$ dd if=/dev/hda of=/media/usb/mbr.raw bs=512 count=1
Back to my host computer and my fresh VirtualBox VM. I booted the VM using Knoppix, and then created the same partition layout (using fdisk expert mode to change the number of heads and sectors to match). I rebooted for good measure.

After booting again in Knoppix I copied first the hda1 into place:
$ dd if=/media/usb/hda1.raw of=/dev/hda1 bs=4096
Then I copied the MBR:
$ dd if=/media/usb/mbr.raw of=/dev/hda bs=512 count=1
I rebooted, and my cloned system wouldn't start. Restarting with Knoppix, I confirmed that I have the following problem:
$ sudo mount /dev/hda1 ~/temp
mount: /dev/hda1: can't read superblock
Now, I've tried this a number of different ways: without the mbr writing step, without tweaking the heads and sectors to match, with a partition larger than the original one - all to no avail.

I'm not finding other people with this same problem. Does anyone have any ideas?

3 comments:

Aidan Ryan said...

Try booting from the rescue disc for the linux distrib.

Curious Attempt Bunny said...

Thanks for that. Right now I'm trying a straight up dd of /dev/hda to see if that changes anything.

Curious Attempt Bunny said...

Doing a straight copy of /dev/hda produced a different problem:

$ sudo fdisk -l
Unable to seek on /dev/hda

:(