PVE Adopt a Native LXD/LXC: Difference between revisions

From WikiMLT
Line 76: Line 76:
== References ==
== References ==
*ProxmoxVE Documentation: <code>[https://pve.proxmox.com/pve-docs/pct.1.html pct]</code>
*ProxmoxVE Documentation: <code>[https://pve.proxmox.com/pve-docs/pct.1.html pct]</code>
*ProxmoxVE Documentation: [[pve:Linux_Container|Linux Container]]  
*ProxmoxVE Wiki: [[pve:Linux_Container|Linux Container]]
*ProxmoxVE Wiki: [[pve:Unprivileged_LXC_containers|Unprivileged LXC containers]]  
*Proxmox Forum: [https://forum.proxmox.com/threads/custom-disksize-and-storage-with-pct-create.54928/ Custom disk size and storage with 'pct create']  
*Proxmox Forum: [https://forum.proxmox.com/threads/custom-disksize-and-storage-with-pct-create.54928/ Custom disk size and storage with 'pct create']  
*Linux Containers: [https://linuxcontainers.org/lxc/security/ LXC > Security > Privileged and Unprivileged containers]  
*Linux Containers: [https://linuxcontainers.org/lxc/security/ LXC > Security > Privileged and Unprivileged containers]  

Revision as of 22:20, 23 September 2022

Con­vert­ing an LXD/LXC to a ProxmoxVE/​​​LXC is pret­ty easy, be­cause the are (al­most) the same thing.

Ex­port the Con­tain­er

Go in­to the in­stance where the LXD is in­stalled and cre­ate a back­up of the LXC you want to clone. If the con­tain­er is in­stalled with­in LVM you need to mount the root filesys­tem some­where and cre­ate the archive from in­side the mount point. I will go­ing to play the oth­er sce­nario where the LXC is in­stalled with­in a di­rec­to­ry on Ubun­tu 22.04.

lxc config show --expanded webserver | grep 'privileged'
security.privileged: "false"
cd /var/snap/lxd/common/lxd/storage-pools/default/containers/webserver/rootfs
tar --exclude=dev --exclude=sys --exclude=proc --exclude=tmp/* \
-czvf /home/backups/lxc-webserver.tar.gz ./

Note in the com­mands above:

  • web­serv­er is the name of the con­tain­er.
  • lxc-webserver.tar.gz is the name of the archive file of that con­tain­er.

In this case the back­up is cre­at­ed while the con­tain­er is run­ning, oth­er­wise the –ex­clude op­tions may not be need­ed. In ad­di­tion I would say us­ing this ap­proach is much eas­i­er than us­ing a na­tive LXD/LXC back­up, where we need to ex­tract on­ly the rootfs/​​​ and archive it again.

Trans­fer the Con­tain­er to the PVE In­stance

Copy the back­up of an LXD/LXC to a ProxmoxVE's tem­plate di­rec­to­ry with­in its stor­age. In my case I'm us­ing a com­mand as the shown be­low.

rsync --progress \
remote.host:/home/backups/lxc-webserver.tar.gz \
/mnt/pve/ssd-1TB/template/cache/

Note in the com­mands above:

  • ssd-1TB is one of my PVE's stor­age de­vices A where Con­tain­er tem­plates B are al­lowed as Con­tent type.

Cre­ate CT with­in Prox­moxVE

At this point we can use the back­up file lxc-webserver.tar.gz as con­tain­er tem­plate C. And we have two po­tions: 1) to use WEB GUI or 2) to use the CLI of PVE.

Cre­ate CT via WEB GUI of PVE

It is pret­ty easy to use the GUI but it can't be used for script­ing. The spe­cif­ic steps are shown at Screen 1.

Screen 1. Create Linux container (CT) within ProxmoxVE 7.2.
Screen 1. Cre­ate Lin­ux con­tain­er (CT) with­in Prox­moxVE 7.2. Screen 1. Create Linux container (CT) within ProxmoxVE 7.2.

Cre­ate CT via CLI of PVE

Gere is how to cre­ate unpriv­i­leged con­tain­er by us­ing the com­mand pct.

pveam list ssd-1TB
NAME                                                         SIZE  
ssd-1TB:vztmpl/lxc-webserver.tar.gz                          2541.03MB
ssd-1TB:vztmpl/ubuntu-20.04-standard_20.04-1_amd64.tar.gz    204.28MB
pct create 177 ssd-1TB:vztmpl/lxc-webserver.tar.gz --password "SuperStrong:)" \
--description "LXC migrated" --hostname "webserver" --ostype "ubuntu" \
--cores 2 --memory 2048 --swap 512 --rootfs ssd-1TB:32 \
--features fuse=1,nesting=1 --unprivileged 1 \
--nameserver 172.16.17.151,8.8.8.8 \
--net0 name=eth0,hwaddr=64:6B:5C:36:48:E3,ip=172.16.17.177/24,gw=172.16.17.1,bridge=vmbr0

Notes:

  • In­stead of -storage ssd-1TB we need to use -rootfs ssd-1TB:32 in or­der to cre­ate large enough vm-disk (32G in this case), oth­er­wise with the de­fault size in most cas­es you will end up with in­suf­fi­cient disk space space.
  • In­stead of ssd-1TB­:vztmpl­/­lxc­-­webserver­.­tar­.­gz, we can use /mnt­/­pve­/­ssd­-­1TB­/­tem­pla­te­/­cache­/­lxc­-webserver.tar.gz or even just lxc­-­webserver­.­tar­.­gz.
  • Al­so the op­tions could be pro­vid­ed by dou­ble -- or by sin­gle - dash.

Ref­er­ences