diff --git a/crates/lib/src/bootc_composefs/boot.rs b/crates/lib/src/bootc_composefs/boot.rs index 8f1d26d27b..7acd1c9880 100644 --- a/crates/lib/src/bootc_composefs/boot.rs +++ b/crates/lib/src/bootc_composefs/boot.rs @@ -1888,6 +1888,12 @@ fn write_systemd_uki_config( } BootSetupType::Upgrade((_, booted_cfs, ..)) => { + // An earlier staged deployment's entry may have another version in + // its file name, so writing ours wouldn't overwrite it + esp_dir + .remove_all_optional(TYPE1_ENT_PATH_STAGED) + .with_context(|| format!("Removing {TYPE1_ENT_PATH_STAGED}"))?; + esp_dir .create_dir_all(TYPE1_ENT_PATH_STAGED) .with_context(|| format!("Creating {TYPE1_ENT_PATH_STAGED}"))?; diff --git a/tmt/tests/booted/test-composefs-gc-uki.nu b/tmt/tests/booted/test-composefs-gc-uki.nu index 51d4f479b0..150b8212b4 100644 --- a/tmt/tests/booted/test-composefs-gc-uki.nu +++ b/tmt/tests/booted/test-composefs-gc-uki.nu @@ -15,11 +15,42 @@ let booted = $st.status.booted.image let uki_prefix = "bootc_composefs-" let is_uki = (($st.status.booted.composefs.bootType | str downcase) == "uki") +let is_sdboot = (($st.status.booted.composefs.bootloader | str downcase) == "systemd") if not $is_uki { exit 0 } +# Build an image with this VERSION_ID and stage it +def stage_version [version: string] { + let containerfile = $" + FROM localhost/bootc as base + RUN sed -i 's/^VERSION_ID=.*/VERSION_ID=($version)/' /usr/lib/os-release + " + + (tap make_uki_containerfile $containerfile) | podman build -t $"localhost/bootc-($version)" . -f - + + bootc switch --transport containers-storage $"localhost/bootc-($version)" +} + +# A UKI's boot entry has the version from its os-release in its file name, so +# staging an image of another version doesn't overwrite the staged entry. Make +# sure that entry goes away, along with the deployment it belongs to. +def restage_another_version [] { + stage_version "restage1" + let replaced = (bootc status --json | from json).status.staged.composefs.verity + + stage_version "restage2" + + let staged = (glob /var/tmp/efi/loader/entries.staged/*.conf) + assert equal ($staged | length) 2 $"Expected the new and booted entries, found ($staged)" + assert (not ($staged | any { |f| $f | str contains "restage1" })) + + let status = (bootc status --json | from json).status + assert ($status.staged.image.image.image | str ends-with "bootc-restage2") + assert (not ($"/sysroot/state/deploy/($replaced)" | path exists)) +} + # Create a large file in a new container image, then bootc switch to the image def first_boot [] { bootc image copy-to-storage @@ -171,6 +202,10 @@ def fourth_boot [] { let path = cat /var/large-file-marker-objpath assert (not ($path | path exists)) + if $is_sdboot { + restage_another_version + } + tap ok }