Virtualizing a physical Linux machine

March 26th, 2009  |  Tags: , , , , ,  |  Leave a comment

Due to some hardware trouble with my main work machine, I’m presently working in a virtual machine on my personal computer. After a few dim trails, I found a pretty straightforward method to clone my work computer into a virtual machine image, so that I am able to work in the exact same environment I would have on my physical work computer. Here’s how to do it:

  1. Clone the drive using dd (the following example assumes your drive is /dev/sda and you have an external drive mounted at /media/removable:
  2. Use qemu-img to convert the raw bits of the drive to an image in the appropriate format for the virtual machine monitor you want to use (QEMU or VMWare):
  3. Create a new virtual machine that uses this drive image, using the interface for your preferred virtual machine monitor.

I was able to image and convert a 100 gb drive in around six hours. My drive was an LVM volume and the home partition was encrypted with LUKS; I was delighted to see that qemu-img handled these oddball features of my drive flawlessly. (I can’t think of a technical reason why these wouldn’t be supported, but I’m nonetheless inclined to be pleasantly surprised when things work as they should out of the box.)

Cross-posted at Chapeau