MEW-DOS v1.1

Converting LXC Containers to full VMs written by neko


Yet another article that’s been sitting on my internal wiki for a while. A bunch of months ago I had to move some LXC containers from my company’s Proxmox machine to full VMs for migration purposes.

The way I went about this was to move the contents of the file system of the container to a new drive or drive image and installing the needed packages for the system kernel as well as bootloader in a chroot environment.

Theoretically, this can also be used to turn an LXC container into a physical machine.

If you find anything amiss with this documentation, contact me!


First, make an export of your container. Make sure it contains the full root file system of the container. On Proxmox, a vzdump-backup was enough.

My container contained a Debian file system, so all the configuration I created further is for Debian. Of course you need to adjust the configuration files to your needs. Consult the documentation for your distribution about what configuration is needed and where it belongs. Most systems should be fine with the provided instructions, though.1

Since my goal was to end up with a VM, the next steps as specific to VMs. If you have a physical hard drive, just mount the drive. If you want a drive image, just create a sparse file with dd and fallocate and mount it to a loop device.

First, I created a new virtual machine with a virtual hard drive attached. Make sure the hard drive has the desired size. Then I booted my live system of choice up to configure the rest: GRML. If you decided to use a real hard drive or a drive image file, you can use the system you’re already running.

It is now time to prepare the disk. Create a new partition table on the drive with one partition spanning the whole drive.2 Then initialise the partition with the file system of your choice. I’d recommend ext43 but your mileage may vary. Just make sure it is bootable by grub.

$ fdisk /dev/sda
$ mkfs.ext4 /dev/sda1

Mount the new file system to a folder and copy the content of the container file system onto the partition:

$ mount /dev/sda1 /mnt/
$ mv vzdump-lxc-103-2021_09_07-15_32_34.tar /mnt
$ cd /mnt
$ tar xfv vzdump-lxc-103-2021_09_07-15_32_34.tar

Next, prepare a chroot environment and start it up:4

$ mount -t proc /proc proc/
$ mount -t sysfs /sys sys/
$ mount --rbind /dev dev/
$ cp /etc/resolv.conf /mnt/etc/
$ chroot /mnt /bin/bash
$ source /etc/profile
$ source ~/.bashrc

Now create the fstab file to mount your root file system on boot:

$ blkid
$ vim /etc/fstab
UUID="f79df0cb-4b4f-4a55-86a8-cd5dd6fefdc4" / ext4 defaults 0 0

The next step is to install the kernel and the bootloader. Since my container is a Debian system, apt will be used. For other distributions check their respective documentation.

$ apt update
$ apt upgrade #not needed but recommended
$ apt install linux-image-amd64 grub2
$ grub-install /dev/sda

Finally, shut down the system, remove the live system medium and boot up.

  1. I have not tested this with anything but Debian. 

  2. It is not strictly required to only have a single large partition. Choose the layout to your liking, but make sure your root partition is large enough. Also, don’t forget to add the fstab entries later. 

  3. Make sure your version of grub is above 1.9, otherwise ext4 may not be supported. 

  4. If you want network, of course, make sure your running system has network configured.