Solaris 11 IPS hand-on LAB – Boot environments beadm

por | 23 julio, 2014

Boot Environments

Boot environments in solaris 11 are multiple images with different kernel, software applications and packages. Only one boot environment can be active at a time. We can boot into different boot environments according to our need. The command to manage boot environments in solaris is beadm. BEs are extremely useful in case of rolling back any software upgrades. The BEs are actually designed over ZFS file system, so its important to have ZFS file system for root.

Now by default we have a BE with name solaris when you install a fresh solaris 11 operating system.

# beadm list
BE      Active Mountpoint Space Policy Created
--      ------ ---------- ----- ------ -------
solaris NR     /          2.28G static 2013-11-19 02:41

As you can see the default BE solaris is the active BE on reboot (NR flag denotes Active on next reboot).

Let us now create a new boot environment called geekBE.

# beadm create geekBE
# beadm list
BE      Active Mountpoint Space  Policy Created
--      ------ ---------- -----  ------ -------
geekBE  -      -          150.0K static 2013-11-19 10:19
solaris NR     /          2.28G  static 2013-11-19 02:41

As you can see the new BE is created but its not active. Check the size of this BE, 150 KB. Check the size of the geekBE when you activate it.

To activate the new BE :
The geekBE will get activated on next reboot. As you can see in the Active column below (R denotes reboot)

# beadm activate geekBE
# beadm list
BE      Active Mountpoint Space Policy Created
--      ------ ---------- ----- ------ -------
geekBE  R      -          2.28G static 2013-11-19 10:19
solaris N      /          37.0K static 2013-11-19 02:41

If you can see now, the size of geekBE is 2.28 GB, as its active BE now.

We can also mount a BE to see the contents of it.

# beadm mount geekBE /mnt

Similarly to umount it :

# beadm umount geekBE

To list a complete information about the new BE we created :

# beadm list -a geekBE
BE/Dataset/Snapshot                          Active Mountpoint Space   Policy Created
-------------------                          ------ ---------- -----   ------ -------
geekBE
   rpool/ROOT/geekBE                         R      -          2.11G   static 2013-11-19 10:19
   rpool/ROOT/geekBE/var                     -      -          129.20M static 2013-11-19 10:19
   rpool/ROOT/geekBE/[email protected]:49:13 -      -          42.0K   static 2013-11-19 10:19
   rpool/ROOT/geekBE/[email protected]             -      -          38.56M  static 2013-11-19 02:45
   rpool/ROOT/[email protected]:49:13     -      -          308.0K  static 2013-11-19 10:19
   rpool/ROOT/[email protected]                 -      -          6.46M   static 2013-11-19 02:45

Installing packages in BE

You can install a package in a particular BE. If the BE is already active the you have to simply use the original pkg install command.

In case you want to add a package by creating a new BE :

# pkg install --be-name newBE vim
           Packages to install:   1
       Create boot environment: Yes
Create backup boot environment:  No

DOWNLOAD                                PKGS         FILES    XFER (MB)   SPEED
Completed                                1/1     1528/1528      7.8/7.8    0B/s

PHASE                                          ITEMS
Installing new actions                     1673/1673
Updating package state database                 Done
Updating image state                            Done
Creating fast lookup database                   Done

A clone of solaris exists and has been updated and activated.
On the next boot the Boot Environment newBE will be
mounted on ‘/’. Reboot when ready to switch to this updated BE.

Snapshots of BE

We can also take snapshots of BEs similar to the ZFS file system snapshots.

# beadm create [email protected]

The -s option in beadm list would also display the snapshot we just created

# beadm list -s geekBE
BE/Snapshot                   Space  Policy Created
-----------                   -----  ------ -------
geekBE
   [email protected]:47:00 311.0K static 2013-11-19 11:17
   [email protected]             6.51M  static 2013-11-19 02:45
   [email protected]              0      static 2013-11-19 11:24

We can also create new BEs using the snapshots.

# beadm create -e [email protected] newBE
## beadm list
BE      Active Mountpoint Space Policy Created
--      ------ ---------- ----- ------ -------
geekBE  R      -          2.31G static 2013-11-19 11:17
newBE   -      -          60.0K static 2013-11-19 11:27
solaris N      /          90.0K static 2013-11-19 02:41
# beadm list
BE      Active Mountpoint Space  Policy Created
--      ------ ---------- -----  ------ -------
geekBE  -      -          150.0K static 2013-11-19 10:31
newBE   R      -          2.41G  static 2013-11-19 10:36
solaris N      /          2.78M  static 2013-11-19 02:41

When you install the vim package by creating a new BE, it gets automatically created and activated as well on next reboot.

Destroying BE

In order to destroy a BE use :

# beadm destroy newBE
Are you sure you want to destroy newBE?  This action cannot be undone(y/[n]): y
The BE that was just destroyed was the 'active on boot' BE.
solaris is now the 'active on boot' BE. Use 'beadm activate' to change it.

I hope the post was informative. Stay tuned for more on Oracle Solaris 11.

Nice example for the power of boot environments

Tuesday, October 4. 2011

There is a nice example of the power of boot environment. Boot environments are something like snapshots of your operating system installation made writeable. As you may already assume, they are based on ZFS snapshots and the clone functionality. This is possible due to the usage of ZFS as the root filesystem.So: Please don’t try this at home. Whey you try it, don’t try it on any Solaris 11 Express installation of any value. But don’t try it. I don’t want to hear any story. that you’ve deleted your ERP system by accident because you used the wrong terminal window. Leave that to trained professional stunt admins with the right equipment (Solaris 11 Express) ;-)

Assume you have a system, configured with all your application, everything is running fine. So you think it would be nice to have something like a freezed state of this situation. No problem. This command will do the trick.

# beadm create rescuenet
# init 6

When you reboot your system you will see it as a new entry in the grub menu.

Okay, but boot into the old environment starting «Oracle Solaris …» first by selecting it in the grub menu (it should be already selected, or you used beadm activate already. Now i will drop the atomic bomb on your installation.

# rm --no-preserve-root -rf /

Essentially we’ve just nuked the installation. After a moment the system should just freeze. Reset the system and boot again via grub into the boot environment starting with «Oracle Solaris …»:

Okay … on a normal system this would send you to the tapes. With Solaris 11: Reset the system. Boot into the boot environment «rescuenet» via selecting it in grub.

Tada! Just creating a boot environment with a single command after a config change may safe your butt later …. and btw … this even works in zones … they know the concepts of boot environment,too.