Move a Linux system into a virtual machine

I wanted to create a copy of my production system in a virtual machine to have a playground for experimenting. For this I cloned my system partition and put it into a virtual environment.

These are the steps:

For the cloning I used the Clonezilla live-CD (http://clonezilla.org/). I used the beginner mode to create an image of my source partition onto an USB drive.

On the host machine, I started Virtualbox to create a virtual machine with a disk size that is a little bigger than the size of the source partition. I created a disk of fixed size.

Now I had to trick clonezilla into restoring the image file to another partition number. Clonzilla does not support this. My source partition was sda6 and my destination in the virtual machine was sda1. This link form the Clonzilla FAQ shows how to do it.

After that, I booted the virtual machine with the CD image of the Clonezilla live-CD, plugged in my external USB drive and used the beginner mode again to restore the image to the empty partition inside the virtual machine.

Before rebooting the new system inside the virtual machine, I had to fix some details. For this I switched to the command shell of the Clonezilla system.

  • /etc/fstab - I had to remove the UUIDs for the drives and had refer to /dev/sdaX instead.
  • /etc/hostname - I changed the hostname of the virtual machine.

To get the new system inside the virtual machine to boot, I had to fix grub. The easiest way for me was to use the Super Grub2 Disk (http://www.supergrubdisk.org/). Set as an CD image in the virtual machine, it will boot into the installed system and allowed me to fix GRUB2 by running “sudo update-grub” in a terminal.

After that, I removed the CD image and booted into the virtual system and it worked immediately. I did not even have to boot into a safe graphics mode. It simply worked.

If you are using a PAE kernel, make sure to enable this feature inside your virtual machine.

Back to top