PVE Adopt a Native LXD/LXC: Difference between revisions
Line 72: | Line 72: | ||
* Instead of <code class="noTypo">-storage ssd-1TB</code> we need to use <code class="noTypo">-rootfs ssd-1TB:32</code> 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 <code class="noTypo">-storage ssd-1TB</code> we need to use <code class="noTypo">-rootfs ssd-1TB:32</code> 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 <code class="noTypo">ssd-1TB­:vztmpl­/­lxc­-­webserver­.­tar­.­gz</code>, we can use <code class="noTypo">/mnt­/­pve­/­ssd­-­1TB­/­tem­pla­te­/­cache­/­lxc­-webserver.tar.gz</code> or even just <code class="noTypo">lxc­-­webserver­.­tar­.­gz</code>. | * Instead of <code class="noTypo">ssd-1TB­:vztmpl­/­lxc­-­webserver­.­tar­.­gz</code>, we can use <code class="noTypo">/mnt­/­pve­/­ssd­-­1TB­/­tem­pla­te­/­cache­/­lxc­-webserver.tar.gz</code> or even just <code class="noTypo">lxc­-­webserver­.­tar­.­gz</code>. | ||
* Also the options could be provided by double <code class="noTypo">--</code> or single <code class="noTypo">-</code> dash. | * Also the options could be provided by double <code class="noTypo">--</code> or by single <code class="noTypo">-</code> dash. | ||
== References == | == References == |
Revision as of 21:04, 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
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
- Linux Containers: LXC > Security > Privileged and Unprivileged containers
- Linux Containers Discuss: Check privileged or unprivileged
- Mi blog lah!: How to view the files of your LXD container from the host
- Server Fault: How to migrate a regular LXC container to a Proxmox LXC container?