Configure grub to automatically install bootcode on all drives

2021-08-29 00:03

TIL the hard way how to configure grub to automatically install bootcode on all drives. Bootcode needs to be present on at least one drive. During package and operating system upgrades, the process of installing/updating bootcode is crucial if you expect the next system boot to be successful.

For software RAID configurations, such as mdadm or zfs, the bootcode must be installed on all 'boot' drives (i.e. drives which contain your / or /boot file systems) to avoid boot failures because

  • the machine randomly decides which disk to boot from
  • the disk with bootcode has been replaced
  • the HBA (host bus adapter) supports only a limited and/or hard coded number or position of drives

Grub provides a way to install bootcode manually. This method is well known and used in most tutorials as well as during Debian system installation:

grub-install /dev/sda
grub-install /dev/sdb

but there is also a way of performing the task automatically (at least on Debian):

dpkg-reconfigure grub-pc

By interactively selecting all boot disks, you lower your chances of boot failure, however, we need to make sure to run the either one of the commands after replacing a disk.

Tags: