Clone your ZFS root file system with one easy command

In their latest release Nexenta added support for ZFS boot. I also wrote an article about how to clone and boot another ZFS file system. The process is quite simple but it still contains a number of steps.

To make things even easier I decided to write a script to automate the process. This can be very useful just before you are going to install some new packages or do an upgrade. With this script you can simply do this


# ./clone_root.sh mynewroot

and the script will snapshot and clone the ZFS file system and then it will add an entry to the grub menu so that you can boot it easily in case something goes wrong. No more worries before you do a critical operation. Read on for more information.

One thing I noticed after playing around with ZFS boot that it is very easy to create new bootable file systems but it is very easy to get confused which file system you are on at the moment. This script will create a file in the root of the file system with the name of the file system. This way you can easily find out where you are without having to resort to the mount command.

Another thing that took quite a while to figure out was where the real menu.lst for grub is located. When you are using ZFS boot you can find it in the “root” file system of the pool (syspool in Nexenta) in the directory boot/grub. The menu.lst files you find in your normal root file systems are not used for anything.

The final thing I had problems with was that the syspool can’t have a mountpoint of none but rather legacy. This is because the script needs to mount the syspool so that it can edit the above mentioned menu.lst. It didn’t mount properly when I set the zfs mountpoint option and if someone could shed some light on this I would be very happy. At the moment I have the legacy workaround implemented.

The script takes the following steps to create the new clone

1. Snapshot the current root file system

2. Create a clone of the snapshot

3. Mount the new clone and edit /etc/vfstab so that it refers to the new clone file system

4. Mount the pool file system and add an entry to /boot/grub/menu.lst

All you have to do is to reboot the server and select the new entry.

ZFS boot is really going to change a few things in system administration circles because you can keep multiple copies of your root file system around for rainy days (or when something goes bad). You can decide to either boot an old copy of your root file system or simply rollback to a certain snapshot. I can’t wait until Sun gets this integrated into mainline Solaris.

You can find the script here. You are free to use it as you wish. If make any nice modifications please leave a comment here or send me an email.

[?]
Do you need system administration assistance? If you like what you are reading please consider subscribing to the RSS feed. If you have feedback or if you find the article useful please leave a comment below.

6 Responses to “Clone your ZFS root file system with one easy command”

  1. You can probably also use this to do offline upgrades with apt…

    you should be able to mount the clone, chroot and run an apt upgrade, and then when you are happy reboot into it.

  2. Justin, that is really an interesting idea. I will play aroud with it and maybe extend the current script or write a new one.

  3. Solaris supports snapshots of the filesystem already, in the current (old) UFS filesystem. ZFS’s innovation is in the integration with clustering, not snapshots.

    /Darao/

  4. 1. UFS is also well integrated with clustering

    2. Sure, UFS has a snapshot facility but ZFS is miles ahead. UFS snapshots are a cumbersome afterthought that I find difficult to work with. ZFS is just beautiful and well integrated.

  5. 7c68701572f1…

    7c68701572f17d9fbf65…

  6. your script does not work!
    I always get this error, when I tryto run it as root:

    bash: ./clone_root.sh: Permission denied

    that’s too bad…

Leave a Reply