How to set up UEFI boot after replacing a drive

I recently had to replace a drive in a zroot pool. I had to dig around to find the correct procedure for setting up the UEFI partition on the new drive so I thought I'd post what I had to do here. I had to piece this together from various forum posts and this blog post.

Code:
# freebsd-version
12.0-RELEASE-p8

Just to be safe, I won't use real device names here. Replace EXISTING and NEW with the proper devices.

This is the layout I'm working with. This was a basic 12.0-RELEASE install.

# gpart show EXISTING
=>         40  15628053088  EXISTING GPT  (7.3T)
           40       409600     1  efi  (200M)
       409640         1024     2  freebsd-boot  (512K)
       410664          984        - free -  (492K)
       411648      4194304     3  freebsd-swap  (2.0G)
      4605952  15623446528     4  freebsd-zfs  (7.3T)
  15628052480          648        - free -  (324K)

First copy the partition table from an existing drive to the new drive (assuming they are identical drives):

# gpart backup EXISTING | gpart restore NEW

Check the partition layout on the new drive to make sure it matches an existing drive:

# gpart show NEW
=>         40  15628053088  NEW GPT  (7.3T)
           40       409600     1  efi  (200M)
       409640         1024     2  freebsd-boot  (512K)
       410664          984        - free -  (492K)
       411648      4194304     3  freebsd-swap  (2.0G)
      4605952  15623446528     4  freebsd-zfs  (7.3T)
  15628052480          648        - free -  (324K)
 
Set up the EFI partition:

# gpart bootcode -p /boot/boot1.efifat -i 1 NEW

NEW should now be formatted as FAT:

# file -s /dev/NEWp1
/dev/NEWp1: DOS/MBR boot sector...
 
You can mount it to be sure:

# mount -t msdosfs /dev/NEWp1 /mnt
# find /mnt
/mnt
/mnt/efi
/mnt/efi/boot
/mnt/efi/boot/BOOTx64.efi
/mnt/efi/boot/startup.nsh
# umount /mnt

Then set up the boot code on the freebsd-boot partition:

# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 NEW

Hope this helps.
 
Back
Top