Last active
June 26, 2024 22:01
-
-
Save grifferz/f262591f59e4f8c199a8b0619bc6a667 to your computer and use it in GitHub Desktop.
Sync EFI System Partition to redundant copy if necessary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Keep two different EFI System Partitions (ESP) in sync, because it's 2021 and | |
# EFI still doesn't support software RAID properly. The idea being to add boot | |
# entries for both: | |
# | |
# $esp1/grubx64.efi | |
# | |
# …and: | |
# | |
# $esp2/grubx64.efi | |
# | |
# …using efibootmgr, and then either can be used to boot from. | |
# | |
# This script is then called after every package update to see if the main ESP | |
# ($esp1) needs to be synced to the secondary one. | |
# | |
# You configure that by making a file like /etc/apt/apt.conf.d/100sync-esps | |
# containing: | |
# | |
# DPkg::Post-Invoke { "/usr/local/sbin/sync-esps.sh"; }; | |
# | |
# That will run it after every time an apt tool (any of them) calls "dpkg". | |
# | |
# Based on script by Sven Hartge: | |
# https://www.mail-archive.com/[email protected]/msg762787.html | |
esp1="/boot/efi/EFI/debian/" | |
esp2="/boot/efi2/EFI/debian/" | |
if [ -d "$esp1" ] && [ -d "$esp2" ]; then | |
if ! diff -rq "$esp1" "$esp2"; then | |
printf "%s differs from %s; syncing…\\n" "$esp1" "$esp2" | |
rsync -rv "$esp1" "$esp2" | |
printf "Done.\\n" | |
exit 0 | |
fi | |
else | |
printf "I don't seem to have both ESPs (%s and %s) mounted\\n" \ | |
"$esp1" "$esp2" | |
printf "Run %s again once you've sorted it out.\\n" "$0" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment