このページの翻訳:
ソースの表示
最近の変更サイトマップ

Migrate FreeBSD boot method from Legacy/GPT to UEFI/GPT

8 years have already passed since I made a Root on ZFS environemnt with Legacy/GPT boot on FreeBSD 9.0-BETA3. I'm using it until now while upgrading the OS, but the boot environment is no change. I thought it wasn't cool even in 2019 nowdays, so I tried to migrate the boot method to UEF/GPT boot.

This how-to is “as-is” way based on my experiment which tried to manually install the FreeBSD UEFI environment or compare between it and a system built by bsdinstall, so this UEFI environment may not fit into FreeBSD's official UEFI environment.

System

  • FreeBSD 12.0-RELEASE-p4
    • Legacy/GPT/ZFS boot: Way to boot FreeBSD from GPT disk under legacy BIOS with gptzfsboot. It is used by a Root on ZFS environment before UEFI boot.
    • A boot device is ada0.
  • FreeBSD single-boot machine.

Steps

All you need is to make a EPS and put a UEFI boot loader on it.

Create the EFI System Partition

Create the ESP((EFI System Partition) on a boot storage. The boot loader for UEFI will be put there, but securing the partition is the biggest hurdle to do it.

It is okay if the disk has enough space otherwise you have no choice but to replace it with new one. In this case, adding a new disk as ZFS mirror member to the system pool makes it easy to synchronize the data. You managed to create the partition by well thought out, please.

# gpart add -a 4k -t efi -s 200m ada0

The partition size is as you like. FYI, the FreeBSD installer makes as 200MB.

I had a prepared 512MB ESP (ada0p1) in for this occasion, so used it.

> gpart show ada0
=>        34  1099999933  ada0  GPT  (525G)
          34           6        - free -  (3.0K)
          40     1048576     1  efi  (512M)
     1048616        1024     2  freebsd-boot  (512K)
     1049640   251658240     3  freebsd-zfs  (120G)
   252707880     8388608     4  freebsd-zfs  (4.0G)
   261096488     8388608     5  freebsd-zfs  (4.0G)
   269485096     8388608     6  freebsd-zfs  (4.0G)
   277873704   629145600     7  freebsd-zfs  (300G)
   907019304   125829120     8  freebsd-zfs  (60G)
  1032848424    41943040     9  freebsd-zfs  (20G)
  1074791464    25208503        - free -  (12G)

Format the ESP for FAT32.

For 512 bytes per sector devices:
# newfs_msdos -F 32 -S 512 -c 4 ada0p1
/dev/ada0p1: 1044464 sectors in 261116 FAT32 clusters (2048 bytes/cluster)
BytesPerSec=512 SecPerClust=4 ResSectors=32 FATs=2 Media=0xf0 SecPerTrack=63 Heads=16 HiddenSecs=0 HugeSectors=1048576 FATsecs=2040 RootCluster=2 FSInfo=1 Backup=2

For 4096 bytes per sector devices:
# newfs_msdos -F 32 -S 4096 -c 1 ada0p1
/dev/nvd0p1: 130812 sectors in 130812 FAT32 clusters (4096 bytes/cluster)
BytesPerSec=4096 SecPerClust=1 ResSectors=4 FATs=2 Media=0xf0 SecPerTrack=63 Heads=255 HiddenSecs=0 HugeSectors=131072 FATsecs=128 RootCluster=2 FSInfo=1 Backup=2

Put UEFI boot loader

Mount the created ESP.

$ mkdir /tmp/esp
# mount -t msdosfs /dev/ada0p1 /tmp/esp

Make a folder and put a UEFI boot loader on the ESP.

$ mkdir -p /tmp/esp/efi/boot
$ cp /boot/boot1.efi /tmp/esp/efi/boot/BOOTx64.efi

Write a UEFI shell script for boot.

$ echo 'BOOTx64.efi' >> /tmp/esp/efi/boot/startup.nsh

It is okay that a file structure on the ESP looks like below:

$ cd /tmp/esp/
$ find .
.
./efi
./efi/boot
./efi/boot/BOOTx64.efi
./efi/boot/startup.nsh

Surely unmount the ESP.

$ cd
# umount /tmp/esp

Reboot your system.

# reboot

Change a BIOS setting

Change boot method “Legacy” to “UEFI” on your machine BIOS. I think the setting menu or the config name is different with each machine, so please somehow find it out.

Save the config, reboot your system again, then the FreeBSD will boot under the UEFI environment.

It may be success when display shows boot screen with a message “FreeBSD EFI boot block” like above.

en/freebsd/migrate_freebsd_legacy_gpt_boot_to_uefi.txt · 最終更新: 2019-09-25 08:11 by Decomo
CC Attribution-Noncommercial-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0