This page describes my investigation into converting a Linux VM from Virtual PC to VMWare and how I completed the conversion. I have an Ubuntu 6.06 server installation that I've been running in Virtual PC (2004 + 2007) on a Windows host for a while. I had a few requests for copies of the installation for running in VMWare so I investigated converting my VM image from Virtual PC to VMWare. 

 VMWare

 I used VMWare server as it’s free to download and run and has a pretty full set of features.

 VMWare provides an import function to convert Virtual PC images into VMWare images but it only works if the guest OS is Windows. Attempting to use the import function on my VirtualPC/Ubuntu installation gave an error saying that boot.ini could not be found.

 VMWare also have a standalone convertor program that claims experimental support for converting linux virtual machines from VirtualPC to VMWare but unfortunately this is only in the enterprise version of the convertor that has to be paid for and so was out of my league.

 

 Manual Conversion

At this point I reached the conclusion that the VMWare tools wouldn't work for me and I would have to do the conversion manually. I was surprised that I couldn't find any pointers on the web for how to do the conversion manually hence this article. I didn’t really have a plan when I started so my method was bitty and probably sub-optimal, I used an Ubuntu LiveCD and SystemRescueCD LiveCD (http://www.sysresccd.org), I used a lot of disc space on the host but the conversion did work. The exact method might not work for you, especially if you are using a different Linux distribution, but hopefully it will save you some effort.

 

Different virtual hardware

Virtual PC and VMWare Server simulate slightly different sets of hardware. I used lshw, lspci and lsmod to investigate the virtual hardware in my VirtualPC installation and booted the Ubuntu 7.04 LiveCD in the VMWare environment to do the same for VMWare. 

It turned out that VMWare wanted the following Linux modules on top of the ones that were in use on Virtual PC:

  • agpgart
  • intel_agp
  • md_mod
  • mii
  • mptbase
  • mptscsih
  • mptspi
  • pci_hotplug
  • pcnet32
  • scsi_mod
  • sg
  • shpchp
  • vga16fb
  • vgastate

 I used insmod to check that all of these modules were available in the Ubuntu 6.06 installation that I wanted to convert. They were, so it looked like it would be a reasonably straightforward conversion after all.

 

The conversion

The basic process is:

  1. set up networking
  2. transfer partitions from Virtual PC to host
  3. create new VM in VMWare
  4. transfer partitions from host to new VM
  5. reinstall grub
  6. boot new VM.

The following steps provide more detail.

 

Setup networking using the loopback adapter

1. I installed the Windows loopback network adapter in the host to avoid sending the entire VM over a physical network. On XP the loopback adapter is installed from the Control Panel’s Add Hardware applet. When the wizard asks, click “Yes I have connected the hardware”.  Next select Add new hardware device from the Installed Hardware list. On the next page select Install the hardware that I manually select from a list.  When the list of device categories appears select Network Device, then Microsoft and Microsoft Loopback Adapter. You should now find that the host PC has an additional network adapter. Enable the adapter and it will automatically give itself an IP address on the 169.254.x.x subnet, e.g. 169.254.178.211.

2. From Windows Explorer on the host I shared a folder (e.g. //169.254.178.211/share); this will be used to store images of the virtual PC hard disc contents. 

3. From the VirtualPC settings dialogue I mapped the first network adapter of my VirtualPC VM to the newly created loopback adapter.

 

Transfer partitions from VirtualPC to host 

4. I booted the VirtualPC VM from the SystemRescueCD.

5. I configured the network adapter on the Virtual PC VM using the following from the command line 

ifconfig eth0 169.254.1.1

6. In the Virtual PC VM I created a mount point for the shared host folder and mounted the shared host folder 

mkdir /mnt/win

mount -t smbfs –o lfs,username=x,password=y //169.254.178.211/share /mnt/win

I had two partitions in my VirtualPC image, /dev/hda5 containing /boot in an EXT3 filesystem and /dev/hda6 containing the rest of the system in an EXT3 filesystem on top of a logical volume called “root” on a volume group called “Ubuntu”. 

7. I copied /dev/hda5 to the host shared folder using

dd if=/dev/hda5 bs=1024000 > /mnt/win/hda5 

8. I’d planned to use partimage (hence the use of SystemRescueCD) but I couldn’t get it to work with an LVM partition. Instead, I activated the logical volume and then copied /dev/Ubuntu/root to the host shared folder using

vgchange –a y Ubuntu

dd if=/dev/Ubuntu/root bs=1024000 > /mnt/win/root 

9. Having safely copied the data partitions to my host I now shutdown the Virtual PC VM.

10. I created a new VM in the VMWare environment making sure to select IDE discs for the new VM (VMWare offers IDE or SCSI, Virtual PC supports IDE only). I configured the VMWare networks and VM network adapter settings to allow the new VM and host to talk to each other directly.

 

Create new VM in VMWare

11. I booted the SystemRescueCD LiveCD in the new VMWare VM and used parted to create partitions that matched those in my VirtualPC VM.

e.g. 

parted

> mkpart logical 0 256MB

> mkpart logical 256MB 3GB

12. On the VMWare VM I created an LVM physical volume in the second new partition, created a new physical volume containing the partition, activated it and created a logical volume with

pvcreate /dev/hda6

vgcreate Ubuntu /dev/hda6 -s 4MB

vgchange -a y Ubuntu

lvcreate -l715 -nroot Ubuntu

 

Transfer partitions from host to new VM

 I now had an empty partion and an active logical volume to transfer my virtual PC image into.

13. VMWare has a built in DHCP server that will give out addresses to interfaces on a VMWare virtual network. On the VMWare VM I activated its network interface, e.g.

dhcpcd eth0 

14. On the VMWare VM I created a mount point for the shared host folder and mounted that shared host folder that I’d used to store the partition images e.g.

mkdir /mnt/win

mount -t smbfs -o lfs,username=x,password=y //169.254.178.211/share /mnt/win 

15. On the VMWare VM I transferred the stored partitions to the new partitions and logical volume on the new VM, e.g.

dd of=/dev/hda5 bs=1024000 < /mnt/win/hda5

dd of=/dev/Ubuntu/root bs=1024000 < /mnt/win/root 

16. Finally I reinstalled grub on the new virtual hard disc (I did this by booting the VM again from the Ubuntu LiveCD, I imagine that grub is on SystemRescueCD).

e.g.

grub

> root (hd0,4)

> setup (hd0)

 

Boot new VM

17. I then rebooted the VMWare VM and the brain transplant was complete! 

I did not copy the swap partition over (there’s no point). If you want a swap area for your new VM then you’ll need to create a partition (either an extra partition with parted or a logical volume) and then create and activate a swap file.