Go to main content

Managing ZFS File Systems in Oracle® Solaris 11.3

Exit Print View

Updated: May 2019

Overview of ZFS Clones

A clone is a writable volume or file system whose initial contents are the same as the dataset from which it was created. As with snapshots, creating a clone is nearly instantaneous and initially consumes no additional disk space. In addition, you can snapshot a clone.

Clones can be created only from a snapshot. When a snapshot is cloned, an implicit dependency is created between the clone and snapshot. Even though the clone is created somewhere else in the file system hierarchy, the original snapshot cannot be destroyed as long as the clone exists. The origin property exposes this dependency, and the zfs destroy command lists any such dependencies, if they exist.

Clones do not inherit the properties of the dataset from which they were created. Use the zfs get and zfs set commands to view and change the properties of a cloned dataset. For more information, see Setting ZFS Properties.

Because a clone initially shares all its disk space with the original snapshot, its used property value is initially zero. As changes are made to the clone, it uses more disk space. The used property of the original snapshot does not include the disk space consumed by the clone.

Creating a ZFS Clone

To create a clone, use the zfs clone command, specifying the snapshot from which to create the clone and the name of the new file system or volume, which can be located anywhere in the ZFS hierarchy. The new dataset is the same type (for example, file system or volume) as the snapshot from which the clone was created. You cannot create a clone of a file system in a pool that is different from where the original file system snapshot resides.

The following example creates a new clone named system1/home/matt/bug123 with the same initial contents as the snapshot system1/ws/gate@yesterday.

# zfs snapshot system1/ws/gate@yesterday
# zfs clone system1/ws/gate@yesterday system1/home/matt/bug123

The following example creates a cloned workspace from the projects/newproject@today snapshot for a temporary user as projects/teamA/tempuser. Properties then are set on the cloned workspace.

# zfs snapshot projects/newproject@today
# zfs clone projects/newproject@today projects/teamA/tempuser
# zfs set share.nfs=on projects/teamA/tempuser
# zfs set quota=5G projects/teamA/tempuser

Destroying a ZFS Clone

You destroy ZFS clones by using the zfs destroy command. For example:

# zfs destroy system1/home/matt/bug123

You must destroy clones before the parent snapshot can be destroyed.

Replacing a ZFS File System With a ZFS Clone

To replace an active ZFS file system with a clone of that file system, use the zfs promote command. This feature enables you to clone and replace file systems so that the original file system becomes the clone of the specified file system. In addition, you can destroy the file system from which the clone was originally created. Without clone promotion, you cannot destroy an original file system of active clones. For more information, see Destroying a ZFS Clone.

In the following example, the system1/test/productA file system is cloned and then the clone file system, system1/test/productAbeta, becomes the original system1/test/productA file system.

# zfs create system1/test
# zfs create system1/test/productA
# zfs snapshot system1/test/productA@today
# zfs clone system1/test/productA@today system1/test/productAbeta
# zfs list -r system1/test
NAME                          USED  AVAIL  REFER  MOUNTPOINT
system1/test                  104M  66.2G    23K  /system1/test
system1/test/productA         104M  66.2G   104M  /system1/test/productA
system1/test/productA@today      0      -   104M  -
system1/test/productAbeta        0  66.2G   104M  /system1/test/productAbeta
# zfs promote system1/test/productAbeta
# zfs list -r system1/test
NAME                              USED  AVAIL  REFER  MOUNTPOINT
system1/test                      104M  66.2G    24K  /system1/test
system1/test/productA                0  66.2G   104M  /system1/test/productA
system1/test/productAbeta         104M  66.2G   104M  /system1/test/productAbeta
system1/test/productAbeta@today      0      -   104M  -

In this zfs list output, note that the disk space accounting information for the original productA file system has been replaced with the productAbeta file system.

You can complete the clone replacement process by renaming the file systems. For example:

# zfs rename system1/test/productA system1/test/productAlegacy
# zfs rename system1/test/productAbeta system1/test/productA
# zfs list -r system1/test

Optionally, you can remove the legacy file system. For example:

# zfs destroy system1/test/productAlegacy