Displaying and Accessing ZFS Clones

By setting a clone's mountpoint property to clonedir, you can access the clone in the mountpoint /.zfs/clone directory that is located in the dataset of which this is a clone. This dataset is called the head dataset.

When you set a clone's mountpoint property to clonedir, ZFS uses the final part of its dataset name as the clone subdirectory to add to .zfs/clone. Thus, ensure that each clone for which you intend to use clonedir has a unique name after the final slash for a given head dataset.

In this example, the head dataset is tank/ds/subds. Create a clone of the tank/ds/subds@march snapshot called tank/march and mount it on /tank/ds/subds. When you set its mountpoint property to clonedir, you can access the clone from the /tank/ds/subds/.zfs/clone/march directory.

To determine whether a file system is a clone, use the zfs command to verify that the value of the origin property is non-NULL.

To share a clone that has mountpoint=clonedir set, ensure that it is shared from the top-level directory that houses the .zfs/clone directory. For example, a file system mounted on /a only permits access to its clonedir clones if /a is shared and not a subdirectory of /a, so the clonedir clones are available in /a/.zfs/clone.

When you set a clone's mountpoint property to clonedir, ZFS does the following:

  • Disables any existing shares of that clone.

  • Adds the clone directory to its head dataset's .zfs/clone directory, such as tank/ds/subds/.zfs/clone/march.

You can mount clones in .zfs/clone in the following ways:

  • The tank/ds/subds/march clone is mounted at the tank/ds/subds mount point, which is tank/ds/subds/.zfs/clone/march.

    Create a clone that sets its mountpoint property to clonedir.

    # zfs clone -o mountpoint=clonedir snapshot-name
              clone-name
            

    The following command creates a clone of the tank/ds/subds@snap snapshot called tank/ds/subds/march:

    # zfs clone -o mountpoint=clonedir tank/ds/subds@march tank/ds/subds/march
            

    Assuming that the mount point of tank/ds/subds is /tank/ds/subds, the tank/ds/subds/march clone is mounted on demand at /tank/ds/subds/.zfs/clone/march.

  • Set an existing clone's mountpoint property to clonedir.

    # zfs set -o mountpoint=clonedir clone-name
            

    The following command sets the mountpoint property to clonedir for the existing tank/ds/subds/march clone:

    # zfs set -o mountpoint=clonedir tank/ds/subds/march
            
  • Use the mkdir command to create a directory for the clone in .zfs/clone directory.

    Note that you can use the mkdir and rmdir commands to create and destroy snapshots and clones, respectively.

    The mkdir command creates a snapshot of the head dataset and then clones it.

    # mkdir .zfs/clone/clone-name
            

    For example, with tank/ds/subds as the head dataset, the following command does the following:

    • Creates a snapshot called tank/ds/subds@march if it does not exist
    • Clones the snapshot as a dataset called tank/ds/subds/march

    The resulting mount path is /tank/ds/subds/.zfs/clone/march when the mount point of tank/ds/subds is the default /tank/ds/subds. Note that you can specify any mount point for the mount path.

    # mkdir .zfs/clone/march
            

    As with the zfs destroy command, the rmdir command does not destroy the origin snapshot.