ZFS utilities for linux containers¶
How to execute operations in a linux container without starting it¶
In some cases we want to change linux container configurations and execute operations in the container without starting it (eg: configure a static ip for the container and avoid duplicate IPs).
To do so, we must:
make sure that the container is stopped
mount the zfs volume that match the stopped container
execute the operations we want to execute in the container
unmount the zfs volume
NOTE: if a container is stopped, the zfs volume that match the container is not mounted
First, we take note of the container of our interest:
lxc list
For example, we choose test-restore-bck1 and make sure that is stopped.
Show all the existing zfs volumes:
zfs list
Show the zfs volume that match our container and take note of the name:
zfs list | grep test-restore-bck1
Show all the already mounted zfs volumes (the volumes that will be shown are all the volumes that match an existing and running container)
df
If we issue the following command:
df | grep test-restore-bck1
we notice that the volume that match our container is not shown (the container is stopped, so the volume that match the container is not mounted)
In order to execute operations on our stopped container, we need to mount the matching zfs volume (use the name obtained in the previous command)
zfs mount vd_lxd_container/containers/test-restore-bck1
If we issue again the df command, we now notice that the volume is shown as mounted:
df | grep test-restore-bck1
With the previous command, we also know the mountpoint of the zfs volume: /var/lib/lxd/storage-pools/vd_lxd_container/containers/test-restore-bck1
Now we can configure the container:
cd /var/lib/lxd/storage-pools/vd_lxd_container/containers/test-restore-bck1/rootfs
execute all the needed operations (eg: configure a static ip for the container)
Unmount the volume:
Make sure that your working directory is not one of the subdirectories of /var/lib/lxd/storage-pools/vd_lxd_container/containers/test-restore-bck1 (test-restore-bck1 included)
zfs unmount vd_lxd_container/containers/test-restore-bck1 (or zfs unmount /var/lib/lxd/storage-pools/vd_lxd_container/containers/test-restore-bck1)
How to check the origin of a linux container¶
execute
zfs list
—> show existing zfs volumes (usually match existing containers)take note of the zfs volume name that match the container of which you want to know the origin (eg: vd_lxd_container/containers/test-restore-bck1)
execute
zfs get origin vd_lxd_container/containers/test-restore-bck1