In our previous article “ZFS: Snapshot Management” we learned about the many methods of using snapshots to give you a shorter path to recovery as well as reduce the time needed to revert changes that need to be reversed. Today we will discuss clones, which are essentially a copy-on-write duplicate of an existing snapshot, which unlike snapshots can be written to, can have snapshots taken against them, and can be promoted into a file system (which would then revert to the original file system as the clone).
Creating a clone is a two-part process. Clones cannot be directly created from a file system, they need to be created from a snapshot of a file system (which quiets the disk).
Configure Test Environment
# mkfile 2g /export/vdisk01.img /export/vdisk02.img /export/vdisk03.img /export/vdisk04.img
# zpool create tank raidz /export/vdisk01.img /export/vdisk02.img /export/vdisk03.img /export/vdisk04.img
# zfs create tank/test
Create a Snapshot of the File System to be Cloned
# zfs snapshot tank/test@now
Clone the Snapshot you Created
# zfs clone tank/test@now tank/testclone
View Details of the File Systems
# zfs list -r tank NAME USED AVAIL REFER MOUNTPOINT tank 21.1M 5.82G 46.4K /tank tank/test 21.0M 5.82G 21.0M /tank/test tank/testclone 1.50K 5.82G 21.0M /tank/testclone
Promote the Clone to a File System
# zfs promote tank/testclone
View Details of the File Systems
# zfs list -r tank NAME USED AVAIL REFER MOUNTPOINT tank 21.1M 5.82G 47.9K /tank tank/test 0 5.82G 21.0M /tank/test tank/testclone 21.0M 5.82G 21.0M /tank/testclone
Perform a Rename Operation of the Newly Promoted File System
# zfs rename tank/testclone tank/promoted
Now you will notice that the snapshot which was used to create the clone has been converted to be a child of the clone. This is a result of the promotion of the clone.
# zfs list -t snapshot -r tank NAME USED AVAIL REFER MOUNTPOINT tank/promoted@now 1.50K - 21.0M -
Destroy the Original File System
# zfs destroy tank/test