# Bootloading in case of UEFI



## ahev (Mar 22, 2020)

How does FreeBSD boot on a machine that uses UEFI-compatible firmware? The handbook describes how boot0 starts the bootloading process on a machine that uses MBR to indicate partitions, and BIOS firmware. But it is not the case with most modern machines, and with mine too, hence the question.

The way I see it now is there are some efi-related files (like bootx64.efi on x86) shipped together with FreeBSD releases, which need to be put under the FAT/whatever else file system that is used as EFI System Partition, and it kind of has to work since then, but how? The handbook gives a very detailed explanation of how boot0 starts the whole system in case of BIOS/MBR, but I need to study this process in case of UEFI/GPT. Please point me at the source code related to my question, I think that would reside somewhere in stand/ directory in the source tree.


----------



## tingo (Mar 22, 2020)

read the uefi(8) man page.


----------



## ahev (Mar 23, 2020)

tingo said:


> read the uefi(8) man page.


I have done it, I have more specific questions, though.

Can I use the bsdinstall script that is on the installer image on the usb stick in my case - will bsdinstall thus take care of installing FreeBSD in UEFI-compatible way, (not overriding my MBR with boot0 and respecting the GPT partitioning)?

If not, then I need to install FreeBSD manually.

Do I get it right? The firmware will be looking for some specific file, which has .efi extension, in a special place on a drive. When it loads it, it will be grub's starting point of execution (I am going to use grub to boot FreeBSD and other OS I have on the same hard drive). Then grub will take care of transferring execution to either of the loaders that are in the same place (somewhere where .efi files are stored). Grub is configured in Linux by writing a config (my grub2 is installed on Ubuntu - as far as I know, grub2 is installed across the whole drive - part of it in efi-partition, another somewhere else, and part on a Linux filesystem, which is responsible for configuration files) manually or by using a special script - something like grub mkconfig, putting FreeBSD's loader1.efi into the /boot/efi can also be done from Linux, after that the firmware will see the FreeBSD loader?


----------



## tingo (Mar 23, 2020)

bsdinstall - it seem to me that your next task might be to read the man page of bsdinstall, and the script itself.


----------



## ahev (Mar 23, 2020)

tingo said:


> bsdinstall - it seem to me that your next task might be to read the man page of bsdinstall, and the script itself.



May I ask you where can I also read the source code for the installation utility? From what I have read, it seems that bsdinstall is used by some other script or program, as it roughly behaves like this: execute 
	
	



```
bsdinstall $VERB
```
, where $VERB may be whatever we want, or "auto" by default. Reference:

```
VERB="${1:-auto}";
```
 in bsdinstall, line 64.

So there must be some code that actually provides this VERB to it...


----------



## ahev (Mar 23, 2020)

Oh God, I think I understand it now. bsdinstall by default uses auto as VERB, so to see what automated installation would do to my machine (I am interested in this) I would just need to study what bsdinstall auto does. Thanks for putting me in the right direction. I still want to know where I can find the sources of the installer - I mean the gui that is run once I trigger installation by booing from usb stick.


----------

