COnverting an LXC to a virtual machine

Ivan Fetch ivan at ivanfetch.com
Mon Jan 30 05:13:15 UTC 2012


Hello,

I'm replying to this, for the list archives, with the hope it may help someone else:

On Dec 11, 2011, at 10:58 PM, Ivan Fetch wrote:

Hello,

I would like to convert some LXC containers into virtual machines, and am looking for advice on how to do this while maintaining an accurate package database.

SO far, I have copied the contents of an LXC into an initial Ubuntu 10.04 installation, mixing the contents of the initial install with the contents of the LXC. A down side to this, is that dpkg does not know about packages which were installed in the initial installation, for example, kernel images, grub, Etc.

How can I register these packages who's files are installed, although they are not listed in the package database? ALternatively, is there a better way to turn an LXC into a more complete; bootable system?

Thanks,

Ivan.


I started with a base virtual machine, installed with Ubuntu 10.04, and no updates applied. I did not apply updates, because I don't want any packages in the base BM to be newer than those which will come from the LXC.

I saved a list of packages installed in the base VM: dpkg -l >packages.txt I adjusted this file so that it only contains a list of packages (no version numbers or other info from dpkg).

I used a second, helper VM to copy the contents of the LXC, into the / and /boot filesystems of the base VM, then booted the base VM.

THe VM's package database now contains packages from the LXC, but not from the base VM. Packages such as kernel and grub are not registered in the package database.

Edit /etc/apt/sources.list, so it only contains the base repositories (not security, updates, Etc):
deb http://us.archive.ubuntu.com/ubuntu/ lucid main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid main restricted

Install any missing packages which were installed in the base VM, by feeding the list of packages taken earlier, to apt-get:
apt-get install `cat packages.txt`

Put back the original /etc/apt/sources.list file.

You may want to run the VM in it's current state, to verify the migration didn't introduce any issues - then, update with apt-get update && apt-get upgrade

- Ivan]





More information about the ubuntu-users mailing list