|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# https://issues.redhat.com/browse/OCPBUGS-54594 |
| 5 | + |
| 6 | +# This script updates the bootloader using bootupd |
| 7 | +# and also detects RAID-1 setups as those requires |
| 8 | +# extra steps. |
| 9 | +if [ -e /dev/disk/by-label/EFI-SYSTEM ]; then |
| 10 | + echo "Found ESP; calling 'bootupctl update'" |
| 11 | + bootupctl update |
| 12 | + exit |
| 13 | +fi |
| 14 | + |
| 15 | +# Handle RAID case manually since bootupd doesn't support it. |
| 16 | +# https://github.com/coreos/bootupd/issues/132 |
| 17 | +# |
| 18 | +# First we'll find the RAID device the root filesystem is |
| 19 | +# mounted from (i.e. /dev/md127). |
| 20 | +root_raid_device=$(findmnt --json --target /sysroot \ |
| 21 | + | jq -r .filesystems[0].source) |
| 22 | +echo "Detected root raid device is: $root_raid_device" |
| 23 | +# Next we'll find all the devices that are a part of that |
| 24 | +# RAID array that have an ESP (i.e. a vfat formatted partition |
| 25 | +# with a label that starts with "esp-", like "esp-1", "esp-2"). |
| 26 | +# and we'll capture the device name for the partition. |
| 27 | +esp_partitions=$( |
| 28 | + lsblk --paths --fs -J | \ |
| 29 | + jq --arg raid_device "${root_raid_device}" -r ' |
| 30 | + .blockdevices[] |
| 31 | + | select(.children[]?.children[]?.name == $raid_device) |
| 32 | + | .children[] |
| 33 | + | select( |
| 34 | + (.fstype == "vfat") and |
| 35 | + (.label != null) and |
| 36 | + (.label | startswith("esp")) |
| 37 | + ) |
| 38 | + | .name') |
| 39 | +for part in $esp_partitions; do |
| 40 | + echo "Found ESP replica in ${part}; updating" |
| 41 | + mount $part /boot/efi |
| 42 | + echo "[Before Update: ${part}]" |
| 43 | + find /boot/efi/ -type f | xargs md5sum |
| 44 | + cp -rp /usr/lib/bootupd/updates/EFI /boot/efi |
| 45 | + echo "[After Update: ${part}]" |
| 46 | + find /boot/efi/ -type f | xargs md5sum |
| 47 | + umount /boot/efi |
| 48 | +done |
| 49 | +sync |
0 commit comments