Skip to content

Commit

Permalink
repartition: Update partitions in EFI load options
Browse files Browse the repository at this point in the history
When the ESP partition ID is regenerated, any EFI load options
referencing the old partition ID become invalid. While shim's fallback
will generate a new load option on the next boot, a downstream patch is
needed to make sure the invalid option is removed.

Rather than having shim cleanup this situation, update the load options
at the time the partition UUID is changed. Since both the old and new
UUIDs are known, eos-update-efi-uuid can update only the affected load
options without changing or deleting load options that aren't affected
by the UUID change.

Note that this runs eos-update-efi-uuid in verbose mode, which is pretty
noisy. When we have confidence this is doing the right thing, we can
drop the -v option.

https://phabricator.endlessm.com/T31604
  • Loading branch information
dbnicholson committed Sep 11, 2024
1 parent 26753f0 commit f2e5767
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions dracut/repartition/endless-repartition.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ else
marker=$(sfdisk --force --part-attrs $root_disk $partno)
fi

# Read the ESP's current UUID so we can update load options below.
orig_esp_uuid=
if [ "$pt_label" = "gpt" ]; then
orig_esp_uuid=$(sfdisk --force --part-uuid $root_disk 1)
fi

case "$marker" in
*GUID:55* | dd)
;;
Expand Down Expand Up @@ -199,6 +205,15 @@ udevadm settle

[ "$ret" != "0" ] && exit 0

# Read the ESP's new UUID and update any invalidated load options.
new_esp_uuid=
if [ "$pt_label" = "gpt" ]; then
new_esp_uuid=$(sfdisk --force --part-uuid $root_disk 1)
fi
if [ -d /sys/firmware/efi ] && [ -n "$orig_esp_uuid" ] && [ -n "$new_esp_uuid" ]; then
eos-update-efi-uuid -v "$orig_esp_uuid" "$new_esp_uuid"
fi

# Loop devices need a prod
if [ -n "$using_loop" ]; then
partx --update --verbose $root_disk
Expand All @@ -214,8 +229,7 @@ udevadm settle
# If we're an sd-booting image we need to fix-up the copy of the
# ESP UUID that sd-boot gave us so systemd mounts the ESP
esp_var=$(echo /sys/firmware/efi/efivars/LoaderDevicePartUUID*)
if [ -f "${esp_var}" ]; then
new_esp_uuid=$(sfdisk $root_disk --part-uuid 1)
if [ -f "${esp_var}" ] && [ -n "${new_esp_uuid}" ]; then
#We need to start with 0x06 0x00 0x00 0x00 and end with 0x00 0x00
#iconv will add the extra 0s
# Shell gotcha - \06\00 works... until ${new_esp_uuid} starts with a decimal digit.
Expand Down
1 change: 1 addition & 0 deletions dracut/repartition/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ depends() {
}

install() {
dracut_install eos-update-efi-uuid
dracut_install sfdisk
dracut_install blockdev
dracut_install readlink
Expand Down

0 comments on commit f2e5767

Please sign in to comment.