This page looks best with JavaScript enabled

Switching between Linux and FreeBSD boot via UEFI

 ·  🎃 kr0m

The biggest issue with having multiple operating systems installed simultaneously is that we can only assign one default option at boot. If we boot Linux, there is no problem since we can use grub-set-default to change the default entry. However, if we boot another OS like FreeBSD, we won’t be able to return to Linux since we can’t modify the Linux Grub configuration from FreeBSD. To solve this problem, we will use the boot options provided by UEFI from both Linux and FreeBSD.

In Gentoo, we compile the tool. In FreeBSD, it won’t be necessary since it is part of the base system:

emerge -av sys-boot/efibootmgr

The first step will be to check the status of the UEFI entries:

efibootmgr -v

BootCurrent: 0001
Timeout: 1 seconds
BootOrder: 0002,0004,0005,0006,0007,0008,0009,0003,0001
Boot0001* gentoo    HD(3,GPT,839e3608-bfd6-42ba-94a2-14c3d5ae227c,0x2e1800,0x32000)/File(\EFI\GENTOO\GRUBX64.EFI)
Boot0002*     HD(3,GPT,839e3608-bfd6-42ba-94a2-14c3d5ae227c,0x2e1800,0x32000)/File(\EFI\FREEBSD\BOOT1.EFI)
Boot0003* UEFI OS    HD(1,GPT,eb358698-5581-11e9-8ecb-3497f636bf45,0x28,0x64000)/File(\EFI\BOOT\BOOTX64.EFI)..BO
Boot0004* UEFI OS    HD(1,GPT,eb358698-5581-11e9-8ecb-3497f636bf45,0x28,0x64000)/File(\EFI\BOOT\BOOTX64.EFI)..BO
Boot0005* Samsung SSD 850 EVO 500GB    BBS(HD,,0x0)..BO
Boot0006* WDC WD10EAVS-00D7B1    BBS(HD,,0x0)..BO
Boot0007* WDC WD60EFRX-68L0BN1    BBS(HD,,0x0)..BO
Boot0008* KINGSTON SA400S37120G    BBS(HD,,0x0)..BO
Boot0009* WDC WD20EARX-00PASB0    BBS(HD,,0x0)..BO
Boot000A* WDC WD20EARX-00PASB0    BBS(HD,,0x0)..BO
Boot000C* KINGSTON SA400S37120G    BBS(HD,,0x0)..BO
Boot000F* KingstonDataTraveler 3.0PMAP    BBS(HD,,0x0)..BO

If we want to modify the Next boot to entry 0002 (FreeBSD), we execute:

efibootmgr -n 0002

If we want to modify the Boot order (GrubGentoo, FreeBSD):

efibootmgr -o 0001,0002


To add entries, we must take into account the disk and partition where the UEFI files reside. We can check it from both Linux and FreeBSD.

  • FreeBSD:

    gpart show

    =>       34  976773101  ada0  GPT  (466G)
        3020800     204800     3  efi  (100M)
    
    mount -t msdosfs /dev/ada0p3 /mnt/aux/
    efibootmgr -c -l /mnt/aux/EFI/gentoo/grubx64.efi -L gentoo
  • Linux:

    fdisk -l /dev/sda

    /dev/sda3    3020800   3225599    204800   100M EFI System
    
    efibootmgr -c -d /dev/sda -l /EFI/freebsd/boot1.efi -L freebsd -p 3

To remove entries.

  • FreeBSD:

    efibootmgr -B ID

  • Linux:

    efibootmgr -b ID -B


For more information about efibootmgr and UEFI on FreeBSD:
https://www.freebsd.org/cgi/man.cgi?query=efibootmgr&sektion=8&manpath=freebsd-release-ports
https://www.freebsd.org/cgi/man.cgi?query=uefi&sektion=8&manpath=freebsd-release-ports

If you liked the article, you can treat me to a RedBull here