How to migrate a regular LXC container to a Proxmox LXC container?

11,027

Solution 1

Without detailed explanation here is how you can do this.

  1. Create an archive of your LXC container.
  2. Create a Proxmox Container using that archive as a template.

First cd into your lxc container root directory:

cd /var/lib/lxc/debian8/rootfs/

(If you used an lvm volume as your containers storage, you need to mount it and cd into your mount point, which can be done by mount /dev/mapper/<lvgroup-lvdisk> /var/lib/lxc/debian8/rootfs/, and than cd into the mount point)

Create an archive:

tar -czvf /var/lib/vz/template/cache/my_debian8_template.tar.gz ./

Then create a new proxmox container out of that

pct create 100 /var/lib/vz/template/cache/my_debian8_template.tar.gz \
    -description LXC -hostname pvecontainer01 -memory 1024 -nameserver 8.8.8.8 \
    -net0 name=eth0,hwaddr=52:4A:5E:26:58:D8,ip=192.168.15.147/24,gw=192.168.15.1,bridge=vmbr0 \
    -storage local -password changeme

(You can modify your options as you would like.)

For more information see - man pct

Solution 2

still valid question and answer, but since time passed it need an update. Proxmox v6 allows you to create unprivileged container (by default), and since is, uhm, unprivileged (more about unprivileged CT on their wiki), you're unable to create devices or sockets (it is possible by manually editing config, but not a subject of this post)

That is why you may possibly need to exclude special dirs like sys, proc, net or dev from container backup.

So the command would rather be this:

tar --exclude=dev --exclude=sys --exclude=proc -czvf /var/lib/vz/template/cache/my_debian8_template.tar.gz ./

or you will get many kinds of "permission denied" restoring container.

Share:
11,027

Related videos on Youtube

ChrisW
Author by

ChrisW

Updated on September 18, 2022

Comments

  • ChrisW
    ChrisW almost 2 years

    How do you migrate a regular LXC container (from another or the same server) to a Proxmox LXC container, which can be accessed via the Proxmox web GUI?

    For example, I have a container created by running:

    lxc-create -n debian8 -t debian -- -r jessie

    This container will not automatically be picked up by Proxmox. I can see related data stored in /var/lib/lxc, and such a container has a regular root filesystem, unlike the raw disks created by Proxmox LXC containers, which are mounted on a ZFS rpool. (I'm using ZFS for storage, as configured by the Proxmox ISO installer.)

    Another difference is, that Proxmox uses its own configuration files for LXC.

    What is the best procedure to import/convert and register such a container with Proxmox?