Solved Transfer existing drive from BIOS motherboard to UEFI motherboard

So, currently running FreeBSD 11.2-RELEASE on an HP z800 workstation with a BIOS motherboard. It is kind of a hybrid, in that it supports GPT partitions. I have 2 SSDs in this box, one for the file system on "/" and one for "/home". Both SSDs have GPT partition tables. Considering building a more modern machine which has a UEFI motherboard. I do not dual-boot or anything: FreeBSD is my sole OS. Can I simply take the drives and use them in the new system or is there some partitioning magic I have to do to get it to boot? I am thinking of the "EFI" partition I always read about but not sure if that is only necessary for folks who dual boot with another OS.

If I need to do a reinstall, I can, I'll just save off the relevant customized configs I have. Thanks in advance!
 
Great, so looks like I'll review the motherboard "UEFI" settings whenever I get the machine up and running. Thanks SirDice!
 
If seen some articles how you can "convert" a traditional CSM boot to an UEFI boot. It basically involves removing the freebsd-boot partition and replacing it with an efi partition. But this can be quite tricky and you could end up destroying everything so I won't recommend doing this unless the new machine has no way to do a CSM boot.
 
I don't think it would be that difficult to do if you were running GPT. Assuming partition 1 was the boot partition something like this?

Code:
gpart show (check it is 1)
gpart destroy -i 1 ada0
gpart add -t efi -i 1 ada0
dd if=/boot/boot1.efifat of=/dev/ada0p1

*warning* definitely don't run this without further advice. I don't use UEFI myself and this is completely untested. I'm just pondering how it would be done!

Or

Code:
mount -t msdosfs /dev/ada0p1 /mnt
mkdir -p /mnt/EFI/BOOT
cp /boot/loader.efi /mnt/EFI/BOOT/BOOTX64.efi
umount /mnt

You get the jist. It's something along these lines.
 
Thanks for the feedback - once i build the machine (next couple of months), I'll play with the BIOS/UEFI settings first to see if the current install will boot. If it doesn't, I'll be back ;)
 
First, I have to say that if I 'd have the same issue, I would set the motherboard to start on legacy BIOS as SirDice advised.

But, for the shake of the challenge and because I worked on this subject for another aim, I can say such a conversion is possible (tested).

It's not far from what xtaz proposes but there are some points to correct:

