Create a boot partition

Hi, all!
After replacing the disk in the zfs pool, I created a similar layout.
Please tell me how to correctly create a bootloader in the efi and freebsd-boot partition on the new disk? My OS is FreeBSD 13.5.
Bit-by-bit copying of data from similar mfid4p1 and mfid5p2 partitions? Or is there a special utility for creating a bootloader?
Code:
zpool status
  pool: zroot
 state: DEGRADED
status: One or more devices is currently being resilvered.  The pool will
        continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
  scan: resilver in progress since Sat Jul 19 14:21:19 2025
        11.0T scanned at 1.38G/s, 5.53T issued at 714M/s, 21.7T total
        26.9G resilvered, 25.56% done, 06:34:26 to go
config:

        NAME               STATE     READ WRITE CKSUM
        zroot              DEGRADED     0     0     0
          raidz1-0         ONLINE       0     0     0
            mfid0p4        ONLINE       0     0     0
            mfid1p4        ONLINE       0     0     0
            mfid2p4        ONLINE       0     0     0
          raidz1-1         DEGRADED     0     0     0
            mfid3p4        ONLINE       0     0     0
            mfid4p4        ONLINE       0     0     0
            replacing-2    DEGRADED     0     0     0
              mfid5p4/old  REMOVED      0     0     0
              mfid5p4      ONLINE       0     0     0  (resilvering)
        logs
          mirror-2         ONLINE       0     0     0
            ada0p1         ONLINE       0     0     0
            ada1p1         ONLINE       0     0     0
        cache
          ada0p2           ONLINE       0     0     0
          ada1p2           ONLINE       0     0     0

Code:
sudo gpart show mfid5
=>         40  11721045088  mfid5  GPT  (5.5T)
           40       532480      1  efi  (260M)
       532520         1024      2  freebsd-boot  (512K)
       533544          984         - free -  (492K)
       534528     16777216      3  freebsd-swap  (8.0G)
     17311744  11703732224      4  freebsd-zfs  (5.4T)
  11721043968         1160         - free -  (580K)

sudo gpart show mfid4
=>         40  11721045088  mfid4  GPT  (5.5T)
           40       532480      1  efi  (260M)
       532520         1024      2  freebsd-boot  (512K)
       533544          984         - free -  (492K)
       534528     16777216      3  freebsd-swap  (8.0G)
     17311744  11703732224      4  freebsd-zfs  (5.4T)
  11721043968         1160         - free -  (580K)

Code:
sudo efibootmgr -v
Boot to FW : false
BootCurrent: 0007
Timeout    : 3 seconds
BootOrder  : 0007, 0005, 0000, 0006, 0001, 0004, 0003, 0002
+Boot0007* EFI Embedded MMC Device 2 PciRoot(0x3)/Pci(0x0,0x0)/Pci(0x0,0x0)/Ctrl(0x0)/Scsi(0x4,0x0)/HD(1,GPT,4ea4b472-24a9-11ed-a868-001dc30057e0,0x28,0x82000)
 Boot0005* EFI Embedded MMC Device 1 PciRoot(0x3)/Pci(0x0,0x0)/Pci(0x0,0x0)/Ctrl(0x0)/Scsi(0x3,0x0)/HD(1,GPT,49968da9-24a9-11ed-a868-001dc30057e0,0x28,0x82000)
 Boot0000* EFI Embedded MMC Device PciRoot(0x3)/Pci(0x0,0x0)/Pci(0x0,0x0)/Ctrl(0x0)/Scsi(0x0,0x0)/HD(1,GPT,3ddd16f8-2488-11ed-9877-001dc30057e0,0x28,0x82000)
 Boot0006* FreeBSD HD(1,GPT,3ddd16f8-2488-11ed-9877-001dc30057e0,0x28,0x82000)/File(\efi\freebsd\loader.efi)
                      mfid0p1:/efi/freebsd/loader.efi /boot/efi//efi/freebsd/loader.efi
 Boot0001* Internal EFI Shell MemoryMapped(0xb,0x2ce1e000,0x2e758fff)/FvFile(7c04a583-9e3e-4f1c-ad65-e05268d0b4d1)
 Boot0004* SAMSUNG MZ7L3960HCJR-00A07       BBS(HD,SAMSUNG MZ7L3960HCJR-00A07      ,0x500)
 Boot0003* SAMSUNG MZ7L3960HCJR-00A07       BBS(HD,SAMSUNG MZ7L3960HCJR-00A07      ,0x500)
 Boot0002* (Bus B3 Dev 00)PCI RAID Adapter BBS(HD,(Bus B3 Dev 00)PCI RAID Adapter,0x0)
 
If you're booting from UEFI, don't mind about freebsd-boot.
Basically, if ESP in another drive is sane (i.e., copied in sync from previously working one), formatting the ESP in your new (replaced) drive as another is and simply copy from another one would do.

If you're booting from legacy BIOS mode, forget about ESP.
Use gpart(8) to write /boot/pmbr and /boot/gptzfsboot to PMBR and freebsd-boot respectively.
Looking in your partition layouts and assuming mfid4 is the replaced new drive, maybe gpart bootcode -b /boot/pmbr mfid4 and gpart bootcode -p /boot/gptzfsboot -i 2 mfid4 would do.
 
