Thursday, December 16, 2004

VMWare - Virtual to Physical with Free Tools

This article describes how to take a physical machine and make a virtual copy of it for use within the VMWare virtual environment. This could be very useful for testing real world configurations. VMWare sells a tool that does this for you, but the following process is done with open source tools, primarily dd.

First, attach the physical HDD to your VMWare host machine. Theoretically you could use a HDD case that connects with USB. However I had difficulty getting USB to work inside my virtual machine with the external HDD interface. I just hooked the physical HDD up to the IDE chain to simplify.

Second, dump HDD to a file. Disk dump (dd) writes block devices byte for byte, it doesn't care about the filesystem or the boot sector. Assuming that /dev/hda is your primary host disk (and you are running Linux) mounted at / and /dev/hdb is the physical disk you wish to clone and is not mounted; run this command to create the image file file:

dd if=/dev/hdb of=/mnt-point/other-systems-hdd.img

Third, create a new virtual machine and boot into Linux. Knoppix Linux is the key component in this process, it is a version of Linux that runs entirely from a CD (it uses a ramdisk). Here are some guidlines for creating your virtual machine:

  • Choose the operating system that you are attempting to clone, for instance Windows 2000.
  • Make the disk at least as big as the HDD you are cloning. Don't allocate the entire disk at once (let it grow).
  • After the initial wizard you will want to edit your virtual machine and add the partition that contains your .img file (you will have to to select physical disk).

Put the Knoppix CD in and boot your new virtual machine from this CD.

Next, write the image to the VMWare virtual system disk. Once you have booted into Knoppix you will write your disk image to the virtual system disk. VMWare sets up virtual disks when you are booted into your virtual environment. The system disk will be /dev/hda (supposing you chose IDE, SCSI would be /dev/sda). The second disk that you added to your virtual machine in step #3 will now be known to Knoppix as /dev/hdb. First you need to mount the drive that contains your image file (/dev/hdb):

mount /dev/hdb

Knoppix creates a mount point for you /mnt/hdb1 (or something similar, if it doesn't create this mount point you will have to manually mount the drive). Then write the contents of your image file to the new VMWare virtual system disk with this command:

dd if=/mnt-point/other-systems-hdd.img of=/dev/hda

Last, reboot your virtual machine. Reboot the virtual machine and remove the Knoppix CD. If things went as expected it should begin booting into your cloned virtual system.

Further Reading

No comments: