This weekend, while playing about with OpenSolaris, I was looking to boot my laptop with some different bits. I didn't want to overwrite my current OS image, but unfortunately I didn't have the disk partitions available to create a new LiveUpgrade boot environment (nor the time to wait for it!)

Thankfully, I'd been running ZFS Mountroot pretty much since it was announced, so I was able to use ZFS snapshots and clones of my root filesystem, with a little editing in various etc/vfstab files to get me what I wanted.

But that got me thinking, it'd be neat if someone automated this - and besides, it wouldn't be a very complex script... Now, I know that ZFS Boot is probably just around the corner, but until LiveUpgrade groks ZFS, here's something to use in the meantime: mountrootadm.sh

Here's me using it :

(an initial one-time only step to setup it's configuration file)
# df -h /
Filesystem             size   used  avail capacity  Mounted on
tank/root_filesystem   9.2G   5.2G   4.0G    57%    /
#
# echo tank/root_filesystem > /ufsroot/opt/etc/mountroot.cfg

(now, onto it's usage..)
# ./mountrootadm
Usage: mountrootadm [command] {arguments}

where command is one of:
         create {name}
                Creates a new mountroot dataset as a clone
                of the existing one.
         activate {name}
                Sets a mountroot dataset as the next
                dataset to be booted from.
         destroy {name}
                Destroys a mountroot dataset. This must not
                be the active dataset.
         list
                Lists the known mountroot datasets.
# ./mountrootadm list
root_filesystem (current)

# ./mountrootadm create newroot
Mountroot dataset tank/newroot has been created, 
and mounted on /tmp/mountroot_dataset.1325

# ./mountrootadm list
root_filesystem (current)
newroot

# ./mountrootadm activate newroot
Currently booted from mountroot dataset tank/root_filesystem
On next reboot, mountroot dataset tank/newroot will be activated.

# ./mountrootadm list
root_filesystem (current)
newroot (active on next reboot)

All the script does, is create a named snapshot of the current root dataset, clone that snapshot to a new dataset, and put appropriate entries into /etc/vfstab and the corresponding /ufsroot/etc/vfstab (and update boot_archives appropriately)

Let me know if you find this useful, or if you run into any problems using it. As soon as ZFS Boot comes out, I'll write something similar for that environment, in case LiveUpgrade hasn't yet seen the light that is ZFS!

Update: Actually, on further testing, this script still needs some work. I'd forgotten about the mountroot bootadm hack, which always copies the current boot_archive into /ufsroot (overwriting the hard work we've done putting an alternate boot environment in there). So after activating a mountroot dataset, you need to shutdown the machine in such a way that the "bootadm update-all script isn't run. Now, "halt -n" will do this, but I'm not sure if that will have any harmful side effects...

Update:This might need some work in light of the recent ZFS bootable dataset putback. I'll hop to it!


Comments:

I've updated this stuff to work with the new ZFS Bootable datasets stuff that's in snv_62 onwards. More here.

Posted by Tim Foster on April 01, 2007 at 02:04 PM IST #

Post a Comment:
  • HTML Syntax: NOT allowed

This blog copyright 2009 by timf