Site Tools


sysadmin:legacy:lxc_to_kvm

Convert LXC Container to KVM VM

To Convert LXC to a Proxmox VM

This is the process:

  • Tar the entire filesystem from the container root directory, usually
    /var/lib/libvirt/images/rootfs/<container_root_dir>
  • SCP the newly created tar to a Proxmox Node in the directory
    /var/lib/vz/template/cache
  • Create a new Container in the Proxmox GUI and use the copied tar as the template.

To Convert LXC to a Libvirt/Virsh Container

The is the process:

  • Create a new qcow2 disk image. The easiest way is to mount an existing image, and remove the files
sudo modprobe nbd max_part=8
sudo qemu-nbd --connect=/dev/nbd0 file.qcow2
sudo mount /dev/nbd0p1 /mnt/kvm
* mount the image with qemu-nbd
* Copy the LXC Files to the KVM image via rsync: rsync -av --numeric-ids <source> <destination>
* mount --bind /dev, /proc, and /sys on the image and chroot to it
* Copy the /etc/fstab from an existing KVM machine to the new disk
* install the kernel and grub-pc to /dev/nbd0
* edit grub.cfg to point nbd0p2 to /dev/vda2
* Boot the new VM
sysadmin/legacy/lxc_to_kvm.txt · Last modified: 2024/03/27 14:00 by 127.0.0.1