Hello Everyone,
is there a way to migrate a lxc container to a KVM?
I would appreciate your help and tips
Greetings,
Alex
is there a way to migrate a lxc container to a KVM?
I would appreciate your help and tips
Greetings,
Alex
hi,
you can basically
1. create an archive of / from the container rootfs
2. create a kvm guest with the same linux distribution
3. extract archive to the kvm disk
4. install necessary packages and restire necessary configs (like network or similar)
be aware this still isn't any official guide or anything like that, just a possible method to achieve what you want.
you get the directory of the containers sysrootpct mount { LXC-ID }
modprobe nbd max_part=3
qemu-nbd -c /dev/nbd0 { KVM-Disk } // i.e.: vm-114-disk-1.qcow2
**** be careful: don't use /mnt - it's used by the host *** better use /mediamount /dev/nbd0p2 { mount-point }
rsync -a * { mount-point }
umount { mount point }
qemu-nbd -d /dev/nbd0
* unmount container-disk byrmmod nbd
* now start the KVM again with a Live-ISO - should be equal to the LXC-OSpct unmount { LXC-ID }
mount /dev/sda2 /mnt
mount /dev/sda1 /mnt/boot
* install bootloader grub2mount -o bind /sys /mnt/sys
mount -o bind /dev /mnt/dev
mount -t proc /proc /mnt/proc
chroot /mnt
* install a kernelyum install grub2
* configure grub2-bootloaderyum install kernel
* change the owner-id's of /bingrub2-install
grub2-mkconfig -o /boot/grub2/grub.cfg
cd /bin
chown root:root *
* reboot in the KVMexit
(I know that I am responding to an old post made back in 2019). *grins* It is nice to see that somebody else has a particular combination of `rsync` flags, just like me! For the sake of conversation, mine are `-avXP` unless the filesystem does not support extended attributes, in which case is just `rsync -avP`.In case you want to use the rsync method, the rsync options which have served me well over the years are:
# rsync -XxAaPSH src/ dest/
I know some options are "optional", I just use that string for an easy mnemonic.