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:

  1. make sure that the container is stopped

  2. mount the zfs volume that match the stopped container

  3. execute the operations we want to execute in the container

  4. 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:

  1. cd /var/lib/lxd/storage-pools/vd_lxd_container/containers/test-restore-bck1/rootfs

  2. execute all the needed operations (eg: configure a static ip for the container)

Unmount the volume:

  1. 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)

  2. 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

  1. execute zfs list —> show existing zfs volumes (usually match existing containers)

  2. 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)

  3. execute zfs get origin vd_lxd_container/containers/test-restore-bck1