PVE Adopt a Native LXD/LXC: Difference between revisions
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 | *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 21:20, 23 September 2022
Converting an LXD/LXC to a ProxmoxVE/LXC is pretty easy, because the are (almost) the same thing.
Export the Container
Go into the instance where the LXD is installed and create a backup of the LXC you want to clone. If the container is installed within LVM you need to mount the root filesystem somewhere and create the archive from inside the mount point. I will going to play the other scenario where the LXC is installed within a directory on Ubuntu 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 commands above:
webserver
is the name of the container.lxc-webserver.tar.gz
is the name of the archive file of that container.
In this case the backup is created while the container is running, otherwise the –exclude
options may not be needed. In addition I would say using this approach is much easier than using a native LXD/LXC backup, where we need to extract only the rootfs/
and archive it again.
Transfer the Container to the PVE Instance
Copy the backup of an LXD/LXC to a ProxmoxVE's template directory within its storage. In my case I'm using a command as the shown below.
rsync --progress \
remote.host:/home/backups/lxc-webserver.tar.gz \
/mnt/pve/ssd-1TB/template/cache/
Note in the commands above:
ssd-1TB
is one of my PVE's storage devices A where Container templates B are allowed as Content type.
Create CT within ProxmoxVE
At this point we can use the backup file lxc-webserver.tar.gz
as container template C. And we have two potions: 1) to use WEB GUI or 2) to use the CLI of PVE.
Create CT via WEB GUI of PVE
It is pretty easy to use the GUI but it can't be used for scripting. The specific steps are shown at Screen 1.
Create CT via CLI of PVE
Gere is how to create unprivileged container by using the command 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:
- Instead of
-storage ssd-1TB
we need to use-rootfs ssd-1TB:32
in order to create large enough vm-disk (32G in this case), otherwise with the default size in most cases you will end up with insufficient disk space space. - Instead of
ssd-1TB:vztmpl/lxc-webserver.tar.gz
, we can use/mnt/pve/ssd-1TB/template/cache/lxc-webserver.tar.gz
or even justlxc-webserver.tar.gz
. - Also the options could be provided by double
--
or by single-
dash.
References
- ProxmoxVE Documentation:
pct
- ProxmoxVE Wiki: Linux Container
- ProxmoxVE Wiki: Unprivileged LXC containers
- Proxmox Forum: Custom disk size and storage with 'pct create'
- Linux Containers: LXC > Security > Privileged and Unprivileged containers
- Linux Containers Discuss: Check privileged or unprivileged
- Linux Containers Discuss: Run-parts: /etc/update-motd.d/98-fsck-at-reboot exited with return code 2 (post installation setup)
- Linux Containers Discuss: Simple script to convert any gnu/linux machine into a proxmox lxc container (more directories and files which can be excluded)
- Server Fault: How to migrate a regular LXC container to a Proxmox LXC container?
- Mi blog lah!: How to view the files of your LXD container from the host
- GitHub Gist: tinoji/proxmox_lxc_pct_provisioner.sh (more commands and ideas)
- TecAdmin: How to Configure Static IP Address on Ubuntu 22.04 [Method 2] (post installation setup)