You have to delete the freebsd-boot partition (assuming it's the first, but if it's a default installation, it's actually the first):

gpart delete -i 1 ada0

Then, create an efi partition which must be a msdos file system.

gpart add -t efi ada0
newfs_msdos -F 12 -c 1 /dev/ada0p1


I selected a FAT12 (that belongs to the floppy world!) because there is not enough room to build another FAT system. The default partition freebsd-boot is 512 KB size.

You can now copy /boot/loader.efi:

mount -t msdosfs /dev/ada0p1 /mnt
mkdir -p /mnt/efi/boot
cp /boot/loader.efi /mnt/efi/boot/bootx64.efi
umount /mnt

(Most of these commands comes from: https://wiki.freebsd.org/UEFI)

Luckily, /boot/loader.efi is just 409,6 KB in size (in FreeBSD 11.2) and can fit in the 512 KB previously dedicated to freebsd-boot (but the efi partition should be 1 MB size because of the free space left after freebsd-boot).

At this point, this system can only be started with EFI. If something goes wrong, you can mend it with a live CD.
 
Oh nice, how convenient that I created a 512k freebsd-boot partition as the first on the disk :) Thanks all for the advice!
 
And to be complete, if you have to reverse this change. Boot on the disc1 of your FreeBSD version.

gpart delete -i 1 ada0
gpart add -t freebsd-boot -i 1 -s 512k ada0


It's important to specify a size of 512 KB since freebsd-boot cannot exceed 545 KB (because of design of pmbr program in the protective MBR of the GPT scheme). The following partition, freebsd-swap, is aligned to 1 MB, so there is a space of 1 MB available at the beginning of the scheme (use gpart show to see that).

If your root file system is ZFS:
gpart bootcode -p /boot/gptzfsboot -i 1 ada0

Else if it is UFS:
gpart bootcode -p /boot/gptboot -i 1 ada0

Your system now can only boot under BIOS and not anymore with EFI.
 
Didn't need to do anything to FreeBSD, except a few config changes for network device, changed from nvidia to intel on the video drivers and the sound device. As far as hardware, changed the boot in UEFI/BIOS to legacy and set the boot order of things, booted perfectly. Woohoo!
 
You can now copy /boot/loader.efi:

mount -t msdosfs /dev/ada0p1 /mnt
mkdir -p /mnt/efi/boot
cp /boot/loader.efi /mnt/efi/boot/bootx64.efi
umount /mnt
Shouldn't that be /boot/boot1.efi instead of /boot/loader.efi?
According to the documentation, boot1.efi is supposed to be put into the ESP as BOOTX64.EFI. During the boot process, it will locate the first GPT partition of type freebsd-ufs and load loader.efi from there, which in turn loads and boots the kernel.
 
ollie@ - you are just clarifying a previously posted point, correct? I did not have to make any file system changes to get the system to boot.
 
Shouldn't that be /boot/boot1.efi instead of /boot/loader.efi?
According to the documentation, boot1.efi is supposed to be put into the ESP as BOOTX64.EFI. During the boot process, it will locate the first GPT partition of type freebsd-ufs and load loader.efi from there, which in turn loads and boots the kernel.

Actually, the whole thing may be replaced by:

Code:
gpart add  -t efi -i 1 ada0
gpart bootcode -p /boot/boot1.efifat -i 1 ada0
 
ollie@ - you are just clarifying a previously posted point, correct? I did not have to make any file system changes to get the system to boot.
Well, you mentioned that you enabled the CSM (“legacy boot”), so your system is probably booting in legacy mode, not in UEFI mode.
You can easily verify it by typing these commands as root:
Code:
kldload efirt
efibootmgr -v
If you get an error message saying that EFI variables are not supported, then your system booted via legacy mechanism (called CSM = compatibility support module).
 
OK, when off work, I'll test that - doesn't matter which mode as long as it boots...at least to me anyway, unless I am misunderstanding something.
 
Actually, the whole thing may be replaced by:
Code:
gpart add  -t efi -i 1 ada0
gpart bootcode -p /boot/boot1.efifat -i 1 ada0
That wasn't my point.
There are situations when you can't simply overwrite the whole ESP with boot1.efifat – for example when FreeBSD is not the only OS on your machine, or when you already have other software installed in the ESP, such as an EFI shell. In such situations you have to create and/or modify the ESP manually. And my point was that boot1.efi should be put into the ESP, not loader.efi.

In fact I think it's a rather serious problem that FreeBSD advertises overwriting the ESP, disabling all other operating systems that might already be installed. That's exactly the behavior that was criticized in Windows in older times.
Instead there should be a tool that can modify an existing ESP (and create a new one if necessary) and put boot1.efi in /EFI/FREEBSD by default, only using /EFI/BOOT if either (a) it's not used yet or (b) the user explicitly instructs it to do so. /EFI/BOOT is intended for the fallback boot loader (especially on removable media such as USB sticks), not for regular booting.
 
OK, when off work, I'll test that - doesn't matter which mode as long as it boots...at least to me anyway, unless I am misunderstanding something.
Sure. If your only concern is that the machine boots, then that's ok.
On the other hand: Upon your next upgrade (i.e. new PC or just a new mainboard) in a few years, chances are that the UEFI BIOS does not have a CSM anymore (there are already PCs that don't). So then you'll have to switch to the UEFI boot process finally. But I guess that FreeBSD will then have a tool that can do the switch automatically, so it shouldn't be a problem.
 
OK, when off work, I'll test that - doesn't matter which mode as long as it boots...at least to me anyway, unless I am misunderstanding something.

You can also partition the disk so that you win the ability to boot on to both modes.
Code:
    sysctl kern.geom.part.mbr.enforce_chs=0
    gpart create -s gpt ada0
    gpart add -a 4k -t efi -s 200M -l efiboot0 ada0
    gpart bootcode -p /boot/boot1.efifat -i 1 ada0
    gpart add -a 4k -t freebsd-boot -s 512k -l gptboot0 ada0
    gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 ada0
    gpart set -a active ada0
    gpart show ada0

Follows, swap, UFS and/or ZFS partitions.

Check out the boot method used:
Code:
sysctl -n machdep.bootmethod
 
Shouldn't that be /boot/boot1.efi instead of /boot/loader.efi?
According to the documentation, boot1.efi is supposed to be put into the ESP as BOOTX64.EFI. During the boot process, it will locate the first GPT partition of type freebsd-ufs and load loader.efi from there, which in turn loads and boots the kernel.

It doesn't work with a ZFS system. Maybe it works only with an UFS based system, I can't say for I never used UFS. Conversely, I don't know if /boot/bootx64.efi works with UFS, it's a good question.
 
If seen some articles how you can "convert" a traditional CSM boot to an UEFI boot. It basically involves removing the freebsd-boot partition and replacing it with an efi partition. But this can be quite tricky and you could end up destroying everything so I won't recommend doing this unless the new machine has no way to do a CSM boot.
I agree. The main issue regards the size needed by one efi partition, 100MB by the past and 200MB for the latest installer.

Basically, it relies on the FAT used, which may requires at least 2M(FAT16) to 32M (FAT32).

What is at least more than the 512K reserved by the legacy boot .

Fortunately, when I have had to do this, there was a swap partition just behind the boot one.
 
Basically, it relies on the FAT used, which may requires at least 2M(FAT16) to 32M (FAT32).
But you miss FAT12 I used here with a 1 MB partition (512 of freebsd-boot + 492 KB of free space). And I read an article where this free space beetween freebsd-boot and freebsd-swap was used (so 492 KB) to place a functioning EFI partition. The system can then boot in both EFI and BIOS (nothing more than a normal installation does under EFI but with a legacy BIOS install as a starting place).
 
It doesn't work with a ZFS system. Maybe it works only with an UFS based system, I can't say for I never used UFS. Conversely, I don't know if /boot/bootx64.efi works with UFS, it's a good question.

The FreeBSD installer use the same bootcode for both, UFS and ZFS: boot1.efifat. This one is a wrapper for boot1.efi.

As far as the make target for your system doesn't define MK_ZFS=no, boot1.efi will be compiled with zfs support.
 
It doesn't work with a ZFS system. Maybe it works only with an UFS based system, I can't say for I never used UFS. Conversely, I don't know if /boot/bootx64.efi works with UFS, it's a good question.
boot1.efi supports both UFS and ZFS for quite some time.
Also see the uefi(8) manual page.
 
Back
Top