For UEFI, there isn't. You mount the 'efi' partition with msdos, copy the right files, etc.

But you may need to tell the EFI boot manager inside your device's firmware to use that disk. You can see your old EFI partition in Boot0006. Since you got a new disk, and use gpart to create that and copied the disk partition contents, that's your problem. The boot entires encode the UUID of the device to boot from. efibootmgr hides that, so you should just be able to use (assuming mfid4 is the new one):
```
efibootmgr --create --activate --label "New FreeBSD Disk" --loader /dev/mfd4p1:/efi/freebsd/loader.efi
```
and that will create a new efibootmgr entry that will boot from this other disk. You can then remove the original disk you just copied and it will boot fine.
 
Thanks for the answers. Sorry for my bad English.

Initially, the mfid5 disk failed.
Code:
 zpool status
  pool: zroot
 state: DEGRADED
status: One or more devices has been removed by the administrator.
        Sufficient replicas exist for the pool to continue functioning in a
        degraded state.
action: Online the device using zpool online' or replace the device with
        'zpool replace'.
  scan: scrub repaired 0B in 2 days 07:28:25 with 0 errors on Sun Jul 13 10:46:04 2025
config:

        NAME         STATE     READ WRITE CKSUM
        zroot        DEGRADED     0     0     0
          raidz1-0   ONLINE       0     0     0
            mfid0p4  ONLINE       0     0     0
            mfid1p4  ONLINE       0     0     0
            mfid2p4  ONLINE       0     0     0
          raidz1-1   DEGRADED     0     0     0
            mfid3p4  ONLINE       0     0     0
            mfid4p4  ONLINE       0     0     0
            mfid5p4  REMOVED      0     0     0
        logs
          mirror-2   ONLINE       0     0     0
            ada0p1   ONLINE       0     0     0
            ada1p1   ONLINE       0     0     0
        cache
          ada0p2     ONLINE       0     0     0
          ada1p2     ONLINE       0     0     0
I installed a new drive and created a partition table like on mfid4. Then I ran
Code:
sudo zpool replace zroot mfid5p4
Now the device in the pool is being replaced.
Code:
zpool status
  pool: zroot
 state: DEGRADED
status: One or more devices is currently being resilvered.  The pool will
        continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
  scan: resilver in progress since Sat Jul 19 14:21:19 2025
        11.0T scanned at 674M/s, 7.02T issued at 431M/s, 21.7T total
        537G resilvered, 32.42% done, 09:52:59 to go
config:

        NAME               STATE     READ WRITE CKSUM
        zroot              DEGRADED     0     0     0
          raidz1-0         ONLINE       0     0     0
            mfid0p4        ONLINE       0     0     0
            mfid1p4        ONLINE       0     0     0
            mfid2p4        ONLINE       0     0     0
          raidz1-1         DEGRADED     0     0     0
            mfid3p4        ONLINE       0     0     0
            mfid4p4        ONLINE       0     0     0
            replacing-2    DEGRADED     0     0     0
              mfid5p4/old  REMOVED      0     0     0
              mfid5p4      ONLINE       0     0     0  (resilvering)
        logs
          mirror-2         ONLINE       0     0     0
            ada0p1         ONLINE       0     0     0
            ada1p1         ONLINE       0     0     0
        cache
          ada0p2           ONLINE       0     0     0
          ada1p2           ONLINE       0     0     0

errors: No known data errors

The server uses a UEFI bootloader.
Code:
mount | grep "on / "
zroot/ROOT/default on / (zfs, local, noatime, nfsv4acls)

mount | grep efi
/dev/mfid0p1 on /boot/efi (msdosfs, local)

sudo file -s /dev/mfid0p1
/dev/mfid0p1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "BSD4.4  ", sectors/cluster 32, root entries 512, sectors/FAT 65, sectors/track 63, heads 255, sectors 532480 (volumes > 32 MB), serial number 0xbd9116f1, unlabeled, FAT (16 bit)
 
Please tell me how to correctly create a bootloader in the efi and freebsd-boot partition on the new disk?
The server uses a UEFI bootloader.
If the system is UEFI, then there is no need to copy bootcode into "freebsd-boot", but just in case: gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 mfid5 (see gpart(8) EXAMPLES).

For UEFI, there are different methods to create the efi system partition on the new disk.

If there is already a functional efi partition, the fastest is to use dd(1):
Code:
# dd if=/dev/mfid0p1  of=/dev/mfid5p1   bs=1m
This method can be used to create all “efi” system partitions on all hard drives fast, and also to copy "freebsd-boot" bootcode.

The normal method is to create a MSDOS file system on the partition and copy the FreeBSD efi loader:
Code:
# newfs_msdos  -c 1  -F 32  /dev/mfid5p1
# mount_msdosfs  /dev/mfid5p1   /mnt

# mkdir  -p  /mnt/efi/freebsd
# cp  /boot/loader.efi   /mnt/efi/freebsd

In all examples, make sure to specify the correct target partition .

My OS is FreeBSD 13.5.
In case the system is upgraded, make sure to upgrade loader.efi(8) as well (see EXAMPLES of manual)
 
Back
Top