BigAdmin System Administration Portal
Community-Submitted Tech Tips
Print-friendly VersionPrint-friendly Version
This content is submitted by a BigAdmin user. It has not been reviewed for technical accuracy by Sun Microsystems, though it may have been lightly edited to improve readability. If you find an error or would like to comment on the article, please contact the submitter or use the comment field at the bottom of the article. Community submissions may not follow Sun trademark guidelines. For information on Sun trademarks, please see http://www.sun.com/suntrademarks/.
 
 

Using ZFS Root in OpenSolaris Developer Preview to Protect Yourself During Upgrades

Anthony Juckel, May 2008

One of the great features of OpenSolaris Developer Preview 2, which is not yet included in the Solaris Express distributions, is the use of ZFS for all file systems, even the root. For example, after installing it on my laptop, zfs list returns the following:

NAME                              USED  AVAIL  REFER  MOUNTPOINT
rpool                            15.2G  16.8G    53K  /rpool
rpool@install                    18.5K      -  49.5K  -
rpool/ROOT                       7.81G  16.8G    18K  /rpool/ROOT
rpool/ROOT@install                 15K      -    18K  -
rpool/ROOT/preview2              7.81G  16.8G  6.61G  legacy
rpool/ROOT/preview2@install       342M      -  1.94G  -
rpool/ROOT/preview2/opt           885M  16.8G   885M  /opt
rpool/ROOT/preview2/opt@install   120K      -  3.61M  -
rpool/export                     7.28G  16.8G    19K  /export
rpool/export@install               15K      -    19K  -
rpool/export/home                7.28G  16.8G   450K  /export/home
rpool/export/home@install          19K      -    21K  -

The file system rpool/ROOT/preview2 is mounted as / in the resulting system. Of particular interest is the fact that the install automatically snapshots the initial install file system for you. If you plan on doing any modifications to your file system that might alter the bootability of your system, I would suggest you first make the following modifications to ensure that you can always boot from this initial install snapshot.

Because you cannot boot directly from a snapshot, the first step is to clone the snapshot into a mountable file system, set its mountpoint to be legacy, and mount it:

$ pfexec zfs clone rpool/ROOT/preview2@install \
rpool/ROOT/install-clone
$ pfexec zfs set mountpoint=legacy rpool/ROOT/install-clone
$ pfexec mount -F zfs rpool/ROOT/install-clone /mnt/solaris0

Remember, if you make no modifications to this clone, there is nearly nil overhead in actual on-disk storage. ZFS is smart enough to keep track of the shared blocks between the two file systems, but you can also modify files on each file system (rpool/ROOT/preview2 and rpool/ROOT/install-clone) without affecting the data on the other.

Now that we have the file system mounted, we want to update vfstab on this new clone of the initial install so that we use our newly created file system for root. I made the following modifications in /mnt/solaris0/etc/vfstab:

# Comment out the original / mountpoint
#rpool/ROOT/preview2  - /  zfs  -  no  -

# Use the newly created clone as the / mountpoint.
rpool/ROOT/install-clone  - /  zfs  -  no  -

Finally, you can update GRUB to ensure that you always have the option of booting from this newly created clone. To do so, you have to edit /rpool/boot/grub/menu.lst. Note the path was not an error. If you attempt to edit the more familiar (to GRUB administrators) path /boot/grub/menu.lst, you'll see the following note:

##################################################################
#                                                                #
# For zfs root, menu.lst has moved to /rpool/boot/grub/menu.lst. #
#                                                                #
##################################################################

Before making your modifications, your menu.lst file should be similar to the following:

splashimage /boot/grub/splash.xpm.gz
timeout 30
default 0
#---------- ADDED BY BOOTADM - DO NOT EDIT ----------
title OpenSolaris Developer Preview 2 snv_79b X86
kernel$ /platform/i86pc/kernel/$ISADIR/unix -B $ZFS-BOOTFS
module$ /platform/i86pc/$ISADIR/boot_archive
#---------------------END BOOTADM--------------------

The $ZFS-BOOTFS variable tells GRUB to read the bootfs property from your rootpool. You can view this property as follows:

$ zpool get bootfs rpool
NAME   PROPERTY  VALUE                SOURCE
rpool  bootfs    rpool/ROOT/preview2  local

Now, we don't want to have to update this property every time we need to recover, but luckily the GRUB within the Solaris OS adds a bootfs command to GRUB that you can use to override the default behavior. Add the following to tell GRUB how to boot your new install snapshot clone:

# In case something goes wrong, use this to
# boot the initial install image.
title OpenSolaris Developer Preview 2 Initial Install
bootfs rpool/ROOT/install-clone
kernel$ /platform/i86pc/kernel/$ISADIR/unix -B $ZFS-BOOTFS
module$ /platform/i86pc/$ISADIR/boot_archive

After these steps are done, you should be able to reboot your Solaris machine, and choose the new title from the GRUB boot menu, and boot to a clone of the initial install of your system. Even if you break the system on rpool/ROOT/preview2, as I did during a recent BFU (blindingly fast upgrade), you can always boot to the clone in order to recover the original.

Also, it should be noted that all file systems under the original root will also be available within your clone install. For instance, when you boot from rpool/ROOT/install-clone, rpool/export/home will still be mounted for your home directories, as well as rpool/ROOT/preview2/opt.

Finally, be aware that there is nothing special about the @install snapshot that is created by default during the install of OpenSolaris Developer Preview 2. You can create your own snapshot at any time using the following:

$ pfexec zfs snapshot rpool/ROOT/preview2@recentsnapshot
$ pfexec zfs clone
rpool/ROOT/preview2@recentsnapshot rpool/ROOT/recentsnapshot
$ pfexec zfs set mountpoint=legacy rpool/ROOT/recentsnapshot

Then follow the previous instructions for updating /etc/vfstab and /rpool/boot/grub/menu.lst to be able to boot from this new snapshot.

About the Author

Anthony Juckel has been administering Linux at home and at work for 10 years. Within the last 2 years, technologies like ZFS and DTrace have convinced him to give the Solaris OS a serious look.

The information and links on this page have been provided by a BigAdmin user. The submitter is solely responsible for such information and links. Sun is not responsible for the availability of external sites or resources, and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. Sun will not be responsible or liable, directly or indirectly, for any actual or alleged damage or loss caused by or in connection with use of or reliance on the information posted here, or goods or services available on or through any external site or resource.
 
 

Comments (latest comments first)

Discuss and comment on this resource in the BigAdmin Wiki

Unless otherwise licensed, code in all technical manuals herein (including articles, FAQs, samples) is provided under this License.


BigAdmin