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 github.com/lxc/lxd/lxd-p2c
cd ~/go/src/github.com/lxc/lxd
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
https://discuss.linuxcontainers.org/t/howto-use-lxd-p2c/3574


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 vs KVM
– LXD achieves 14.5 times greater density than KVM
– LXD launches instances 94% faster than KVM
– LXD provides 57% less latency than KVM
https://blog.ubuntu.com/2015/05/18/lxd-crushes-kvm-in-density-and-speed


how to convert LXD image to Docker image
https://www.reddit.com/r/docker/comments/3ctm16/how_do_you_convert_an_lxc_container_to_a_docker/


reference
for LXD container
https://discuss.linuxcontainers.org/t/made-a-script-to-convert-a-kvm-vm-to-an-lxd-rootfs/981/2
https://www.reddit.com/r/LXD/comments/8b4q9a/how_to_build_the_lxdp2c_toolapplication_to/
https://blog.ubuntu.com/2018/04/13/on-the-road-to-lean-infrastructure

for LXC container
https://snikt.net/blog/2014/03/22/convert-kvm-image-to-lxc-container/
http://wiki.deimos.fr/LXC_:_Install_and_configure_the_Linux_Containers#Convert.2FMigrate_a_VM.2FHost_to_a_LXC_container
https://stgraber.org/2012/03/04/booting-an-ubuntu-12-04-virtual-machine-in-an-lxc-container/

Leave a Reply

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