openzfs / zfs

OpenZFS on Linux and FreeBSD
https://openzfs.github.io/openzfs-docs
Other
10.65k stars 1.75k forks source link

add a recursive option to zfs mount #2901

Open krichter722 opened 10 years ago

krichter722 commented 10 years ago

I'd be great to have an option for zfs mount which doesn't mount specific dataset or all datasets, like zfs mount -a, but all datasets which are children of a dataset x, e.g. zfs mount -r x should mount the existing datasets x/1, x/2/alpha, but not a and a/3 (well, you know what recursive means :)). The -a option could be reused, i.e. the meaning of zfs mount -a <dataset> would become different from zfs mount -a without dataset specification, but I guess that adding an option, e.g. -r would be more elegant and easier to test and document.

The mountpoints should be checked recursively for conflicting mountpoint, which would be identical one and those which are deeper in the tree than than predecessors in a top down iteration of the tree. The command should simply fail when such a conflict is encountered.

QORTEC commented 3 years ago

This feature would be especially useful if we where to add an option that would mount all child datasets with the property of canmount=noauto.

zfs mount -a filesystem     Mounts the specified filesystem and its children. If no filesystem is specified, then all available ZFS file systems are mounted. Invoked automatically as part of the boot process if configured. -r filesystem     Mounts the specified filesystem and its children. Note filesystems with the canmount=noauto property will also be mounted.

One use-case for this feature would be multi-boot environments; currently there is no elegant way to setup a multi-boot environment with child datasets that are boot environment specific.

# zfs list -r -o name,canmount,mountpoint syspool/ROOT
NAME                         CANMOUNT  MOUNTPOINT
syspool/ROOT                      off  none
syspool/ROOT/bootenv1          noauto  /
syspool/ROOT/bootenv2          noauto  /
syspool/ROOT/bootenv3          noauto  /
syspool/ROOT/bootenv3/tmp      noauto  /tmp
syspool/ROOT/bootenv3/var         off  /var
syspool/ROOT/bootenv3/var/log  noauto  /var/log
# zfs mount -r syspool/ROOT/bootenv3
# df --output=source,target
Filesystem                                 Mounted on
syspool/ROOT/bootenv3                      /
syspool/ROOT/bootenv3/tmp                  /tmp
syspool/ROOT/bootenv3/var/log              /var/log
Jip-Hop commented 2 years ago

I'm currently instructing to use zfs mount -a to mount a backup pool and all descending datasets (see the Recovery paragraph). But this has the side effect of also mounting other filesystems (not just the backup pool and children). A dedicated zfs mount -a <dataset> option would be great in this case.