Solved UEFI only laptop and FreeBSD

Hey everyone,
I am trying to boot up FreeBSD on a UEFI only laptop and failed so far. Here is some backstory
I am a long time Linux user and wanted to try out FreeBSD as a desktop OS. I plugged in my second hard drive and passed it through a kvm machine then installed FreeBSD and all that jazz. When I configured my system inside that kvm machine i tried to boot it up bare metal on my laptop but could not find find that drive as an option in my boot menu. After digging a bit i found out that my FreeBSD installation is using legacy BIOS (while using GPT) but my laptop is UEFI only and cannot boot in legacy mode at all (2021 laptop so fairly new). Back in my linux machine booted that kvm machine back up and looked around.
First thing I found was that it was actually booting with legacy mode while running as a vm aswell (sysctl machdep.bootmethod returns BIOS). Now the question remained if I can make it boot using UEFI and completely ignore legacy mode. I opened up FreeBSD wiki and found this https://wiki.freebsd.org/UEFI but i cannot figure out what exactly i need to do on an existing installation. Apparently there is a freebsd-boot partition which is 512K big (Don't exactly know why exists because /boot is located on my main freebsd-ufs partition and not that freebsd-boot and i could not mount the boot partition either) and i was thinking of resizing freebsd-ufs and creating a fat32 partition and do the same thing the UEFI wiki did
newfs_msdos -F 32 -c 1 /dev/da0p1 mount -t msdosfs /dev/da0p1 /mnt mkdir -p /mnt/EFI/BOOT cp /boot/loader.efi /mnt/EFI/BOOT/BOOTX64.efi
Is this the right way to do it? Wouldn't it be easier to install grub2 on FreeBSD? does grub2 on FreeBSD even support UEFI? (Not dual booting with my linux machine but having a grub bootloader for each of my drives and i do not like dual booting it feels very dirty)
I am a bit lost in where I should look into.
Best regards
 
I get sometimes the system failing to boot, because of a wrong boot device.
Hitting ESC just after switching on the computer takes me to the bios menu, then choosing the right UEFI device to boot from.
 
I get sometimes the system failing to boot, because of a wrong boot device. Hitting ESC just after switching on the computer takes me to the bios menu, then choosing the right UEFI device to boot from.

I tried this multiple times before but the hard drive is not recognized as some bootable device at all
Only my nvme is recognized which is my linux drive.
 
Apparently there is a freebsd-boot partition which is 512K big (Don't exactly know why exists because /boot is located on my main freebsd-ufs partition and not that freebsd-boot and i could not mount the boot partition either)
The freebsd-boot partition embeds a bootstrap code (in your case /boot/gptboot, for details see gpart(8), BOOTSTRAPPING), it does not contain boot loader, accessory helper scripts or the kernel, it can't be mounted, it has no file system.

i was thinking of resizing freebsd-ufs and creating a fat32 partition and do the same thing the UEFI wiki did
FreeBSD UFS2 can only be grown in size, not shrunk. You can add a FAT32 partition only if there is at least 1m free space left on the disk, so that /boot/loader.efi can fit in it.

If I where you, I would copy a FreeBSD installer image on a USB stick, plug the second hard drive and install fresh.

If you insist on KVM installation, enable UEFI to the VM before installing FreeBSD.

Wouldn't it be easier to install grub2 on FreeBSD? does grub2 on FreeBSD even support UEFI? (Not dual booting with my linux machine but having a grub bootloader for each of my drives
There is no GRUB port/package for FreeBSD, it needs to be installed from a Linux system, and it needs some detailed boot menu configuration. I would recommend rEFInd instead, it's working out of the box.
 
The freebsd-boot partition embeds a bootstrap code (in your case /boot/kernel/gptboot, for details see gpart(8), BOOTSTRAPPING), it does not contain boot loader, accessorie helper scripts or the kernel, it can't be mounted, it has no file system.


FreeBSD UFS2 can only be grown in size, not shrunk. You can add a FAT32 partition only if there is at least 1m free space left on the disk, so that /boot/loader.efi can fit in it.

If I where you, I would copy a FreeBSD installer image on a USB stick, plug the second hard drive and install fresh.

If you insist on KVM installation, enable UEFI to the VM before installing FreeBSD.


There is no GRUB port/package for FreeBSD, it needs to be installed from a Linux system, and it needs some detailed boot menu configuration. I would recommend rEFInd instead, it's working out of the box.
Thank you for your detailed explanation.
Looks like there is a 1MB partition available (Made by default but unused? check the attachment).
So should i copy loader.efi to that 1MB partition and thats it?
The reason I decided to use my KVM setup first was because although i have been a long time Linux user i still do not feel very comfortable with FreeBSD. So I decided to install it in a KVM machine first and search any kind of issue i might run into from my host easily.
I found grub using pkg search:
grub2-efi grub2-pcbsd
And thought maybe this is the traditional grub we have on Linux aswell.
I will look into rEFInd aswell
Is rEFInd needed if I copy loader.efi to a FAT32 partition?
Thanks for your time
 

Attachments

  • Screenshot from 2022-06-03 14-12-24.png
    Screenshot from 2022-06-03 14-12-24.png
    5.3 KB · Views: 23
So should i copy loader.efi to that 1MB partition and thats it?
That should work. Just add the efi system partition to the partition table and copy the loader as explained in the wiki.

I found grub using pkg search:
grub2-efi grub2-pcbsd
I wasn't aware there is a functional GRUB boot loader in ports, since the sysutils/grub2 port has expired and was deleted. Thanks for bringing it to my attention.

You can try sysutils/grub2-pcbsd. In addition install sysutils/grub2-efi, that port provides x86_64-efi boot modules.

And thought maybe this is the traditional grub we have on Linux aswell.
I can't comment on that, never tried it.

I will look into rEFInd aswell
Is rEFInd needed if I copy loader.efi to a FAT32 partition?
No, it's not needed.
 
That should work. Just add the efi system partition to the partition table and copy the loader as explained in the wiki.


I wasn't aware there is a functional GRUB boot loader in ports, since the sysutils/grub2 port has expired and was deleted. Thanks for bringing it to my attention.

You can try sysutils/grub2-pcbsd. In addition install sysutils/grub2-efi, that port provides x86_64-efi boot modules.


I can't comment on that, never tried it.


No, it's not needed.
Thank you for your explanation
I created that EFI partition and moved that file into it
cp /boot/loader.efi /mnt/EFI/BOOT/BOOTX64.efi
And now It can boot using UEFI
 
Top