How to convert bare metal FS to LXC Container?

Jan 12, 2015
94
2
28
I'm just trying out containers in Proxmox 4.4. I have a 1U bare metal I'd like to convert to a container. I've done this with KVM by booting the VM with a cdrom and then using rsync to copy files over from a hard disk/usb stick onto the VM filesystem. I don't see a cdrom boot option for LXC containers.

What's the process for migrating a bare metal host to a container?
Thanks
 
Thanks. Is there a way to boot the container from ISO ? I like to boot the target with an acquiesced filesystem before doing a sync. Usually there is an option under Hardware > Add > CDROM for this but that doesn't exist for a container.
 
Thanks. Is there a way to boot the container from ISO ? I like to boot the target with an acquiesced filesystem before doing a sync. Usually there is an option under Hardware > Add > CDROM for this but that doesn't exist for a container.

Of course not, you do not need that step and it is technically impossible. You are already on the target so to speak. Containers use the kernel of your PVE host, so you just need to rsync the files (pct mount if you're not using ZFS).
 
yes, thanks


UPDATE: just tried it on a second host today and it worked perfectly.
I mounted the bare metal root fs on /mnt/ssd and then mounted the container rootfs via pct. Commands below if anyone is wondering how to do it.

pct mount 700
cd /var/lib/lxc/700/rootfs/
rsync -av /mnt/ssd/ . --exclude=proc --exclude=sys --exclude=etc --exclude=dev --exclude=etc/fstab --exclude=default/grub --delete

(to chroot into rootfs)
mount -o bind /proc proc
mount -o bind /dev dev
mount -o bind /dev/pts dev/pts/
mount -o bind /sys sys
chroot /var/lib/lxc/700/rootfs /bin/bash
 
Last edited:
  • Like
Reactions: stappers

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!