ZFS `zfs clone` – `canmount` Not Preserved

I recently installed 13.2-RELEASE and, perhaps for the first time after the change of upstream source for ZFS changed, ran some long-standing scripts that cloned ZFS hierarchies. After scratching my head for a while, it appears that the canmount property is not being preserved.

Is this a "feature" that I haven't been able to find documentation around?

To replicate, install using bsdinstall on ZFS

Note that the usr filesystem is intentionally not mounted (it serves as an anchor for other file systems). That canmount=off is intentional can be confirmed by examining /usr/libexec/bsdinstall/zfsboot

Code:
        # Don't mount /usr so that 'base' files go to the BEROOT
        /usr            mountpoint=/usr,canmount=off

Cloning that filesystem results in it being mounted at the point in the hierarchy one would expect with the mountpoint being unspecified

Code:
[jeff@m75 ~]$ zfs get canmount,mounted zroot-m75-2023/usr
NAME                PROPERTY  VALUE     SOURCE
zroot-m75-2023/usr  canmount  off       local
zroot-m75-2023/usr  mounted   no        -

[jeff@m75 ~]$ sudo zfs clone zroot-m75-2023/usr@2023-04-24 zroot-m75-2023/cloned_usr
[jeff@m75 ~]$ zfs get canmount,mounted zroot-m75-2023/cloned_usr
NAME                       PROPERTY  VALUE     SOURCE
zroot-m75-2023/cloned_usr  canmount  on        default
zroot-m75-2023/cloned_usr  mounted   yes       -

[jeff@m75 ~]$ freebsd-version -ku
13.2-RELEASE
13.2-RELEASE
[jeff@m75 ~]$ zfs --version
zfs-2.1.9-FreeBSD_g92e0d9d18
zfs-kmod-2.1.9-FreeBSD_g92e0d9d18


The same occurs if the filesystem's mountpoint is simply inherited.

Code:
[jeff@m75 ~]$ sudo zfs get mountpoint,mounted,canmount zroot-m75-2023/_jail/_base/usr
NAME                            PROPERTY    VALUE                            SOURCE
zroot-m75-2023/_jail/_base/usr  mountpoint  /zroot-m75-2023/_jail/_base/usr  inherited from zroot-m75-2023
zroot-m75-2023/_jail/_base/usr  mounted     no                               -
zroot-m75-2023/_jail/_base/usr  canmount    off    local

[jeff@m75 ~]$ sudo zfs snapshot zroot-m75-2023/_jail/_base/usr@test

[jeff@m75 ~]$ sudo zfs clone zroot-m75-2023/_jail/_base/usr@test zroot-m75-2023/cloned_usr_test

[jeff@m75 ~]$ sudo zfs get mountpoint,mounted,canmount zroot-m75-2023/cloned_usr_test
NAME                            PROPERTY    VALUE                            SOURCE
zroot-m75-2023/cloned_usr_test  mountpoint  /zroot-m75-2023/cloned_usr_test  inherited from zroot-m75-2023
zroot-m75-2023/cloned_usr_test  mounted     yes                              -
zroot-m75-2023/cloned_usr_test  canmount    on                               default
 
ZFS documentation nowhere promises or implies that a clone would get the same properties as a dataset from whose snapshot the clone was created.
A clone gets default / inherited properties unless overridden with -o option.
A clone shares a snapshot (the origin) with initial dataset, so it shares (some) data, but it is a completely independent dataset in terms of properties, etc.
In that respect you should think of clone operation the same as of create operation.
 
Let's say you have a dataset x and mountpoint /x
After cloning x you normally don't want the cloned dataset to overmount the mountpoint /x.
 
A clone gets default / inherited properties unless overridden with -o option.
You can see explicitly see the properties that a snapshot (zfs get all path/to@snapshot) possesses, canmount is notably not among them.

The short answer, as Andriy has already pointed out, is to use '-o prop=value' to set any values you need applied to the new clone during creation.
 
  • Thanks
Reactions: jef
Back
Top