I do not have to remind you that I am a big fan of ZFS Boot Environments feature. From the time when I first used it on OpenSolaris and Solaris systems I was really fascinated by it. Bulletproof upgrades and changes to entire system … and it was possible more then decade ago. Like a Dream. Today with beadm(8) and bectl(8) tools and also the FreeBSD loader(8) the ZFS Boot Environments are first class and one of the main features of the FreeBSD operating system.
Back in the more ‘normal’ times (before C19) I was able to talk two times about ZFS Boot Environments. I hope I explained them well.
- 1st in Poland at PBUG meeting – with presentation available HERE.
- 2nd in Holland at NLUUG conference – with presentation available HERE.
I do not know any downsides of ZFS Boot Environments but if you would stick a gun into my head and make me find one – I would say that you still have to reboot(8) to change to the other BE. This is about to change …
Reroot Instead Reboot
What is reroot? Its the ability to switch to other root filesystem without the need for full system reboot. The loaded and running kernel stays the same of course – but this is the only downside. This feature is implemented in the reboot(8) command with -r argument.
As we can read in the FreeBSD 10.3-RELEASE Release Notes page:
The initial implementation of “reroot” support has been added to the reboot(8) utility, allowing the root filesystem to be mounted from a temporary source filesystem without requiring a full system reboot. (r293744) (Sponsored by The FreeBSD Foundation)
How can reroot be useful here? It will save you a lot of time when you did not updated the kernel. There are two types of update strategies when using the ZFS Boot Environments. You can create new BE (as a backup world that you can get back to) and update the running system. Then you can use checkrestart(1) to verify which processes should be restarted because either binaries or libraries has been updated.
The other way was to create new separate BE (while not touching the running one) and then mount it and update that new BE and reboot into it later. This created a need to reboot(8) but not anymore. Especially when you just update the packages with pkg(8) command.
beadm(8)
With the new reroot option of beadm(8) you will tell FreeBSD to reroot your running kernel into specified BE. It will definitely have less impact in virtual machines as they reboot quite fast but imagine saved time on a server class physical machine with about 10 minutes lost for BIOS POST messages and initialization … or personal desktop/laptop GELI encrypted system without the need to type in again the GELI password to decrypt it after reboot.
On the screenshot above I use the latest FreeBSD 13.1-BETA1 but it works the same on other production FreeBSD releases such as 12.3-RELEASE or 13.0-RELEASE. The new upgraded beadm(8) is available from its home at GitHub page here:
I will add that updated version to the FreeBSD Ports tree later along with updated man page later.
Usage
Usage of this new feature is quite simple. You type beadm reroot BENAME in the terminal and FreeBSD reroots into that BE without reboot. Takes about 9-10 seconds on my 11 years old ThinkPad W520 so it may be even faster on your more up to date system.
# beadm list BE Active Mountpoint Space Created 12.3 - - 9.5G 2021-10-18 13:14 13.0.p6 - - 13.9G 2022-01-27 11:07 13.0 - - 12.9G 2022-03-05 15:02 13.0.safe - - 2.8M 2022-03-08 14:54 13.1 NR / 9.5G 2022-03-12 00:18 13.1.safe - - 544.0M 2022-03-13 23:18 # beadm activate 13.1.safe Activated successfully # beadm reroot 13.1.safe
… and you are going the route similar to typing shutdown now on a running system. All services are stopped. Then root is changed to new one. Then system continues to boot along with starting all its services as usual. Just without the BIOS POST and the bootloader and kernel parts.
The reroot feature is especially useful in one of these scenarios:
From what I know the bectl(8) does not has that reroot feature but maybe it will be added to it somewhere in the future.
Summary
Not sure that ZFS Boot Environments Revolutions is the best title for this blog post, but as I used Reloaded on my 2nd ZFS Boot Environments presentation I though that sticking to The Matrix (1999) schema. I could of course do 3rd and updated presentation … but I am afraid that it will not happen … or at least not soon.
I did not thought that the FreeBSD Enterprise Storage presentation that I gave at 2020/02 PBUG would be my last – it was more then 2 years ago.
UPDATE 1 – Faster Upgrade with New beadm(8) Version
Today (2022/05/06) I introduced new beadm(8) version 1.3.5 that comes with new chroot(8) feature. It has already been committed to the FreeBSD Ports tree under 263805 PR so expect packages being available soon.
You can also update beadm(8) directly like that:
# fetch -o /usr/local/sbin/beadm https://raw.githubusercontent.com/vermaden/beadm
Now for the faster update process – here are the instructions depending on the shell you use.
- ZSH / CSH
# beadm create 13.1-RC6 # beadm chroot 13.1-RC6 BE # zsh || csh BE # yes | freebsd-update upgrade -r 13.1-RC6 BE # repeat 3 freebsd-update install BE # exit # beadm activate 13.1-RC6 # reboot
- SH / BASH / FISH / KSH
# beadm create 13.1-RC6 # beadm chroot 13.1-RC6 BE # sh || bash || fish || ksh BE # yes | freebsd-update upgrade -r 13.1-RC6 BE # seq 3 | xargs -I- freebsd-update install BE # exit # beadm activate 13.1-RC6 # reboot
Happy upgrading π
EOF
Pingback: Valuable News – 2022/03/14 | ππππππππ
Good info; I can see it being useful in some cases, but not in all (as you point out).
Thanks.
LikeLike
Rerooting is _NOT_ a replacement for rebooting when upgrading a system, which is the primary reason ZFS boot environments exist.
The primary reason why it was implemented, as documented in the original commit message on https://cgit.freebsd.org/src/commit/?id=3f5ac575ea12 was to move from UFS to ZFS without rebooting the system, not as a way to avoid rebooting – and the process has been documented at least as far back as 2017 by Kurt Lidl on https://people.freebsd.org/~lidl/blog/re-root.html before he tragically passed away.
LikeLike
If you do not change the kernel – its faster to reroot then to reboot.
For example, I recently updated the packages on my running system. One of these packages were broken after upgrade. Kernel did not changed so I reroot back to BE I created before that pkg upgrade command.
If you do not need to use reroot then do not use it but many people will find it useful.
Regards.
LikeLiked by 1 person
Pingback: FreeBSD 13.1 on ThinkPad W520 | ππππππππ
Sorry if I ask an off-topic question: At the bottom of the article, I notice you mention two families of shells, zsh/csh and sh/bash/fish/ksh. May I know which ones you use for daily terminal work? Are there any pages here about shells?
LikeLiked by 1 person
I wanted to cover as much as possible for the upgrade process above. These shells – as they are grouped – are not ‘families’ exactly – its just ZSH and CSH shells support the repeat … command syntax – so that makes less typing with them while other shells need the ‘typical’ seq … | xargs scripting because they do not implement the repeat … command syntax.
I personally use ZSH with config described here:
– https://vermaden.wordpress.com/2021/09/19/ghost-in-the-shell-part-7-zsh-setup/
You may also check other parts of the – https://vermaden.wordpress.com/ghost-in-the-shell/ – Ghost in the Shell series – but they are not that much focused on shells as more on command line useful one-liners and solutions.
I do not like CSH/TCSH/FISH shells as they do not support the POSIX /bin/sh loops and scripting – which makes them very hard to use as daily driver – at least for me – as I often drop for I in …; do something “${I}”; done on the terminal.
I do not have anything against KSH or BASH but they are just SO MUCH LIMITED comparing to what ZSH can do (especially with config and fish(1) like coloring that I use – and my config is plain/short/simple without any additional ‘frameworks’ like OhMyZsh or anything like that).
I use bash(1) daily on many Linux servers and ksh(1) on AIX systems … but to be honest the first thing I do after logging into the AIX system is typing bash to have at least *some* command completion π
Regards.
LikeLiked by 1 person
Thank you very much for the thorough explanation, the links, and your time!
LikeLiked by 1 person
No problem π
LikeLiked by 1 person