I am known as a strong ZFS Boot Environment supporter … and not without a reason. I have stated the reasons ‘why’ many times but most (or all) of them are condensed here – https://is.gd/BECTL – in my presentation about it.
The upcoming FreeBSD 13.0-RELEASE looks very promising. In many tests it is almost TWICE as fast as the 12.2-RELEASE. Ouch!
The detailed tests are available on the phoronix.com site.
Having 12.2-RELEASE installed I wanted to check 13.0-BETA* to check if things that are important for me – like working suspend/resume for example – work as advertised on the newer version. It is the perfect task that can be achieved by using ZFS Boot Environments.
In the example below we will create entire new ZFS Boot Environment with clone of our current 12.2-RELEASE system and upgrade it there (in BE) to the 13.0-BETA3 version … and there will only be required on reboot – not three as in typical freebsd-update(8) upgrade procedure.
I assume that you have FreeBSD 12.2-RELEASE installed with ZFS (default ZFS FreeBSD install) and its installed in UEFI or UEFI+BIOS mode.
Here are the steps that will be needed.
(host) # beadm create 13 # create new '13' ZFS Boot Environment Created successfully (host) # beadm mount 13 /var/tmp/BE-13 # mount new '13' BE somewhere Mounted successfully on '/var/tmp/BE-13' (host) # chroot /var/tmp/BE-13 # make chroot(8) into that place (BE) # mount -t devfs devfs /dev # mount the devfs(8) in that BE (BE) # rm -rf /var/db/freebsd-update # remove any old patches (BE) # mkdir /var/db/freebsd-update # create fresh dir for patches (BE) # freebsd-update upgrade -r 13.0-BETA3 # fetch the patches needed for upgrade (BE) # freebsd-update install # install kernel and kernel modules (BE) # freebsd-update install # install userspace/binaries/libraries (BE) # pkg upgrade # upgrade all packages with pkg(8) (BE) # freebsd-update install # remove old libraries and files (BE) # exit # leave chroot(8) environment (host) # umount /var/tmp/BE-13/dev # umount the devfs(8) in that BE (host) # beadm activate 13 # activate new '13' BE Activated successfully
I am using mine sysutils/beadm for the process but you as well may use the bectl(8) from FreeBSD base system.
We will also need new FreeBSD loader(8) which will be updated this way – thanks to @JeffSipek for pointing that out.
On my system FreeBSD is installed on ada1 device.
(host) # gpart show -p ada1 | grep efi # find UEFI msdosfs(5) partition 40 409600 ada1p1 efi (200M) # <-- this one (host) # mount_msdosfs /dev/ada1p1 /mnt # mount it under /mnt (host) # find /mnt # display its contents /mnt /mnt/efi /mnt/efi/boot /mnt/efi/boot/bootx64.efi # update bootx64.efi file (host) # cp /boot/boot1.efi /mnt/efi/boot/bootx64.efi # copy from /boot/boot1.efi file (host) # umount /mnt # unmount /mnt filesystem
There is small chance that you will not be able to mount the efi partition. Even fsck(8) is not able to help here.
Typical errors that some users faced look like that:
(host) # mount_msdosfs /dev/ada1p1 /mnt # error when trying to mount efi partition mount_msdosfs: /dev/ada1p1: Invalid argument (host) # fsck_msdosfs -y /dev/ada1p1 # error when trying to fsck(8) that partition ** /dev/ada1p1 Invalid signature in boot block: 0b6a
If you hit that problem then first backup your current efi partition to for example /BACKUP.ada1p1 file.
(host) # dd < /dev/ada1p1 > /BACKUP.ada1p1 bs=1m
Now we will create fresh efi partition from scratch.
(host) # newfs_msdos -F 32 -c 1 /dev/ada0p1 # create new FAT32 partition (host) # mount_msdosfs /dev/ada0p1 /mnt # mount it under /mnt (host) # mkdir -p /mnt/efi/boot # create needed directories (host) # cp /boot/loader.efi /mnt/efi/boot/bootx64.efi # copy from /boot/loader.efi file (host) # umount /mnt # unmount /mnt filesystem
Now you should have new ‘working’ efi partition.
The last step is to reboot(8) into the new 13.0-BETA3 system.
(host) # reboot
If you find any problems with new bootloader not being able to load your new FreeBSD then you may alternatively copy the /boot/boot1.efi instead of /boot/loader.efi into the /mnt/efi/boot/bootx64.efi place.
Keep in mind that if you boot from geli(8)encrypted system then /boot/loader.efi is mandatory and you will not be able to boot if you would use /boot/boot1.efi file instead.
You should now see the new FreeBSD loader(8) in all its glory 🙂
You may now enjoy latest FreeBSD 13.0-BETA3 installation.
Same steps will be required to update to soon to be available FreeBSD 13.0-RC* (RC1/RC2/RC3) version and finally FreeBSD 13.0-RELEASE hopefully somewhere in March 2021.
UPDATE 1 – What if Everything Went Fine
You now have most up to date FreeBSD system that should work faster then 12.2-RELEASE and you still has your older 12.2-RELEASE Boot Environment that you can go back to if you find any problems with 13.0 version.
On my system it looks like that:
(host) # beadm list BE Active Mountpoint Space Created 12.2 - - 6.5G 2021-02-12 10:15 13 NR / 18.8G 2021-02-13 11:32
The Space column is little misleading as it takes into account snapshots space used for example. To get exact information each Boot Environment takes use -D option. This way you will get information about each Boot Environment space separately.
(host) # beadm list -D BE Active Mountpoint Space Created 12.2 - - 9.8G 2021-02-12 10:15 13 NR / 9.6G 2021-02-13 11:32
I will be keeping the 12.2-RELEASE Boot Environment for a while – maybe I will delete it a month or so after 13.0-RELEASE is available but if you tested all your needs and feel that 13.0 fulfills all your needs the same way or better then 12.2-RELEASE then you may delete that older Boot Environment with below command.
(host) # beadm destroy 12.2
UPDATE 2 – What if Something Goes Wrong
Generally if the new BE named ‘13‘ does not boot (or hangs at boot) then just select your earlier Boot Environment that you used before the upgrade – the one that has 12.2-RELEASE inside it.
You now have the system that worked for you before we proceed to the upgrade process.
If that fails (or bootloader is broken) then grab the FreeBSD-13.0-BETA3-amd64-memstick.img image and write it on some pendrive with dd(8) command.
# dd if=FreeBSD-13.0-BETA3-amd64-memstick.img of=/dev/da0 bs=1M status=progress
As you now have the pendrive with FreeBSD 13.0-BETA3 then you may boot from it and fix your installation. Pick LiveCD after its loaded. Then type root at login: prompt and hit [ENTER] for empty password.
The list of tasks that can be done now depends on what is broken and I can not guess every possible error and fix scenario so if you hit any problems during that upgrade process then just contact me with your preferred way and we will figure something out.
UPDATE 3 – 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 🙂