From 0df5ebc079df9dd0c55d56868ff92c86ebcbd6a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Tue, 7 Jul 2026 13:15:36 +0200 Subject: [PATCH] repart: Clarify and test that --copy-from= argument respects grain size 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 | 11 ++++++----- test/units/TEST-58-REPART.sh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/man/systemd-repart.xml b/man/systemd-repart.xml index dbf9edad21..27e35d19da 100644 --- a/man/systemd-repart.xml +++ b/man/systemd-repart.xml @@ -609,11 +609,12 @@ Instructs systemd-repart 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. + 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. diff --git a/test/units/TEST-58-REPART.sh b/test/units/TEST-58-REPART.sh index f5dfd88c4a..7bd18312df 100755 --- a/test/units/TEST-58-REPART.sh +++ b/test/units/TEST-58-REPART.sh @@ -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" <