February 11

Linux container to VM

* First create a new KVM with a Harddisk. I used a QEMU-Disk
* Start the VM with a Linux-Live-ISO
* Create the following partitions:
– Linux boot (ext2/3)
– Linux Data (i.e. ext4)
– swap

*set the boot-flag on the boot-partition
* shut down the KVM
* connect to host-console – I preferred to login by ssh
* mount LXC-Disk by enter

pct mount { LXC-ID }

you get the directory of the containers sysroot

* mount the new KVM-harddisk by using the following command:

modprobe nbd max_part=3

qemu-nbd -c /dev/nbd0 { KVM-Disk } // i.e.: vm-114-disk-1.qcow2

mount /dev/nbd0p2 { mount-point }

**** be careful: don’t use /mnt – it’s used by the host *** better use /media

* change to the sysroot-directory you got before
* copy the whole directory-structure to the mounted disk by using rync

rsync -a * { mount-point }

* unmount KVM-disk by enter

umount { mount point }

qemu-nbd -d /dev/nbd0

rmmod nbd

* unmount container-disk by

pct unmount { LXC-ID }

* now start the KVM again with a Live-ISO – should be equal to the LXC-OS
* mount the KVM-Disk i.e. /mnt

mount /dev/sda2 /mnt
mount /dev/sda1 /mnt/boot

* change sysroot by enter

mount -o bind /sys /mnt/sys
mount -o bind /dev /mnt/dev
mount -t proc /proc /mnt/proc

chroot /mnt

* install bootloader grub2

yum install grub2

* install a kernel

yum install kernel

* configure grub2-bootloader

grub2-install --force /dev/sdX1
grub2-mkconfig -o /boot/grub2/grub.cfg

* change the owner-id’s of /bin

cd /bin
chown root:root *

* exit chroot by

exit

* reboot in the KVM

Original post is stored here