diff --git a/README.md b/README.md index b290eb3..df57219 100644 --- a/README.md +++ b/README.md @@ -349,6 +349,55 @@ zpool/data/opt /opt off zpool/data/opt/git /opt/git on ``` +## Nested environment-independent datasets + +### Caution + +If you want a dedicated dataset for a directory that lives deeper in your file system tree than just `/opt/git`, for example like `/var/lib/docker` make sure to not recursively create this structure in a single `zfs create` command. + +In [Adding another boot environment-independent dataset](#adding-another-boot-environment-independent-dataset) above you can safely do: +``` +zfs create -o canmount=off zpool/data/opt +``` +Here `zpool/data` already exists, you're only creating one child dataset `opt` and you're setting `-o canmount=off` so that it never mounts into your `/opt` directory. + +Now consider the same setup for `/var/lib/docker`. If you follow the exact same approach: +``` +zfs create -o canmount=off zpool/data/var/lib +``` +Docker will correctly report: +``` +cannot create 'zpool/data/var/lib': parent does not exist +``` +You might want to just create the parent then with `-p` argument: +``` +zfs create -p -o canmount=off zpool/data/var/lib + ~~ +``` +Note, however, that `-o canmount=off` only applies to `lib` dataset and that `zpool/data/var` has just been auto-mounted into `/var`: +``` +# zfs list -r -oname,mountpoint,canmount,mounted zpool/data +NAME MOUNTPOINT CANMOUNT MOUNTED +zpool/data / off no +zpool/data/home /home on yes +zpool/data/opt /opt off no +zpool/data/opt/git /opt/git on yes +zpool/data/var /var on yes <--- +zpool/data/var/lib /var/lib off no +``` + +### Advice + +Instead create nested parents in multiple steps where you set each one to `-o canmount=off`: +``` +zfs create -o canmount=off zpool/data/var +zfs create -o canmount=off zpool/data/var/lib +``` +Lastly create the dataset you want mounted: +``` +zfs create zpool/data/var/lib/docker +``` + # Development ## Conventional commits