|
By Hugo Rivero, with contributions from Marina Sum, November 25, 2008, updated: December 16, 2008
|
|
|
Note: Subsequent to the OpenSolaris 2008.11 release in early December, we've updated the content of this article to match the file structure in the new release.
Often, developers must maintain multiple system configurations and switch back and forth among them for testing. With the introduction of ZFS in the Solaris 10 OS in 2005, you could take snapshots and clone file systems with minimal space overhead and time delay, thereby backing up and restoring environments. However, several steps were involved, particularly if the environment contained multiple file systems.
New in the OpenSolaris OS (henceforth, OpenSolaris) is a utility called beadm with which you can more efficiently manage boot environments, BEs for short. beadm seamlessly handles the tasks of copying all relevant file systems and updating the GNU GRUB [GRand Unified Bootloader] menu on the x86 and x64 platforms. Furthermore, you can create, modify, or delete BEs in a single step.
In this article, you learn how to manage BEs on OpenSolaris with beadm through an example.
Contents
Verifying Your Environment
While booting a new installation of OpenSolaris, OpenSolaris 2008.11 in this example, you see the GRUB menu, similar to the one shown in Figure 1.
Figure 1. GRUB Menu in OpenSolaris 2008.11 |
This menu shows that only one BE is currently available. Once the OS has booted, you can verify that by executing beadm list:
jack@opensolaris:~$ beadm list
BE Active Mountpoint Space Policy Created
-- ------ ---------- ----- ------ -------
opensolaris NR / 2.58G static 2008-12-05 11:35
|
Here, the BE is called opensolaris. By running the df command, you'll see that the ZFS root file system also shares the same name:
jack@opensolaris:~$ df /
Filesystem 1K-blocks Used Available Use% Mounted on
rpool/ROOT/opensolaris 14955636 2433976 12521660 17% /
|
Cloning Your Environment
The set of file systems that constitute a BE is the root file system itself and all its children. By default, a BE contains only the / file system, but you can add more file systems as needed.
Note: If you upgrade from a previous OpenSolaris release, you might see /opt as a separate file system. The output in the rest of this article is what is displayed if OpenSolaris 2008.11 is your first OpenSolaris installation.
For example, the following command (executed as root, all on one line) creates an empty file system, to be mounted under /MyData:
root@opensolaris:~# zfs create -o mountpoint=/MyData -o canmount=noauto rpool/ROOT/opensolaris/MyData
|
Browse the directories in ZFS and you'll see this output:
jack@opensolaris:~$ zfs list -r rpool/ROOT/opensolaris
NAME USED AVAIL REFER MOUNTPOINT
rpool/ROOT/opensolaris 2.45G 11.9G 2.32G /
rpool/ROOT/opensolaris/MyData 18K 11.9G 18K /MyData
|
Suppose you're about to make significant changes to the BE but would like to preserve it and boot back into it if necessary. Simply create another BE called, say, test_be, with beadm:
root@opensolaris:~# beadm create test_be
root@opensolaris:~# beadm list
BE Active Mountpoint Space Policy Created
-- ------ ---------- ----- ------ -------
opensolaris NR / 2.58G static 2008-12-05 11:35
test_be - - 61.0K static 2008-12-07 20:43
|
The beadm create command takes only a couple of seconds to complete. Note the minimal space for test_be with no modified data. Upon reboot, test_be will show up in the GRUB menu. See Figure 2.
Figure 2. GRUB Menu With Two Boot Environments |
Voilà! You've just cloned all the file systems in opensolaris, the original BE, and updated the GRUB menu with a single command.
Exploring the Setup
Take a look under the cover. You'll see that beadm has created snapshots—read-only images of a file system—for all the file systems in opensolaris:
jack@opensolaris:~$ zfs list -r -t filesystem,snapshot rpool/ROOT/opensolaris
NAME USED AVAIL REFER MOUNTPOINT
rpool/ROOT/opensolaris 2.53G 11.9G 2.34G /
rpool/ROOT/opensolaris@test_be 67.7M - 2.32G -
rpool/ROOT/opensolaris/MyData 18K 11.9G 18K /MyData
rpool/ROOT/opensolaris/MyData@test_be 0 - 18K -
|
A snapshot is identified by the @ delimiter, followed by the snapshot name, test_be in this example. Once it has captured all the snapshots, beadm uses them to create clones of the original BE, as shown here:
jack@opensolaris:~$ zfs list -r rpool/ROOT/test_be
NAME USED AVAIL REFER MOUNTPOINT
rpool/ROOT/test_be 61K 11.9G 2.32G /
rpool/ROOT/test_be/MyData 0 11.9G 18K /MyData
|
Finally, note that beadm has also revised the GRUB menu accordingly:
jack@opensolaris:~$ more /rpool/boot/grub/menu.lst
splashimage /boot/grub/splash.xpm.gz
background 215ECA
timeout 30
default 0
#---------- ADDED BY BOOTADM - DO NOT EDIT ----------
title OpenSolaris 2008.11 snv_101b_rc2 X86
findroot (pool_rpool,0,a)
splashimage /boot/solaris.xpm
foreground d25f00
background 115d93
bootfs rpool/ROOT/opensolaris
kernel$ /platform/i86pc/kernel/$ISADIR/unix -B $ZFS-BOOTFS,console=graphics
module$ /platform/i86pc/$ISADIR/boot_archive
#---------------------END BOOTADM--------------------
title OpenSolaris 2008.11 snv_101b_rc2 X86 text boot
findroot (pool_rpool,0,a)
bootfs rpool/ROOT/opensolaris
kernel$ /platform/i86pc/kernel/$ISADIR/unix -B $ZFS-BOOTFS
module$ /platform/i86pc/$ISADIR/boot_archive
title test_be
findroot (pool_rpool,0,a)
splashimage /boot/solaris.xpm
foreground d25f00
background 115d93
bootfs rpool/ROOT/test_be
kernel$ /platform/i86pc/kernel/$ISADIR/unix -B $ZFS-BOOTFS,console=graphics
module$ /platform/i86pc/$ISADIR/boot_archive
#============ End of LIBBE entry =============
|
At this point, test_be is an exact replica of the opensolaris BE. As you modify the / and /MyData directories, they will consume more disk space.
Managing Boot Environments
To return to the original BE, just reboot and choose it from the GRUB menu.
If a BE is no longer necessary, feel free to delete it:
- As root, type, for example:
root@opensolaris:~# beadm destroy test_be |
beadm prompts you to confirm:
Are you sure you want to destroy test_be? This action cannot be undone (y/[n]): |
- Type
y to confirm.
Afterwards, beadm deletes all the snapshots and clones for test_be and the ZFS pool immediately reclaims the space. Finally, beadm updates the GRUB menu.
Conclusion
The OpenSolaris beadm utility offers a simple, flexible, and versatile capability that enables you to manage multiple boot environments on your system. For more details, see the beadm Command Reference documentation.
|
Hugo Rivero is a senior staff engineer at Sun's ISV Engineering team. He has been working for over 10 years on porting applications to the Solaris platform and optimizing them. Currently, Hugo leads the OpenSolaris adoption efforts with ISVs and open-source communities and blogs regularly on technical topics.
|
Marina Sum, is a staff writer for Sun Developer Network. She has been writing for Sun since 1989, mostly in the technical arena. Marina blogs on Sun products, technologies, events, publications, and unsung heroes.
|
|