]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
mkosi-obs: support splitting out and compressing partitions 3780/head
authorLuca Boccassi <luca.boccassi@gmail.com>
Sat, 21 Jun 2025 16:54:48 +0000 (17:54 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 21 Jun 2025 18:16:15 +0000 (19:16 +0100)
Need to recompress the verity-sig partition after creating it,
and deleting the non-compressed split out partitions that are
already present as compressed but that sd-repart re-creates
when doing the signature attach operation.

mkosi/resources/mkosi-obs/mkosi.build
mkosi/resources/mkosi-obs/mkosi.postoutput

index a9d2931394ffc575c3e814b9d3412b9698b3334b..c73366fed38d7ea8c43533db86510fa88a1b29ac 100755 (executable)
@@ -209,12 +209,25 @@ while read -r SIG; do
         cp "/usr/src/packages/SOURCES/$(basename "${SIG%roothash.sig}osrelease")" mkosi.repart/usr/lib/os-release
         ARGS+=(--root="$PWD"/mkosi.repart)
     fi
+
+    if jq -r '.SplitArtifacts[]' "$MKOSI_CONFIG" | grep -q partitions; then
+        # Need to recreate the split artifact and compress it if needed
+        ARGS+=(--split=yes)
+        split=1
+    fi
     systemd-repart "${ARGS[@]}"
     rm -rf mkosi.repart
 
     if ((recompress)); then
         zstd --force "$OUTPUTDIR/$(basename "${SIG%roothash.sig}")"raw*
         rm -f "$OUTPUTDIR/$(basename "${SIG%roothash.sig}raw")" "$OUTPUTDIR/$(basename "${SIG%roothash.sig}raw.img")"
+        if ((split)); then
+            zstd --force "$OUTPUTDIR/$(basename "${SIG%roothash.sig}")"*-verity-sig.*.raw
+            # sd-repart will split out all partitions again
+            rm -f "$OUTPUTDIR/$(basename "${SIG%roothash.sig}")"usr-*.raw \
+                "$OUTPUTDIR/$(basename "${SIG%roothash.sig}")"root-*.raw \
+                "$OUTPUTDIR/$(basename "${SIG%roothash.sig}")"esp.raw
+        fi
     fi
 
     # Do not publish the roothash here, as importctl and friends will mistake it as the roothash of the .raw image
@@ -240,6 +253,10 @@ mapfile -t AUTHVARS < <(find hashes/authvars -type f -name "*.auth")
 if (( ${#AUTHVARS[@]} > 0 )); then
     for ddi in "$OUTPUTDIR"/*.raw*; do
         test -f "$ddi" || continue
+        # Skip over split artifacts, if any
+        [[ "$ddi" =~ \.usr- ]] && continue
+        [[ "$ddi" =~ \.root- ]] && continue
+        [[ "$ddi" =~ -verity ]] && continue
 
         if [[ $ddi == *.zst ]]; then
             unzstd "${ddi}"
index 1693a8a552f57e5b903d358f79c5b414e737e7c5..5e8cb7adedbe4486652c01757671e93e24ec0d26 100755 (executable)
@@ -72,6 +72,11 @@ done
 # Handle bootloaders separately from UKIs
 for ddi in "${DDIS[@]}"; do
     test -f "$ddi" || continue
+    # Skip over split artifacts, if any
+    [[ "$ddi" =~ \.usr- ]] && continue
+    [[ "$ddi" =~ \.root- ]] && continue
+    [[ "$ddi" =~ -verity ]] && continue
+
     if [[ $ddi == *.zst ]]; then
         unzstd "${ddi}"
     fi
@@ -141,12 +146,17 @@ echo "Staging the following files for signing:"
 cpio -t <"$OUTPUTDIR/hashes.cpio.rsasign"
 
 # The second stage will not do a full rebuild, but only attach signatures to the existing UKI
+# Remember whether we need to split out the verity signature partition, as it's generated later
+if jq -r '.SplitArtifacts[]' "$MKOSI_CONFIG" | grep -q partitions; then
+    split="SplitArtifacts=partitions"
+fi
 cat >"$OUTPUTDIR/mkosi.conf" <<EOF
 [Distribution]
 Distribution=custom
 [Output]
 Format=none
 ImageId=$IMAGE_ID
+${split:-}
 [Include]
 Include=mkosi-obs
 [Build]