Beadm is a tool which provides a wonderful and distinctive functionality on Solaris, OpenIndiana and FreeBSD. It relies on the ZFS filesystem allowing to take a filesystem snapshot. That can be used to manage the so called boot environments which provide a great way to secure updates, even when everything goes down the tubes. Hence the name beadm (boot environment administration).
If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.
Use this link to get $200 credit at DigitalOcean and support Adminbyaccident.com costs.
Get $100 credit for free at Vultr using this link and support Adminbyaccident.com costs.
Mind Vultr supports FreeBSD on their VPS offer.
The basic principle and use is as follows. You pretend to update your system. It can be your home system or a production system for some important job of yours. System updates can contain changes to some core components such as the kernel. Many users have experienced reliable updates to their machines through the years and FreeBSD versions without a hassle. There is even a way to rollback the update if anything goes sideways. However there is a little chance of failure. Minuscule you may say but it exists nevertheless. And even if you rollback and everything gets back to its original state your nerves will suffer anyway if anything has gone the wrong direction. And even if they are made of steel you’ve lost some precious time.
Beadm comes handy to updates/upgrades. You look for an update and there is one. You create a new boot environment which is basically a way to take a snapshot of your file system at its current state. You then activate this new boot environment. You reboot your hardware and boot into this recently created filesystem. You apply the updates/upgrades to the machine. If anything goes wrong… you can boot to the old sane state, known as “old boot environment”. If everything has gone right you can use the system as you did before.
Here is a real example:
This is one of my machines. And I check its version with uname.
username@T430:~ % uname -a
FreeBSD T430 11.1-RELEASE-p1 FreeBSD 11.1-RELEASE-p1 #0: Wed Aug 9 11:55:48 UTC 2017 [email protected]:/usr/obj/usr/src/sys/GENERIC amd64
I then look for an update and bingo! There is one.
username@T430:~ % sudo freebsd-update fetch
Password:
src component not installed, skipped
Looking up update.FreeBSD.org mirrors... 3 mirrors found.
Fetching metadata signature for 11.1-RELEASE from update5.freebsd.org... done.
Fetching metadata index... done.
Fetching 2 metadata patches.. done.
Applying metadata patches... done.
Inspecting system... done.
Preparing to download files... done.
Fetching 2 patches.. done.
Applying patches... done.
The following files will be updated as part of updating to 11.1-RELEASE-p4:
/bin/freebsd-version
/boot/kernel/kernel
The updates have been downloaded but still haven’t been installed. I will prepare a boot environment just in case after installing them something breaks and my system comes into a brick state, sort of.
First of all I list my boot environments list.
usernmae@T430:~ % sudo beadm list
BE Active Mountpoint Space Created
default NR / 8.9G 2017-10-18 14:39
There is just one, the default one, since this system has been recently deployed. We create a new boot environment giving it the new version name of the system. You can use the name you may like.
username@T430:~ % sudo beadm create 11.1-RELEASE-p4
Created successfully
As you can see we have two boot environments.
username@T430:~ % sudo beadm list
BE Active Mountpoint Space Created
default NR / 8.9G 2017-10-18 14:39
11.1-RELEASE-p4 - - 172.0K 2017-11-16 20:55
We now have to activate this recently created BE. Why? Well… if we don’t do this the system will boot again to the current BE. And that is not what we want. We have set a new filesystem snapshot. We activate it and we reboot into it so we can apply the new changes.
username@T430:~ % sudo beadm activate 11.1-RELEASE-p4
Activated successfully
Notice the new environment has now a flag marked by an “R”. Next time we boot that will be the environment we will get into.
username@T430:~ % sudo beadm list
BE Active Mountpoint Space Created
default N / 328.0K 2017-10-18 14:39
11.1-RELEASE-p4 R - 8.9G 2017-11-16 20:55
username@T430:~ %
We now reboot the machine.
username@T430:~ % sudo shutdown -r now
Once we are in we install the updates using the freebsd-update command as we’ve always done.
username@T430:~ % sudo freebsd-update install
Password:
src component not installed, skipped
Installing updates... done.
Mind the updates included kernel updates. To take effect the system has to reboot completely once more.
username@T430:~ % sudo shutdown -r now
And voilá! The system has been now updated to its latest release, being at this time FreeBSD 11.1-p4.
username@T430:~ % uname -a
FreeBSD T430 11.1-RELEASE-p4 FreeBSD 11.1-RELEASE-p4 #0: Tue Nov 14 06:12:40 UTC 2017 [email protected]:/usr/obj/usr/src/sys/GENERIC amd64
username@T430:~ %
Updating a system hasn’t been as easy as it is now and as well as safely. Obviously this is very practical for home use but at enterprise level as well. You can easily rollback a whole machine into its previous state without a hassle or loss.
Beadm is the safety net for system administration acrobatics. And it’s quicker, easier and safer than having to rescue a system from backups at the same time you maintain bare metal performance. This snapshot, cloning thing is the same thing you may find in commercial software such as VMWare or Hyper-V and the like. However as you know there is a performance penalty using those technologies as well as an associated cost on licenses.
Beadm and the ZFS capabilities are one of those technological reasons which set FreeBSD, Illumos and Solaris appart. For home users this may be a trivial thing. For production systems on the enterprise this may be a very good reason to contemplate this alternatives to the Linux ecosystem.
If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.
Use this link to get $200 credit at DigitalOcean and support Adminbyaccident.com costs.
Get $100 credit for free at Vultr using this link and support Adminbyaccident.com costs.
Mind Vultr supports FreeBSD on their VPS offer.