Converting An UbuntuTM Physical Machine To A Virtual Machine (VMWare)

Step 1: Creating A Backup Disk/Partition Image

  1. Prepare a ClonezillaTM Live CD or USB.
  2. Boot the physical machine from the ClonezillaTM Live CD or USB.
  3. Follow the ClonezillaTM wizard to convert the desired disk or partitions into an image (a folder containing some files).

Step 2: Creating A Virtual Machine To Be Cloned To

  1. Use VMware Player to create an empty virtual machine. When creating the virtual machine, choose not to install any OS for now. When specifying the hard drive size, make sure it is larger than the disk where the clone image is from. Note, even if your backup image is only from some partitions in that physical hard drive, the destination (virtual) disk size still needs to be equal to or larger than that entire physical hard drive. This is something related to the physical partition table stored in the image. If the virtual disk is smaller than the physical disk, ClonezillaTM won't allow you to proceed.
  2. Specify the virtual CD/ROM drive to be linked to an iso file that represent a Live OS. Here, for the Live OS, I recommend UbuntuTM LiveCD. One can go to "Try Ubuntu" mode by booting from UbuntuTM installation iso file. This Live OS will be used for the first boot of the virtual machine, so we can format and partition the destination virtual disk before cloning anything onto it.
  3. Increase boot delay of the virtual machine to specify boot order. Do this by adding the following line to the *.vmx file of the virtual machine: bios.bootDelay = "10000". This delay the booting by 10000 milliseconds (10 seconds).
  4. Format and partition the destination virtual disk via the Live OS. Start the virtual machine. When it pauses (for the 10 seconds we delayed above), press ESC to invoke the boot menu. In the boot menu, select to boot from CD (where your Live OS resides). This will lead us into the Live OS. In the Live OS, use whichever partitioning program to partition the destination virtual disk. I used GParted in UbuntuTM for this purpose. After this is done, shut down the virtual machine.

Step 3: Loading The Backup Image To The Virtual Disk

  1. Boot from ClonezillaTM in the virtual machine. Change the virtual CD/ROM to link it to the iso file of ClonezillaTM Live. Then just like booting from the Live OS in the previous step, boot from CD to go into ClonezillaTM in the virtual machine.
  2. Follow the ClonezillaTM wizard to restore. In ClonezillaTM, you might want to use the expert mode to go through the process. In expert mode, you can specify to manually create partitions on the destination disk when the old partition layout (what we did above) is different from the partition layout of the old physical disk as specified in the backup image.

Other Thoughts:

To convert a Windows PC to a virtual machine, the task is much easier and more straight-forward with VMWare VCenter Converter. However, if you want to follow a path similar to this tutorial for Windows, it should be viable. In addition to Clonezilla, Windows7 also comes with a system image creating utility in its Backup and Restore center (check here).

VCenter Converter is also an alternative to the current approach. However, VCenter Converter can only be installed on a Windows machine and the conversion of a Linux system should be done as converting a remote source. In other words, one runs the Converter in Windows and specify the IP address of the Linux system that is to be converted. I tried this method before, but the problem for me was that the Converter cannot gain root access to the remote Ubuntu system via my username, which was already an administrator. I found a plausible solution in VMWare's knowledge base (1008164), but I didn't succeed by following it.

Note, there are other alternatives to Clonezilla, for example, Partimage and FSArchiver. If you use Partimage, be careful since it does not support imaging of an ext4 file system (ref), which is popular for Linux OS nowadays and your Linux system is very likely to be on. However, FSArchiver does not have this problem (ref).

[:(] Turned out I didn't actually succeed in Step 3 when carrying my Ubuntu from a dual-boot physical machine to a virtual machine. For the dual-boot machine, I only used Clonezilla to image the Ubuntu related partitions. When carrying this image onto the virtual disk, Clonezilla still did well. However, the virtual machine wouldn't boot from this virtual disk. I checked why and found that, although content-wise Clonezilla only imaged those of the Ubuntu partitions, when it came to disk layout, all partitions were covered. As a result, when restoring from the image to the virtual disk, Clonezilla created partitions proportionally (if not exactly) the same to the physical disk, resulting in both Ubuntu partitions and non-Ubuntu partitions (this was also why the size of the virtual disk needed to be no smaller than the physical disk). Then, the Ubuntu partitions were restored with the backup content, leaving the non-Ubuntu partitions empty. As a result, probably, the Master Boot Record (MBR) was not correctly installed/restored onto the virtual disk (remember that the virtual disk was a fresh disk without any existing boot mechanism), leaving it an unbootable hard drive. [:)] I resorted to FSArchiver eventually and succeeded. What I did was: 1) Similar to Step 1 but using FSArchiver, 2) Similar to Step 2 but creating a loaded virtual machine with Ubuntu installed, and the virtual disk was only larger than the imaged partitions, 3) Overwrote the Ubuntu partitions in the virtual machine with the imaged partitions. As a result, since the MBR was already there before restoring from the image backup, the virtual machine booted correctly from the virtual disk. I happily saw my old Ubuntu in VMWare Player. But be aware, there was still a little problem related to the swap partition. At booting, the restored Ubuntu warned me of error finding the swap partition every time, since I didn't image and restore the swap partition from the physical machine. Comments and suggestions to clarify this issue and provide fixations are welcome via email.

Useful References:

  1. Virtualizing a Linux System (Creating a Linux VM P2V) (done using SystemRescueCD and Partimage)
  2. How do I migrate currently installed Ubuntu to a Virtual Machine?
  3. Free Imaging Software - CloneZilla & PartImage - Tutorial (old, new)
  4. Ubuntu BackupYourSystem Series
  5. Accessing the BIOS when the POST screen clears too quickly (VMWare KB 1004129)