Understanding ZFS Clone – Tutorial

Oracle Solaris 0 Comments

We saw in my previous article that zfs snapshot is a read-only copy of a dataset which can be used as a backup mechanism to rollback the system to it’s previous state, this can be useful before application upgrade or patching.
The other feature that is related to zfs snapshot is the zfs clone, which in counterpart is a write copy of a file system.
A zfs clone is related to its snapshot, without it it can not exist and the clone can’t be deleted without first deleting its source snapshot.

Let’s simplify things with some examples.

Creating a zfs clone

root@sol01:/datapool/project1# zfs list datapool
NAME                              USED  AVAIL  REFER  MOUNTPOINT
datapool                         5.59M   149M    32K  /datapool
datapool/project1                5.42M   149M  5.42M  /datapool/project1
root@sol01:/datapool/project1# zfs snapshot datapool/project1@original
root@sol01:/datapool/project1# zfs clone datapool/project1@original datapool/devops
root@sol01:/datapool/project1# zfs list datapool
NAME                              USED  AVAIL  REFER  MOUNTPOINT
datapool                         5.63M   149M    33K  /datapool
datapool/devops                    19K   149M  5.42M  /datapool/devops
datapool/project1                5.42M   149M  5.42M  /datapool/project1
datapool/project1@original           0      -  5.42M  -

Here we created our clone and as you can see the clone in devops have the same contents as /datapool/project1.

root@sol01:/datapool/project1# ls -lh /datapool/project1/
total 11041
-r--r--r--   1 root     root        1.7M Jan 12 11:17 lastlog
-rw------T   1 root     root        1.0M Jan 12 10:24 meeting
-rw-r--r--   1 root     root        545K Jan 12 11:17 messages
-rw------T   1 root     root        2.0M Jan 12 14:18 project6
-rw-r--r--   1 root     root        5.8K Jan 12 13:20 projet1.gz
root@sol01:/datapool/project1# ls -lh /datapool/project1/devops/
total 11041
-r--r--r--   1 root     root        1.7M Jan 12 11:17 lastlog
-rw------T   1 root     root        1.0M Jan 12 10:24 meeting
-rw-r--r--   1 root     root        545K Jan 12 11:17 messages
-rw------T   1 root     root        2.0M Jan 12 14:18 project6
-rw-r--r--   1 root     root        5.8K Jan 12 13:20 projet1.gz

You should also note that creating the clone can only be done on the same zfs pool, if you try to create it on another zpool you will get an error like this one.

root@sol01:/datapool/project1# zfs snapshot datapool/project1@original
root@sol01:/datapool/project1# zfs clone datapool/project1@original devops/project1
cannot create 'devops/project1': source and target pools differ

How can we identify that a file system is a clone ?
Using the zfs list we can’t see any difference, we should use zfs get origin which can show the original snapshot from where the clone was created.

root@sol01:~# zfs get origin datapool/devops
NAME             PROPERTY  VALUE                       SOURCE
datapool/devops  origin    datapool/project1@original  -

Destroying a ZFS clone

A zfs clone is a zfs file system (dataset) so it can be destroyed like any other file system using zfs destory.
As you should know, zfs clone is dependent on their origin snapshot, if your try to delete the snapshot first you will get an error like this:

root@sol01:~# zfs destroy datapool/project1@original
cannot destroy 'datapool/project1@original': snapshot has dependent clones
use '-R' to destroy the following datasets:
datapool/devops

Promoting a ZFS Clone

Suppose that we have cloned a dataset and we worked on it and we no longer need the original for some reason like space optimization or that we have done some work on the clone and we want to only keep a single copy of the file system.
We can do this using the zfs promote, in the last example we created a clone named datapool/devops from our snapshot datapool/project1@original, you can’t delete the original without deleting the clone, this is where promotion come into play.

root@sol01:~# zfs promote datapool/devops
root@sol01:~# zfs rename datapool/project1 datapool/project1_old
root@sol01:~# zfs rename datapool/devops  datapool/project1
root@sol01:~# zfs destroy datapool/project1_old

The beauty of zfs is that it take care of all the other aspects of mounting/unmounting and updating the /etc/vfstab (Solaris).

Find this useful! spread the word, share your knowledge.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

Leave a Reply

Your email address will not be published. Required fields are marked *