how to convert an KVM image to a LXC container image

  • install lxd-p2c tool
sudo apt install golang-go -y
go get -v -x
cd ~/go/src/
make lxd-p2c
~/go/bin/lxd-p2c --help

  • convert VM image(raw or qcow2) to a lxd container instance
sudo apt install qemu-utils
sudo modprobe nbd
ls -al /dev/nbd*
sudo qemu-nbd -c /dev/nbd0  $kvm_image_path
sudo fdisk -l /dev/nbd0
sudo mkdir /mnt/a
sudo mount /dev/nbd0p1 /mnt/a
lxc storage list
sudo lxd-p2c https://$lxdserver-ip[:8443] mytest /mnt/a [-s $lxd-storage-pool]
sudo umount /mnt/a
sudo qemu-nbd -d /dev/nbd0
# you can convert a VM to a container inside the running VM
# login to the running source system (physical or VM)
# install lxd-p2c as described above, and execute below commands
sudo systemctl disable rsyslog
sudo systemctl stop rsyslog
sudo systemctl mask systemd-journald
sudo systemctl stop systemd-journald
sudo lxd-p2c https://$lxdserver-ip:8443 test / [--rsync-args="--exclude=/var/cache"]

lxd-p2c samples

lxd-p2c tool is recommended one to convert physical/VM to lxd container. if you have ISO, create a VM with the ISO, and then use the lxd-p2c tool to convert the VM to an LXD container.

– LXD achieves 14.5 times greater density than KVM
– LXD launches instances 94% faster than KVM
– LXD provides 57% less latency than KVM

how to convert LXD image to Docker image

for LXD container

for LXC container

Leave a Reply

Your email address will not be published. Required fields are marked *