# Booting a GPT+ESP+UFS system on a BIOS-only machine



## mtu (May 24, 2021)

For reasons too convoluted to go into, I find myself needing to do the following:

Take an SSD with a working 11.4-RELEASE install that uses UEFI/ESP on GPT to boot the system from a UFS partition, and
put that SSD into another machine that does _not_ support UEFI booting (only BIOS), and
boot the 11.4-RELEASE system.
My preferred solution would be to prepare a BIOS-bootable USB stick that could "redirect" the boot process to the system's UFS partition. I'd be willing to type some commands to achieve this, it doesn't need to "boot through" unattended.

Any hints on how to do that?


----------



## Alain De Vos (May 24, 2021)

In fact you only need a /boot filesystem on your USB and tell in loader.conf where to mount root.
Boot0 tells where to find boot1. Boot1 tells where to find the loader. The loader tells where to mount root.


----------



## covacat (May 24, 2021)

if the change is for good you can nuke the esp and convert it to freebsd boot
if its a one time use then do the usb stick. you need to have up to loader and all loader deps on it, change currdev and rootfs and boot


----------



## Alain De Vos (May 24, 2021)

In fact I will try this idea with my PC now and try to make a boot usb.
There are some interesting man pages. 
man gpart
man makefs
man mkimg


----------



## SirDice (May 24, 2021)

How big is that efi ESP partition? You might be able to split it up into a efi and freebsd-boot partition. Then you can "multi" boot between EUFI and CSM. The freebsd-boot partition is 512K with a default install but can be a lot smaller, it only has to fit /boot/gptzfsboot (for ZFS systems) or /boot/gptboot for UFS.


----------



## Emrion (May 24, 2021)

I would make a GPT scheme on the USB stick. Add pmbr as boot code and gptboot to fill the freebsd-boot partition. Then, create an UFS partition with boot.config file. Inside, you can specify where to find the loader.

gptboot()
boot.config(5)

But, I don't know if this will work.


----------



## Alain De Vos (May 24, 2021)

Here what i did and it worked.

```
gpart create -s MBR myusbdisk
gpart add -t freebsd myusbdisk
gpart set -a active -i 1 myusbdisk
gpart bootcode -b /boot/boot0 myusbdisk
gpart create -s BSD -n 20 mypartition
gpart add -t freebsd-ufs mypartition
gpart bootcode -b /boot/boot mypartition
news -O 2 -U -j myslice
mount_the_slice
Copy over your /boot directory
Verify the loader.conf on the destination
```
This works fine.
I tried the same after removing /boot/kernel directory from the USB stick but that did not worked.
I don't know why.
I thought the loader was taking the kernel from the to mount root filesystem but it seems not, or the loader needs a module from the kernel directory ?


----------



## covacat (May 24, 2021)

Alain De Vos said:


> Here what i did and it worked.
> 
> ```
> gpart create -s MBR myusbdisk
> ...


loader does not "understand" kernel device specs as in vfs.root.mountfrom=
you need to play with set currdev before loading modules and kernel


----------



## Alain De Vos (May 24, 2021)

Do you specify currdev in loader.conf , loader.rc or boot.4th ?
Then i can make a super mini boot partition.


----------



## covacat (May 24, 2021)

i assume loader.conf (never tested)


----------



## Alain De Vos (May 24, 2021)

I added to loader.conf

```
currdev="zfs:ZT/ROOT/default:"
```
And the loader took the kernel from the zpool. It worked.
There was no need for a boot.config file on the USB stick.


----------

