]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: Clarify and test that --copy-from= argument respects grain size
authorJonas Dreßler <verdre@v0yd.nl>
Tue, 7 Jul 2026 11:15:36 +0000 (13:15 +0200)
committerJonas Dreßler <verdre@v0yd.nl>
Mon, 13 Jul 2026 10:09:43 +0000 (12:09 +0200)
The --copy-from= argument currently is documented as "copied partitions will have
the same size". This doesn't hold true in the case where a different grain-size is
passed to repart. Because `partition_min/max_size()` currently do rounding, the
size is implicitly rounded to grain size, and therefore partitions are enlarged
to align to grain size whenever possible.

Clarify this behavior and change the manpage, and also add a test for it.

man/systemd-repart.xml
test/units/TEST-58-REPART.sh

index dbf9edad218811d6784b876c65b48826c8a89a64..27e35d19da9c469f8617fa461cfe1780f8b95525 100644 (file)
         <listitem><para>Instructs <command>systemd-repart</command> to synthesize partition definitions from
         the partition table in the given image or device. This option can be specified multiple times to
         synthesize definitions from each of the given images or devices. The generated definitions will copy
-        the partitions into the destination partition table. The copied partitions will have the same size,
-        metadata and contents but might have a different partition number and might be located at a different
-        offset in the destination partition table. These definitions can be combined with partition
-        definitions read from regular partition definition files. The synthesized definitions take precedence
-        over the definitions read from partition definition files.</para>
+        the partitions into the destination partition table. The copied partitions will have the same or a
+        slightly larger size (partitions may be enlarged to align to the new grain or sector size), metadata
+        and contents but might have a different partition number and might be located at a different offset
+        in the destination partition table. These definitions can be combined with partition definitions read
+        from regular partition definition files. The synthesized definitions take precedence over the
+        definitions read from partition definition files.</para>
 
         <xi:include href="version-info.xml" xpointer="v255"/></listitem>
       </varlistentry>
index f5dfd88c4a71d995412900e3bb6912cfdbbbf923..7bd18312df94cf6056bc2193e5e49f6328e381e4 100755 (executable)
@@ -493,6 +493,40 @@ EOF
     assert_in "$imgs/copy_to2 : start=       51200, size=       10240, type=${xbootldr_guid}," "$output"
 }
 
+testcase_copy_from_respects_new_grain() {
+    local defs imgs output
+
+    defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
+    imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
+    # shellcheck disable=SC2064
+    trap "rm -rf '$defs' '$imgs'" RETURN
+    chmod 0755 "$defs"
+
+    truncate -s 80MiB "$imgs/copy_from"
+    sfdisk "$imgs/copy_from" <<EOF
+label: gpt
+
+size=20480, type=${root_guid}, uuid=837c3d67-21b3-478e-be82-7e7f83bf96d3
+size=10240, type=${xbootldr_guid}, uuid=4985c03e-eecb-4fe0-9f65-3f6345782214
+EOF
+
+    truncate -s 100MiB "$imgs/copy_to"
+    output=$(systemd-repart --offline="$OFFLINE" \
+                            --empty=allow \
+                            --definitions="$defs" \
+                            --seed="$seed" \
+                            --dry-run=no \
+                            --json=pretty \
+                            --copy-from="$imgs/copy_from" \
+                            --grain-size=4194304 \
+                            "$imgs/copy_to")
+
+    output=$(sfdisk --dump "$imgs/copy_to")
+
+    assert_in "$imgs/copy_to1 : start=        8192, size=       24576, type=${root_guid}," "$output"
+    assert_in "$imgs/copy_to2 : start=       32768, size=       16384, type=${xbootldr_guid}," "$output"
+}
+
 testcase_dropin() {
     local defs imgs output