Booting from either disk of a UEFI mirror
Software RAID protects your data, but UEFI firmware cannot read it. A little extra care keeps the boot files on both drives so a disk failure never stops a restart.
Why is UEFI boot a special case on software RAID?
Firmware reads only plain FAT partitions, not md arrays. The boot loader that starts Linux must therefore live on an EFI System Partition (ESP) outside the mirror. If only one drive carries an ESP and that drive fails, the system on the surviving disk is intact but the machine has nothing to boot from. The answer is an ESP on each drive, a firmware entry for each, and a routine that keeps their contents identical.
How do I check the current state?
List the partitions with their types and the firmware boot entries. You want an ESP on every drive, and an entry pointing at each.
lsblk -o NAME,SIZE,PARTTYPENAME,FSTYPE,MOUNTPOINTS | grep -iE 'efi|vfat|NAME' efibootmgr -v findmnt /boot/efi
Our installer creates the ESP on both drives of a mirrored model. Only one is mounted at /boot/efi; the other sits unmounted as the spare copy. The firmware entries show HD(1,GPT,<partuuid>,...); compare those PARTUUIDs with blkid output to see which entry points at which disk.
How do I keep both ESPs in step?
Copy the mounted one to the other whenever the boot loader or kernel changes. A small script does the job; run it by hand after updates or hook it into the package manager so it runs automatically.
#!/bin/sh # /usr/local/sbin/esp-sync set -e SPARE=/dev/disk/by-partuuid/REPLACE-WITH-SPARE-PARTUUID mkdir -p /mnt/esp-spare mount "$SPARE" /mnt/esp-spare rsync -a --delete /boot/efi/ /mnt/esp-spare/ umount /mnt/esp-spare
Using the PARTUUID path rather than /dev/nvme1n1p1 keeps the script correct when device names shift. Make it executable with chmod 700.
How do I make it run after every update?
On Debian and Ubuntu, an apt hook runs after each package operation. On AlmaLinux, Rocky Linux and Fedora, a kernel install plugin runs when kernels are added or removed.
# Debian and Ubuntu: /etc/apt/apt.conf.d/99esp-sync
DPkg::Post-Invoke { "/usr/local/sbin/esp-sync || true"; };
# Enterprise Linux: /etc/kernel/install.d/99-esp-sync.install #!/bin/sh [ "$1" = add ] || [ "$1" = remove ] && /usr/local/sbin/esp-sync exit 0
Also run the script after grub-install, after changing /etc/default/grub and regenerating the configuration, and after any shim or Secure Boot related update.
How do I add a missing firmware entry?
Create one with efibootmgr, naming the disk, the partition number and the loader path on that ESP. Give it a label that says which disk it belongs to.
efibootmgr -c -d /dev/nvme1n1 -p 1 -L "debian (disk 2)" -l '\EFI\debian\shimx64.efi' efibootmgr -o 0003,0004
The second command sets the boot order; use the entry numbers efibootmgr printed. Keep the network boot entry where it was, because rescue boot from the console relies on the machine trying the network first.
Is there an alternative to two separate ESPs?
Yes: a RAID 1 array with metadata version 1.0, which stores its superblock at the end of the partition so firmware sees an ordinary FAT filesystem on each member. It keeps the two copies identical automatically. The catch is that firmware can write to the ESP itself, for example boot variables or capsule updates, without the array knowing, which leaves the mirror out of sync. Separate ESPs with a sync script are more predictable, and that is the layout this guide assumes.
mdadm -C /dev/md/esp -e 1.0 -l 1 -n 2 /dev/sda1 /dev/sdb1
How do I test that both disks can boot?
Change the boot order to try the second disk's entry first and reboot from the console. If the machine comes back, the spare ESP works. Restore the order afterwards. A softer test is efibootmgr -n 0004, which sets a one-time next boot entry, so a failure falls back to the normal order on the following restart.
efibootmgr -n 0004 && systemctl reboot
If neither disk boots, rescue mode from the console lets you mount the arrays, chroot in and reinstall the boot loader to both ESPs. For the broader start-up sequence, see How a dedicated server boots; for replacing a drive and rebuilding its ESP, see Replace a disk in software RAID.
Related pages
How a dedicated server boots
From power on to login prompt: firmware, boot loader, kernel, initramfs and systemd, and how disk boot differs from rescue boot.
Read moreReplace a disk in software RAID
The full command sequence to remove a dead member from an mdadm mirror, partition the new drive, rebuild and restore boot on both disks.
Read moreSoftware RAID with mdadm
Read, create, monitor and tune Linux software RAID arrays with mdadm: status fields, email alerts, scrubs and the write-intent bitmap.
Read moreIPMI and rescue mode
What out-of-band management is, and how console power control, reinstall and rescue boot cover the same needs on our machines.
Read moreQuestions and answers
Why can the EFI partition not be on the RAID mirror?
Firmware reads plain FAT partitions only and cannot assemble software RAID, so each disk needs its own EFI partition.
How do I keep two EFI partitions identical?
Mount the spare by PARTUUID and rsync /boot/efi onto it after boot loader or kernel updates, ideally from a package manager hook.
Will the server boot if the first disk fails?
Yes, when the second disk has a current EFI partition and a firmware entry pointing at it.
Should I mirror the ESP with mdadm metadata 1.0?
It works, but firmware can write to the partition without the array knowing. Separate partitions with a sync script are more predictable.
How do I test booting from the second disk?
Run efibootmgr -n with the second entry number and reboot. The one-time setting falls back to the normal order afterwards.