/* We know up front we're never going to put more than this in a verity sig partition. */
#define VERITY_SIG_SIZE (HARD_MIN_SIZE*4ULL)
-/* libfdisk takes off slightly more than 1M of the disk size when creating a GPT disk label */
-#define GPT_METADATA_SIZE (1044ULL*1024ULL)
-
/* LUKS2 takes off 16M of the partition size with its metadata by default */
#define LUKS2_METADATA_SIZE (16ULL*1024ULL*1024ULL)
assert(c);
- minimal_size = round_up_size(GPT_METADATA_SIZE, 4096);
+ /* At the beginning of the image, some size is reserved for:
+ * Protective MBR (1 block) + GPT header (1 block) +
+ * Primary partition table (minimum 16KiB) = (2 * c->sector_size) + (16 * 1024)
+ *
+ * Note that fdisk usually sets the first usable block to 1MiB (at least for
+ * disks larger than 4MiB), so we just force it to that as well. If fdisk
+ * decides to set it lower, we made the image a bit larger than necessary,
+ * if it sets it higher, we'd have a problem. */
+ minimal_size = 1024 * 1024;
+ /* Of course need to align the start to our grain size as well */
+ minimal_size = round_up_size(minimal_size, c->grain_size);
+
+ /* At the end of the image, there is size reserved for:
+ * Secondary partition table (minimum 16KiB) + GPT header (1 block) */
+ minimal_size += (16 * 1024) + c->sector_size;
if (c->from_scratch)
current_size = 0;
else
- current_size = round_up_size(GPT_METADATA_SIZE, 4096);
+ current_size = minimal_size;
foreign_size = 0;
device: $imgs/zzz
unit: sectors
first-lba: 2048
-last-lba: 6422494
+last-lba: 6422487
$imgs/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=4980595D-D74A-483A-AA9E-9903879A0EE5, name=\"home-first\", attrs=\"GUID:59\"
$imgs/zzz2 : start= 593904, size= 591856, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"
$imgs/zzz3 : start= 1185760, size= 591864, type=${root_guid}, uuid=${root_uuid2}, name=\"root-${architecture}-2\", attrs=\"GUID:59\"
device: $imgs/zzz
unit: sectors
first-lba: 2048
-last-lba: 6553566
+last-lba: 6553559
$imgs/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=4980595D-D74A-483A-AA9E-9903879A0EE5, name=\"home-first\", attrs=\"GUID:59\"
$imgs/zzz2 : start= 593904, size= 591856, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"
$imgs/zzz3 : start= 1185760, size= 591864, type=${root_guid}, uuid=${root_uuid2}, name=\"root-${architecture}-2\", attrs=\"GUID:59\"
assert_in "$imgs/copy_to3 : start= 32768, size= 90072, type=${esp_guid}," "$output"
}
+testcase_size_auto_with_grain_size() {
+ 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"
+
+ tee "$defs/01-esp.conf" <<EOF
+[Partition]
+Type=esp
+SizeMinBytes=10M
+EOF
+
+ tee "$defs/02-usr.conf" <<EOF
+[Partition]
+Type=usr-${architecture}
+SizeMinBytes=10M
+EOF
+
+ tee "$defs/03-root.conf" <<EOF
+[Partition]
+Type=root-${architecture}
+SizeMinBytes=10M
+EOF
+
+ systemd-repart --offline="$OFFLINE" \
+ --empty=create \
+ --size=auto \
+ --definitions="$defs" \
+ --seed="$seed" \
+ --dry-run=no \
+ --grain-size=2097152 \
+ "$imgs/auto"
+
+ output=$(sfdisk --dump "$imgs/auto")
+
+ assert_in "first-lba: 2048" "$output"
+ assert_in "last-lba: 65535" "$output"
+ assert_in "$imgs/auto1 : start= 4096, size= 20480, type=${esp_guid}," "$output"
+ assert_in "$imgs/auto2 : start= 24576, size= 20480, type=${usr_guid}," "$output"
+ assert_in "$imgs/auto3 : start= 45056, size= 20480, type=${root_guid}," "$output"
+}
+
testcase_dropin() {
local defs imgs output