]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
kernel-install: handle removal unsuccessful UKIs and loader entries separately
authorJörg Behrmann <behrmann@physik.fu-berlin.de>
Fri, 23 Jan 2026 12:55:51 +0000 (13:55 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 27 Feb 2026 20:05:57 +0000 (20:05 +0000)
When a tries file exists, 90-uki-copy.install removes a previous UKI of the
same kernel version and all it's unbooted variants. This removal is guarded
behind a check for the existence of the already booted UKI, i.e. if uki.efi
already exists, uki.efi and uki+*.efi will be removed.

This leaves the edge case that if uki.efi does not exist, but only an unbooted,
e.g. uki+3.efi, it will not be removed. This is not a problem, if the number of
tries is constant between both builds, since a new uki+3.efi would overwrite
the existing one, but if the number of tries is changed to, e.g. uki+5.efi, we
are left with both uki+3.efi and uki+5.efi.

The same is done for loader entries.

(cherry picked from commit cab4b9defdef1f9f9d3c31b262aed408a6616490)
(cherry picked from commit 1567b00b632d426e50ee6a1cb75d906e2c8035ef)
(cherry picked from commit 583b5ef3d3c5dfa66bd45c0307dbfd85912c339f)

src/kernel-install/90-loaderentry.install.in
src/kernel-install/90-uki-copy.install

index 832a82794cac677d56cb181e292854791446f5d5..c730ba894b8cd84dbc94ce38269965052cf4572e 100755 (executable)
@@ -106,8 +106,14 @@ if [ -f "$TRIES_FILE" ]; then
     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
+        rm -f "$LOADER_ENTRY"
     fi
+    for loaderentry in "${LOADER_ENTRY%.conf}+"*.conf; do
+        [ "$loaderentry" = "${LOADER_ENTRY%.conf}+*.conf" ] && break
+        [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
+            echo "Removing previous loader entry '$loaderentry' that has not yet booted successfully." >&2
+        rm -f "$loaderentry"
+    done
     LOADER_ENTRY="${LOADER_ENTRY%.conf}+$TRIES.conf"
 fi
 
index 04bf5d1752f77462d816db720af0529bddf99959..f48417f85df696b6fa54933b73f8599cd50f4822 100755 (executable)
@@ -65,8 +65,14 @@ if [ -f "$TRIES_FILE" ]; then
     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
+        rm -f "$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION.efi"
     fi
+    for uki in "$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION+"*.efi; do
+        [ "$uki" = "$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION+*.efi" ] && break
+        [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
+            echo "Removing previous UKI '$uki' that has not yet booted successfully." >&2
+        rm -f "$uki"
+    done
 
     UKI_FILE="$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION+$TRIES.efi"
 else