Skip to content

Commit

Permalink
kernel-install: Remove existing loader entries and UKIs
Browse files Browse the repository at this point in the history
When boot counting is enabled, adding a new loader entry or UKI can conflict
with an existing one that has booted successfully and therefore has its boot
counter removed. systemd-bless-boot will fail to bless the new successful boot,
since a file without a boot counter already exists. Since kernel-install will
clobber existing files without boot counting, we should therefore remove files
without a boot count as well, when we add a file with one.

Fixes: #33504
(cherry picked from commit 99d4575e541fa1fb00dc80f7aad572f3a66db461)
(cherry picked from commit b78618540659a40c4c26aa588b3cd8b9c46116d1)
  • Loading branch information
behrmann authored and bluca committed Jul 24, 2024
1 parent 0672a43 commit 85ca158
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/kernel-install/90-loaderentry.install.in
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ if [ -f "$TRIES_FILE" ]; then
echo "$TRIES_FILE does not contain an integer." >&2
exit 1
fi
if [ -f "$LOADER_ENTRY" ]; then
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "Removing previous loader entry '$LOADER_ENTRY' without boot counting." >&2
rm -f "$LOADER_ENTRY" "${LOADER_ENTRY%.conf}+"*.conf
fi
LOADER_ENTRY="${LOADER_ENTRY%.conf}+$TRIES.conf"
fi

Expand Down
6 changes: 6 additions & 0 deletions src/kernel-install/90-uki-copy.install
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ if [ -f "$TRIES_FILE" ]; then
echo "$TRIES_FILE does not contain an integer." >&2
exit 1
fi
if [ -f "$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION.efi" ]; then
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "Removing previous UKI '$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION.efi' without boot counting." >&2
rm -f "$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION.efi" "$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION+"*.efi
fi

UKI_FILE="$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION+$TRIES.efi"
else
UKI_FILE="$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION.efi"
Expand Down

0 comments on commit 85ca158

Please sign in to comment.