2021-04-19 15:30:33 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-10-17 16:13:06 +00:00
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
2023-05-22 14:02:43 +00:00
|
|
|
# shellcheck disable=SC2317
|
2021-04-19 15:30:33 +00:00
|
|
|
set -eux
|
2021-04-20 15:07:41 +00:00
|
|
|
set -o pipefail
|
2021-04-19 15:30:33 +00:00
|
|
|
|
2023-05-16 20:41:03 +00:00
|
|
|
# shellcheck source=test/units/util.sh
|
|
|
|
. "$(dirname "$0")"/util.sh
|
2022-11-10 14:40:00 +00:00
|
|
|
|
2023-05-29 10:28:34 +00:00
|
|
|
if ! command -v systemd-repart >/dev/null; then
|
2021-04-21 21:37:57 +00:00
|
|
|
echo "no systemd-repart" >/skipped
|
2024-04-02 18:37:30 +00:00
|
|
|
exit 77
|
2021-04-21 21:37:57 +00:00
|
|
|
fi
|
|
|
|
|
2023-05-22 14:02:43 +00:00
|
|
|
# shellcheck source=test/units/test-control.sh
|
|
|
|
. "$(dirname "$0")"/test-control.sh
|
2023-05-16 17:09:13 +00:00
|
|
|
# shellcheck source=test/units/util.sh
|
|
|
|
. "$(dirname "$0")"/util.sh
|
2022-08-19 07:33:09 +00:00
|
|
|
|
2021-04-19 15:30:33 +00:00
|
|
|
export SYSTEMD_LOG_LEVEL=debug
|
|
|
|
export PAGER=cat
|
|
|
|
|
2022-11-10 16:18:50 +00:00
|
|
|
# Disable use of special glyphs such as →
|
|
|
|
export SYSTEMD_UTF8=0
|
|
|
|
|
2022-08-19 07:33:09 +00:00
|
|
|
seed=750b6cd5c4ae4012a15e7be3c29e6a47
|
|
|
|
|
2022-08-19 19:59:03 +00:00
|
|
|
if ! systemd-detect-virt --quiet --container; then
|
2022-08-26 15:51:28 +00:00
|
|
|
udevadm control --log-level debug
|
2022-08-19 19:59:03 +00:00
|
|
|
fi
|
2022-08-19 19:37:00 +00:00
|
|
|
|
2022-01-12 22:38:22 +00:00
|
|
|
machine="$(uname -m)"
|
|
|
|
if [ "${machine}" = "x86_64" ]; then
|
2022-08-19 07:33:09 +00:00
|
|
|
root_guid=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709
|
2022-01-12 22:38:22 +00:00
|
|
|
root_uuid=60F33797-1D71-4DCB-AA6F-20564F036CD0
|
2022-08-19 19:37:00 +00:00
|
|
|
root_uuid2=73A4CCD2-EAF5-44DA-A366-F99188210FDC
|
2022-08-19 07:33:09 +00:00
|
|
|
usr_guid=8484680C-9521-48C6-9C11-B0720656F69E
|
2022-01-12 22:38:22 +00:00
|
|
|
usr_uuid=7E3369DD-D653-4513-ADF5-B993A9F20C16
|
|
|
|
architecture="x86-64"
|
|
|
|
elif [ "${machine}" = "i386" ] || [ "${machine}" = "i686" ] || [ "${machine}" = "x86" ]; then
|
2022-08-19 07:33:09 +00:00
|
|
|
root_guid=44479540-F297-41B2-9AF7-D131D5F0458A
|
|
|
|
root_uuid=02B4253F-29A4-404E-8972-1669D3B03C87
|
2022-08-19 19:37:00 +00:00
|
|
|
root_uuid2=268E0FD3-B468-4806-A823-E533FE9BB9CC
|
2022-08-19 07:33:09 +00:00
|
|
|
usr_guid=75250D76-8CC6-458E-BD66-BD47CC81A812
|
|
|
|
usr_uuid=7B42FFB0-B0E1-4395-B20B-C78F4A571648
|
2022-01-12 22:38:22 +00:00
|
|
|
architecture="x86"
|
|
|
|
elif [ "${machine}" = "aarch64" ] || [ "${machine}" = "aarch64_be" ] || [ "${machine}" = "armv8b" ] || [ "${machine}" = "armv8l" ]; then
|
2022-08-19 07:33:09 +00:00
|
|
|
root_guid=B921B045-1DF0-41C3-AF44-4C6F280D3FAE
|
|
|
|
root_uuid=055D0227-53A6-4033-85C3-9A5973EFF483
|
2022-08-19 19:37:00 +00:00
|
|
|
root_uuid2=F7DBBE48-8FD0-4833-8411-AA34E7C8E60A
|
2022-08-19 07:33:09 +00:00
|
|
|
usr_guid=B0E01050-EE5F-4390-949A-9101B17104E9
|
|
|
|
usr_uuid=FCE3C75E-D6A4-44C0-87F0-4C105183FB1F
|
2022-01-12 22:38:22 +00:00
|
|
|
architecture="arm64"
|
|
|
|
elif [ "${machine}" = "arm" ]; then
|
2022-08-19 07:33:09 +00:00
|
|
|
root_guid=69DAD710-2CE4-4E3C-B16C-21A1D49ABED3
|
|
|
|
root_uuid=567DA89E-8DE2-4499-8D10-18F212DFF034
|
2022-08-19 19:37:00 +00:00
|
|
|
root_uuid2=813ECFE5-4C89-4193-8A52-437493F2F96E
|
2022-08-19 07:33:09 +00:00
|
|
|
usr_guid=7D0359A3-02B3-4F0A-865C-654403E70625
|
|
|
|
usr_uuid=71E93DC2-5073-42CB-8A84-A354E64D8966
|
2022-01-12 22:38:22 +00:00
|
|
|
architecture="arm"
|
|
|
|
elif [ "${machine}" = "loongarch64" ]; then
|
2022-08-19 07:33:09 +00:00
|
|
|
root_guid=77055800-792C-4F94-B39A-98C91B762BB6
|
|
|
|
root_uuid=D8EFC2D2-0133-41E4-BDCB-3B9F4CFDDDE8
|
2022-08-19 19:37:00 +00:00
|
|
|
root_uuid2=36499F9E-0688-40C1-A746-EA8FD9543C56
|
2022-08-19 07:33:09 +00:00
|
|
|
usr_guid=E611C702-575C-4CBE-9A46-434FA0BF7E3F
|
|
|
|
usr_uuid=031FFA75-00BB-49B6-A70D-911D2D82A5B7
|
2022-01-12 22:38:22 +00:00
|
|
|
architecture="loongarch64"
|
|
|
|
elif [ "${machine}" = "ia64" ]; then
|
2022-08-19 07:33:09 +00:00
|
|
|
root_guid=993D8D3D-F80E-4225-855A-9DAF8ED7EA97
|
|
|
|
root_uuid=DCF33449-0896-4EA9-BC24-7D58AEEF522D
|
2022-08-19 19:37:00 +00:00
|
|
|
root_uuid2=C2A6CAB7-ABEA-4FBA-8C48-CB4C52E6CA38
|
2022-08-19 07:33:09 +00:00
|
|
|
usr_guid=4301D2A6-4E3B-4B2A-BB94-9E0B2C4225EA
|
|
|
|
usr_uuid=BC2BCCE7-80D6-449A-85CC-637424CE5241
|
2022-01-12 22:38:22 +00:00
|
|
|
architecture="ia64"
|
|
|
|
elif [ "${machine}" = "s390x" ]; then
|
2022-08-19 07:33:09 +00:00
|
|
|
root_guid=5EEAD9A9-FE09-4A1E-A1D7-520D00531306
|
|
|
|
root_uuid=7EBE0C85-E27E-48EC-B164-F4807606232E
|
2022-08-19 19:37:00 +00:00
|
|
|
root_uuid2=2A074E1C-2A19-4094-A0C2-24B1A5D52FCB
|
2022-08-19 07:33:09 +00:00
|
|
|
usr_guid=8A4F5770-50AA-4ED3-874A-99B710DB6FEA
|
|
|
|
usr_uuid=51171D30-35CF-4A49-B8B5-9478B9B796A5
|
2022-01-12 22:38:22 +00:00
|
|
|
architecture="s390x"
|
|
|
|
elif [ "${machine}" = "ppc64le" ]; then
|
2022-08-19 07:33:09 +00:00
|
|
|
root_guid=C31C45E6-3F39-412E-80FB-4809C4980599
|
|
|
|
root_uuid=061E67A1-092F-482F-8150-B525D50D6654
|
2022-08-19 19:37:00 +00:00
|
|
|
root_uuid2=A6687CEF-4E4F-44E7-90B3-CDA52EA81739
|
2022-08-19 07:33:09 +00:00
|
|
|
usr_guid=15BB03AF-77E7-4D4A-B12B-C0D084F7491C
|
|
|
|
usr_uuid=C0D0823B-8040-4C7C-A629-026248E297FB
|
2022-01-12 22:38:22 +00:00
|
|
|
architecture="ppc64-le"
|
|
|
|
else
|
2024-05-11 17:17:13 +00:00
|
|
|
echo "Unexpected uname -m: ${machine} in TEST-58-REPART.sh, please fix me"
|
2022-01-12 22:38:22 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-05-22 14:02:43 +00:00
|
|
|
testcase_basic() {
|
2022-08-19 19:37:00 +00:00
|
|
|
local defs imgs output
|
|
|
|
local loop volume
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
|
2023-06-05 13:29:47 +00:00
|
|
|
imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
|
2022-08-19 19:37:00 +00:00
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "rm -rf '$defs' '$imgs'" RETURN
|
2023-08-11 09:30:11 +00:00
|
|
|
chmod 0755 "$defs"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** 1. create an empty image ***"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--empty=create \
|
|
|
|
--size=1G \
|
|
|
|
--seed="$seed" \
|
|
|
|
"$imgs/zzz"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
|
|
|
output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$')
|
|
|
|
|
|
|
|
assert_eq "$output" "label: gpt
|
|
|
|
label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD
|
|
|
|
device: $imgs/zzz
|
|
|
|
unit: sectors
|
|
|
|
first-lba: 2048
|
|
|
|
last-lba: 2097118"
|
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** 2. Testing with root, root2, home, and swap ***"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/root.conf" <<EOF
|
2022-08-19 19:37:00 +00:00
|
|
|
[Partition]
|
|
|
|
Type=root
|
|
|
|
EOF
|
|
|
|
|
|
|
|
ln -s root.conf "$defs/root2.conf"
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/home.conf" <<EOF
|
2022-08-19 19:37:00 +00:00
|
|
|
[Partition]
|
|
|
|
Type=home
|
|
|
|
Label=home-first
|
|
|
|
Label=home-always-too-long-xxxxxxxxxxxxxx-%v
|
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/swap.conf" <<EOF
|
2022-08-19 19:37:00 +00:00
|
|
|
[Partition]
|
|
|
|
Type=swap
|
|
|
|
SizeMaxBytes=64M
|
|
|
|
PaddingMinBytes=92M
|
|
|
|
EOF
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--dry-run=no \
|
|
|
|
--seed="$seed" \
|
|
|
|
--include-partitions=home,swap \
|
|
|
|
--offline="$OFFLINE" \
|
|
|
|
"$imgs/zzz"
|
2022-11-11 13:26:45 +00:00
|
|
|
|
|
|
|
output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$')
|
|
|
|
|
|
|
|
assert_eq "$output" "label: gpt
|
|
|
|
label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD
|
|
|
|
device: $imgs/zzz
|
|
|
|
unit: sectors
|
|
|
|
first-lba: 2048
|
|
|
|
last-lba: 2097118
|
2022-11-22 13:27:30 +00:00
|
|
|
$imgs/zzz1 : start= 2048, size= 1775576, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=4980595D-D74A-483A-AA9E-9903879A0EE5, name=\"home-first\", attrs=\"GUID:59\"
|
|
|
|
$imgs/zzz2 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\""
|
2022-11-11 13:26:45 +00:00
|
|
|
|
2023-08-10 12:41:31 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--empty=create \
|
|
|
|
--size=50M \
|
|
|
|
--seed="$seed" \
|
|
|
|
--include-partitions=root,home \
|
|
|
|
"$imgs/qqq"
|
|
|
|
|
|
|
|
sfdisk -d "$imgs/qqq" | grep -v -e 'sector-size' -e '^$'
|
|
|
|
|
2023-08-01 19:38:39 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--empty=create \
|
|
|
|
--size=1G \
|
|
|
|
--dry-run=no \
|
|
|
|
--seed="$seed" \
|
2023-08-10 12:41:31 +00:00
|
|
|
--definitions "" \
|
|
|
|
--copy-from="$imgs/qqq" \
|
|
|
|
--copy-from="$imgs/qqq" \
|
2023-08-01 19:38:39 +00:00
|
|
|
"$imgs/copy"
|
|
|
|
|
|
|
|
output=$(sfdisk -d "$imgs/copy" | grep -v -e 'sector-size' -e '^$')
|
|
|
|
|
|
|
|
assert_eq "$output" "label: gpt
|
|
|
|
label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD
|
|
|
|
device: $imgs/copy
|
|
|
|
unit: sectors
|
|
|
|
first-lba: 2048
|
|
|
|
last-lba: 2097118
|
2023-08-10 12:41:31 +00:00
|
|
|
$imgs/copy1 : start= 2048, size= 33432, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=4980595D-D74A-483A-AA9E-9903879A0EE5, name=\"home-first\", attrs=\"GUID:59\"
|
2023-08-12 05:53:16 +00:00
|
|
|
$imgs/copy2 : start= 35480, size= 33440, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"
|
|
|
|
$imgs/copy3 : start= 68920, size= 33440, type=${root_guid}, uuid=${root_uuid2}, name=\"root-${architecture}-2\", attrs=\"GUID:59\"
|
2023-08-10 12:41:31 +00:00
|
|
|
$imgs/copy4 : start= 102360, size= 33432, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=4980595D-D74A-483A-AA9E-9903879A0EE5, name=\"home-first\", attrs=\"GUID:59\"
|
2023-08-12 05:53:16 +00:00
|
|
|
$imgs/copy5 : start= 135792, size= 33440, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"
|
|
|
|
$imgs/copy6 : start= 169232, size= 33440, type=${root_guid}, uuid=${root_uuid2}, name=\"root-${architecture}-2\", attrs=\"GUID:59\""
|
2023-08-10 12:41:31 +00:00
|
|
|
|
|
|
|
rm "$imgs/qqq" "$imgs/copy" # Save disk space
|
2023-08-01 19:38:39 +00:00
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--dry-run=no \
|
|
|
|
--seed="$seed" \
|
|
|
|
--empty=force \
|
|
|
|
--defer-partitions=home,root \
|
|
|
|
"$imgs/zzz"
|
2022-11-11 13:26:45 +00:00
|
|
|
|
|
|
|
output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$')
|
|
|
|
|
|
|
|
assert_eq "$output" "label: gpt
|
|
|
|
label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD
|
|
|
|
device: $imgs/zzz
|
|
|
|
unit: sectors
|
|
|
|
first-lba: 2048
|
|
|
|
last-lba: 2097118
|
|
|
|
$imgs/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\""
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--dry-run=no \
|
|
|
|
--seed="$seed" \
|
|
|
|
"$imgs/zzz"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
|
|
|
output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$')
|
|
|
|
|
|
|
|
assert_eq "$output" "label: gpt
|
|
|
|
label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD
|
|
|
|
device: $imgs/zzz
|
|
|
|
unit: sectors
|
|
|
|
first-lba: 2048
|
|
|
|
last-lba: 2097118
|
|
|
|
$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\"
|
|
|
|
$imgs/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\""
|
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** 3. Testing with root, root2, home, swap, and another partition ***"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/swap.conf" <<EOF
|
2022-08-19 19:37:00 +00:00
|
|
|
[Partition]
|
|
|
|
Type=swap
|
|
|
|
SizeMaxBytes=64M
|
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/extra.conf" <<EOF
|
2022-08-19 19:37:00 +00:00
|
|
|
[Partition]
|
|
|
|
Type=linux-generic
|
|
|
|
Label=custom_label
|
|
|
|
UUID=a0a1a2a3a4a5a6a7a8a9aaabacadaeaf
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo "Label=ignored_label" >>"$defs/home.conf"
|
|
|
|
echo "UUID=b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" >>"$defs/home.conf"
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--dry-run=no \
|
|
|
|
--seed="$seed" \
|
|
|
|
"$imgs/zzz"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
|
|
|
output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$')
|
|
|
|
|
|
|
|
assert_eq "$output" "label: gpt
|
|
|
|
label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD
|
|
|
|
device: $imgs/zzz
|
|
|
|
unit: sectors
|
|
|
|
first-lba: 2048
|
|
|
|
last-lba: 2097118
|
|
|
|
$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\"
|
|
|
|
$imgs/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\"
|
|
|
|
$imgs/zzz5 : start= 1908696, size= 188416, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name=\"custom_label\""
|
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** 4. Resizing to 2G ***"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--size=2G \
|
|
|
|
--dry-run=no \
|
|
|
|
--seed="$seed" \
|
|
|
|
"$imgs/zzz"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
|
|
|
output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$')
|
|
|
|
|
|
|
|
assert_eq "$output" "label: gpt
|
|
|
|
label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD
|
|
|
|
device: $imgs/zzz
|
|
|
|
unit: sectors
|
|
|
|
first-lba: 2048
|
|
|
|
last-lba: 4194270
|
|
|
|
$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\"
|
|
|
|
$imgs/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\"
|
|
|
|
$imgs/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name=\"custom_label\""
|
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** 5. Testing with root, root2, home, swap, another partition, and partition copy ***"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
|
|
|
dd if=/dev/urandom of="$imgs/block-copy" bs=4096 count=10240
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/extra2.conf" <<EOF
|
2022-08-19 19:37:00 +00:00
|
|
|
[Partition]
|
|
|
|
Type=linux-generic
|
|
|
|
Label=block-copy
|
|
|
|
UUID=2a1d97e1d0a346cca26eadc643926617
|
|
|
|
CopyBlocks=$imgs/block-copy
|
|
|
|
EOF
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--size=3G \
|
|
|
|
--dry-run=no \
|
|
|
|
--seed="$seed" \
|
|
|
|
"$imgs/zzz"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
|
|
|
output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$')
|
|
|
|
|
|
|
|
assert_eq "$output" "label: gpt
|
|
|
|
label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD
|
|
|
|
device: $imgs/zzz
|
|
|
|
unit: sectors
|
|
|
|
first-lba: 2048
|
|
|
|
last-lba: 6291422
|
|
|
|
$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\"
|
|
|
|
$imgs/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\"
|
|
|
|
$imgs/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name=\"custom_label\"
|
|
|
|
$imgs/zzz6 : start= 4194264, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=2A1D97E1-D0A3-46CC-A26E-ADC643926617, name=\"block-copy\""
|
|
|
|
|
|
|
|
cmp --bytes=$((4096*10240)) --ignore-initial=0:$((512*4194264)) "$imgs/block-copy" "$imgs/zzz"
|
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** 6. Testing Format=/Encrypt=/CopyFiles= ***"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/extra3.conf" <<EOF
|
2022-08-19 19:37:00 +00:00
|
|
|
[Partition]
|
|
|
|
Type=linux-generic
|
|
|
|
Label=luks-format-copy
|
|
|
|
UUID=7b93d1f2-595d-4ce3-b0b9-837fbd9e63b0
|
|
|
|
Format=ext4
|
|
|
|
Encrypt=yes
|
|
|
|
CopyFiles=$defs:/def
|
|
|
|
SizeMinBytes=48M
|
|
|
|
EOF
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--size=auto \
|
|
|
|
--dry-run=no \
|
|
|
|
--seed="$seed" \
|
|
|
|
"$imgs/zzz"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
|
|
|
output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$')
|
|
|
|
|
|
|
|
assert_eq "$output" "label: gpt
|
|
|
|
label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD
|
|
|
|
device: $imgs/zzz
|
|
|
|
unit: sectors
|
|
|
|
first-lba: 2048
|
|
|
|
last-lba: 6389726
|
|
|
|
$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\"
|
|
|
|
$imgs/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\"
|
|
|
|
$imgs/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name=\"custom_label\"
|
|
|
|
$imgs/zzz6 : start= 4194264, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=2A1D97E1-D0A3-46CC-A26E-ADC643926617, name=\"block-copy\"
|
|
|
|
$imgs/zzz7 : start= 6291416, size= 98304, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=7B93D1F2-595D-4CE3-B0B9-837FBD9E63B0, name=\"luks-format-copy\""
|
|
|
|
|
2022-11-10 14:40:00 +00:00
|
|
|
if systemd-detect-virt --quiet --container; then
|
|
|
|
echo "Skipping encrypt mount tests in container."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2022-08-19 19:37:00 +00:00
|
|
|
loop="$(losetup -P --show --find "$imgs/zzz")"
|
2024-05-17 01:12:25 +00:00
|
|
|
udevadm wait --timeout 60 --settle "${loop:?}p7"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
|
|
|
volume="test-repart-$RANDOM"
|
|
|
|
|
|
|
|
touch "$imgs/empty-password"
|
|
|
|
cryptsetup open --type=luks2 --key-file="$imgs/empty-password" "${loop}p7" "$volume"
|
|
|
|
mkdir -p "$imgs/mount"
|
|
|
|
mount -t ext4 "/dev/mapper/$volume" "$imgs/mount"
|
|
|
|
# Use deferred closing on the mapper and autoclear on the loop, so they are cleaned up on umount
|
|
|
|
cryptsetup close --deferred "$volume"
|
|
|
|
losetup -d "$loop"
|
|
|
|
diff -r "$imgs/mount/def" "$defs" >/dev/null
|
|
|
|
umount "$imgs/mount"
|
|
|
|
}
|
|
|
|
|
2023-05-22 14:02:43 +00:00
|
|
|
testcase_dropin() {
|
2022-08-19 19:37:00 +00:00
|
|
|
local defs imgs output
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
|
2023-06-05 13:29:47 +00:00
|
|
|
imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
|
2022-08-19 19:37:00 +00:00
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "rm -rf '$defs' '$imgs'" RETURN
|
2023-08-11 09:30:11 +00:00
|
|
|
chmod 0755 "$defs"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/root.conf" <<EOF
|
2022-08-19 19:37:00 +00:00
|
|
|
[Partition]
|
|
|
|
Type=swap
|
|
|
|
SizeMaxBytes=64M
|
|
|
|
UUID=837c3d67-21b3-478e-be82-7e7f83bf96d3
|
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
mkdir -p "$defs/root.conf.d"
|
|
|
|
tee "$defs/root.conf.d/override1.conf" <<EOF
|
2022-08-19 19:37:00 +00:00
|
|
|
[Partition]
|
|
|
|
Label=label1
|
|
|
|
SizeMaxBytes=32M
|
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/root.conf.d/override2.conf" <<EOF
|
2022-08-19 19:37:00 +00:00
|
|
|
[Partition]
|
|
|
|
Label=label2
|
|
|
|
EOF
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
output=$(systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--empty=create \
|
|
|
|
--size=100M \
|
|
|
|
--json=pretty \
|
|
|
|
"$imgs/zzz")
|
2022-08-19 19:37:00 +00:00
|
|
|
|
2022-11-10 16:18:50 +00:00
|
|
|
diff -u <(echo "$output") - <<EOF
|
2022-08-19 19:37:00 +00:00
|
|
|
[
|
|
|
|
{
|
|
|
|
"type" : "swap",
|
|
|
|
"label" : "label2",
|
|
|
|
"uuid" : "837c3d67-21b3-478e-be82-7e7f83bf96d3",
|
2023-08-23 07:54:38 +00:00
|
|
|
"partno" : 0,
|
2022-12-21 16:06:14 +00:00
|
|
|
"file" : "$defs/root.conf",
|
2022-08-19 19:37:00 +00:00
|
|
|
"node" : "$imgs/zzz1",
|
|
|
|
"offset" : 1048576,
|
|
|
|
"old_size" : 0,
|
|
|
|
"raw_size" : 33554432,
|
2024-05-29 16:07:23 +00:00
|
|
|
"size" : "-> 32M",
|
2022-08-19 19:37:00 +00:00
|
|
|
"old_padding" : 0,
|
|
|
|
"raw_padding" : 0,
|
2022-11-10 16:18:50 +00:00
|
|
|
"padding" : "-> 0B",
|
2022-08-19 19:37:00 +00:00
|
|
|
"activity" : "create",
|
|
|
|
"drop-in_files" : [
|
|
|
|
"$defs/root.conf.d/override1.conf",
|
|
|
|
"$defs/root.conf.d/override2.conf"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2023-05-22 14:02:43 +00:00
|
|
|
testcase_multiple_definitions() {
|
2022-08-19 19:37:00 +00:00
|
|
|
local defs imgs output
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
|
2023-06-05 13:29:47 +00:00
|
|
|
imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
|
2022-08-19 19:37:00 +00:00
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "rm -rf '$defs' '$imgs'" RETURN
|
2023-08-11 09:30:11 +00:00
|
|
|
chmod 0755 "$defs"
|
2022-08-19 19:37:00 +00:00
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
mkdir -p "$defs/1"
|
|
|
|
tee "$defs/1/root1.conf" <<EOF
|
2022-08-19 19:37:00 +00:00
|
|
|
[Partition]
|
|
|
|
Type=swap
|
|
|
|
SizeMaxBytes=32M
|
|
|
|
UUID=7b93d1f2-595d-4ce3-b0b9-837fbd9e63b0
|
|
|
|
Label=label1
|
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
mkdir -p "$defs/2"
|
|
|
|
tee "$defs/2/root2.conf" <<EOF
|
2022-08-19 19:37:00 +00:00
|
|
|
[Partition]
|
|
|
|
Type=swap
|
|
|
|
SizeMaxBytes=32M
|
|
|
|
UUID=837c3d67-21b3-478e-be82-7e7f83bf96d3
|
|
|
|
Label=label2
|
|
|
|
EOF
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
output=$(systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs/1" \
|
|
|
|
--definitions="$defs/2" \
|
|
|
|
--empty=create \
|
|
|
|
--size=100M \
|
|
|
|
--json=pretty \
|
|
|
|
"$imgs/zzz")
|
2022-08-19 19:37:00 +00:00
|
|
|
|
2022-11-10 16:18:50 +00:00
|
|
|
diff -u <(echo "$output") - <<EOF
|
2022-08-19 19:37:00 +00:00
|
|
|
[
|
|
|
|
{
|
|
|
|
"type" : "swap",
|
|
|
|
"label" : "label1",
|
|
|
|
"uuid" : "7b93d1f2-595d-4ce3-b0b9-837fbd9e63b0",
|
2023-08-23 07:54:38 +00:00
|
|
|
"partno" : 0,
|
2022-12-21 16:06:14 +00:00
|
|
|
"file" : "$defs/1/root1.conf",
|
2022-08-19 19:37:00 +00:00
|
|
|
"node" : "$imgs/zzz1",
|
|
|
|
"offset" : 1048576,
|
|
|
|
"old_size" : 0,
|
|
|
|
"raw_size" : 33554432,
|
2024-05-29 16:07:23 +00:00
|
|
|
"size" : "-> 32M",
|
2022-08-19 19:37:00 +00:00
|
|
|
"old_padding" : 0,
|
|
|
|
"raw_padding" : 0,
|
2022-11-10 16:18:50 +00:00
|
|
|
"padding" : "-> 0B",
|
2022-08-19 19:37:00 +00:00
|
|
|
"activity" : "create"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type" : "swap",
|
|
|
|
"label" : "label2",
|
|
|
|
"uuid" : "837c3d67-21b3-478e-be82-7e7f83bf96d3",
|
2023-08-23 07:54:38 +00:00
|
|
|
"partno" : 1,
|
2022-12-21 16:06:14 +00:00
|
|
|
"file" : "$defs/2/root2.conf",
|
2022-08-19 19:37:00 +00:00
|
|
|
"node" : "$imgs/zzz2",
|
|
|
|
"offset" : 34603008,
|
|
|
|
"old_size" : 0,
|
|
|
|
"raw_size" : 33554432,
|
2024-05-29 16:07:23 +00:00
|
|
|
"size" : "-> 32M",
|
2022-08-19 19:37:00 +00:00
|
|
|
"old_padding" : 0,
|
|
|
|
"raw_padding" : 0,
|
2022-11-10 16:18:50 +00:00
|
|
|
"padding" : "-> 0B",
|
2022-08-19 19:37:00 +00:00
|
|
|
"activity" : "create"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2023-05-22 14:02:43 +00:00
|
|
|
testcase_copy_blocks() {
|
2022-08-19 07:33:09 +00:00
|
|
|
local defs imgs output
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
|
2023-06-05 13:29:47 +00:00
|
|
|
imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
|
2022-08-19 07:33:09 +00:00
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "rm -rf '$defs' '$imgs'" RETURN
|
2023-08-11 09:30:11 +00:00
|
|
|
chmod 0755 "$defs"
|
2021-04-19 15:30:33 +00:00
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** First, create a disk image and verify its in order ***"
|
2021-04-19 15:30:33 +00:00
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/esp.conf" <<EOF
|
2021-04-19 15:30:33 +00:00
|
|
|
[Partition]
|
|
|
|
Type=esp
|
|
|
|
SizeMinBytes=10M
|
|
|
|
Format=vfat
|
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/usr.conf" <<EOF
|
2021-04-19 15:30:33 +00:00
|
|
|
[Partition]
|
2022-01-12 22:38:22 +00:00
|
|
|
Type=usr-${architecture}
|
2021-04-19 15:30:33 +00:00
|
|
|
SizeMinBytes=10M
|
|
|
|
Format=ext4
|
|
|
|
ReadOnly=yes
|
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/root.conf" <<EOF
|
2021-04-19 15:30:33 +00:00
|
|
|
[Partition]
|
2022-01-12 22:38:22 +00:00
|
|
|
Type=root-${architecture}
|
2021-04-19 15:30:33 +00:00
|
|
|
SizeMinBytes=10M
|
|
|
|
Format=ext4
|
|
|
|
MakeDirectories=/usr /efi
|
|
|
|
EOF
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--empty=create \
|
|
|
|
--size=auto \
|
|
|
|
--seed="$seed" \
|
|
|
|
"$imgs/zzz"
|
2021-04-19 15:30:33 +00:00
|
|
|
|
2022-08-19 07:33:09 +00:00
|
|
|
output=$(sfdisk --dump "$imgs/zzz")
|
2021-04-19 15:30:33 +00:00
|
|
|
|
2022-08-19 07:33:09 +00:00
|
|
|
assert_in "$imgs/zzz1 : start= 2048, size= 20480, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=39107B09-615D-48FB-BA37-C663885FCE67, name=\"esp\"" "$output"
|
|
|
|
assert_in "$imgs/zzz2 : start= 22528, size= 20480, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"" "$output"
|
|
|
|
assert_in "$imgs/zzz3 : start= 43008, size= 20480, type=${usr_guid}, uuid=${usr_uuid}, name=\"usr-${architecture}\", attrs=\"GUID:60\"" "$output"
|
2021-04-19 15:30:33 +00:00
|
|
|
|
2022-11-10 14:40:00 +00:00
|
|
|
if systemd-detect-virt --quiet --container; then
|
|
|
|
echo "Skipping second part of copy blocks tests in container."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** Second, create another image with CopyBlocks=auto ***"
|
2021-04-19 15:30:33 +00:00
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/esp.conf" <<EOF
|
2021-04-19 15:30:33 +00:00
|
|
|
[Partition]
|
|
|
|
Type=esp
|
|
|
|
CopyBlocks=auto
|
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/usr.conf" <<EOF
|
2021-04-19 15:30:33 +00:00
|
|
|
[Partition]
|
2022-01-12 22:38:22 +00:00
|
|
|
Type=usr-${architecture}
|
2021-04-19 15:30:33 +00:00
|
|
|
ReadOnly=yes
|
|
|
|
CopyBlocks=auto
|
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/root.conf" <<EOF
|
2021-04-19 15:30:33 +00:00
|
|
|
[Partition]
|
2022-01-12 22:38:22 +00:00
|
|
|
Type=root-${architecture}
|
2021-04-19 15:30:33 +00:00
|
|
|
CopyBlocks=auto
|
|
|
|
EOF
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
2022-08-19 07:33:09 +00:00
|
|
|
--empty=create \
|
|
|
|
--size=auto \
|
|
|
|
--seed="$seed" \
|
|
|
|
--image="$imgs/zzz" \
|
|
|
|
"$imgs/yyy"
|
2021-04-19 15:30:33 +00:00
|
|
|
|
2022-08-19 07:33:09 +00:00
|
|
|
cmp "$imgs/zzz" "$imgs/yyy"
|
|
|
|
}
|
2021-04-19 15:30:33 +00:00
|
|
|
|
2023-05-22 14:02:43 +00:00
|
|
|
testcase_unaligned_partition() {
|
2022-08-19 07:33:09 +00:00
|
|
|
local defs imgs output
|
2021-04-19 15:30:33 +00:00
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
|
2023-06-05 13:29:47 +00:00
|
|
|
imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
|
2022-08-19 07:33:09 +00:00
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "rm -rf '$defs' '$imgs'" RETURN
|
2023-08-11 09:30:11 +00:00
|
|
|
chmod 0755 "$defs"
|
2021-11-09 15:53:11 +00:00
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** Operate on an image with unaligned partition ***"
|
2021-11-09 15:53:11 +00:00
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/root.conf" <<EOF
|
2021-11-09 15:53:11 +00:00
|
|
|
[Partition]
|
2022-01-12 22:38:22 +00:00
|
|
|
Type=root-${architecture}
|
2021-11-09 15:53:11 +00:00
|
|
|
EOF
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
truncate -s 10g "$imgs/unaligned"
|
2022-08-19 07:33:09 +00:00
|
|
|
sfdisk "$imgs/unaligned" <<EOF
|
2021-11-09 15:53:11 +00:00
|
|
|
label: gpt
|
|
|
|
|
|
|
|
start=2048, size=69044
|
|
|
|
start=71092, size=3591848
|
|
|
|
EOF
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--seed="$seed" \
|
|
|
|
--dry-run=no \
|
|
|
|
"$imgs/unaligned"
|
2022-08-19 07:33:09 +00:00
|
|
|
|
|
|
|
output=$(sfdisk --dump "$imgs/unaligned")
|
2021-11-09 15:53:11 +00:00
|
|
|
|
2022-08-19 07:33:09 +00:00
|
|
|
assert_in "$imgs/unaligned1 : start= 2048, size= 69044," "$output"
|
|
|
|
assert_in "$imgs/unaligned2 : start= 71092, size= 3591848," "$output"
|
|
|
|
assert_in "$imgs/unaligned3 : start= 3662944, size= 17308536, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"" "$output"
|
|
|
|
}
|
|
|
|
|
2023-05-22 14:02:43 +00:00
|
|
|
testcase_issue_21817() {
|
2022-08-19 07:33:09 +00:00
|
|
|
local defs imgs output
|
2021-11-09 15:53:11 +00:00
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
|
2023-06-05 13:29:47 +00:00
|
|
|
imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
|
2022-08-19 07:33:09 +00:00
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "rm -rf '$defs' '$imgs'" RETURN
|
2023-08-11 09:30:11 +00:00
|
|
|
chmod 0755 "$defs"
|
2021-11-09 15:53:11 +00:00
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** testcase for #21817 ***"
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/test.conf" <<EOF
|
2022-08-19 07:33:09 +00:00
|
|
|
[Partition]
|
|
|
|
Type=root
|
|
|
|
EOF
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
truncate -s 100m "$imgs/21817.img"
|
2022-08-19 07:33:09 +00:00
|
|
|
sfdisk "$imgs/21817.img" <<EOF
|
2022-04-06 16:39:20 +00:00
|
|
|
label: gpt
|
|
|
|
|
|
|
|
size=50M, type=${root_guid}
|
|
|
|
,
|
|
|
|
EOF
|
2021-12-20 14:47:52 +00:00
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--pretty=yes \
|
|
|
|
--definitions "$imgs" \
|
|
|
|
--seed="$seed" \
|
|
|
|
--dry-run=no \
|
|
|
|
"$imgs/21817.img"
|
2021-12-20 14:47:52 +00:00
|
|
|
|
2022-08-19 07:33:09 +00:00
|
|
|
output=$(sfdisk --dump "$imgs/21817.img")
|
2021-12-20 14:47:52 +00:00
|
|
|
|
2022-08-19 07:33:09 +00:00
|
|
|
assert_in "$imgs/21817.img1 : start= 2048, size= 102400, type=${root_guid}," "$output"
|
|
|
|
# Accept both unpadded (pre-v2.38 util-linux) and padded (v2.38+ util-linux) sizes
|
|
|
|
assert_in "$imgs/21817.img2 : start= 104448, size= (100319| 98304)," "$output"
|
|
|
|
}
|
2022-02-07 13:35:40 +00:00
|
|
|
|
2023-05-22 14:02:43 +00:00
|
|
|
testcase_issue_24553() {
|
2022-09-05 13:11:55 +00:00
|
|
|
local defs imgs output
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
|
2023-06-05 13:29:47 +00:00
|
|
|
imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
|
2022-09-05 13:11:55 +00:00
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "rm -rf '$defs' '$imgs'" RETURN
|
2023-08-11 09:30:11 +00:00
|
|
|
chmod 0755 "$defs"
|
2022-09-05 13:11:55 +00:00
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** testcase for #24553 ***"
|
2022-09-05 13:11:55 +00:00
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/root.conf" <<EOF
|
2022-09-05 13:11:55 +00:00
|
|
|
[Partition]
|
|
|
|
Type=root
|
|
|
|
SizeMinBytes=10G
|
|
|
|
SizeMaxBytes=120G
|
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$imgs/partscript" <<EOF
|
2022-09-05 13:11:55 +00:00
|
|
|
label: gpt
|
|
|
|
label-id: C9FFE979-A415-C449-B729-78C7AA664B10
|
|
|
|
unit: sectors
|
|
|
|
first-lba: 40
|
|
|
|
|
|
|
|
start=40, size=524288, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=F2E89C8A-DC5D-4C4C-A29C-6CFB643B74FD, name="ESP System Partition"
|
|
|
|
start=524328, size=14848000, type=${root_guid}, uuid=${root_uuid}, name="root-${architecture}"
|
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** 1. Operate on a small image compared with SizeMinBytes= ***"
|
2023-06-05 13:29:47 +00:00
|
|
|
truncate -s 8g "$imgs/zzz"
|
2022-09-05 13:11:55 +00:00
|
|
|
sfdisk "$imgs/zzz" <"$imgs/partscript"
|
|
|
|
|
|
|
|
# This should fail, but not trigger assertions.
|
2023-06-05 13:29:47 +00:00
|
|
|
assert_rc 1 systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--seed="$seed" \
|
|
|
|
--dry-run=no \
|
|
|
|
"$imgs/zzz"
|
2022-09-05 13:11:55 +00:00
|
|
|
|
|
|
|
output=$(sfdisk --dump "$imgs/zzz")
|
|
|
|
assert_in "$imgs/zzz2 : start= 524328, size= 14848000, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\"" "$output"
|
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** 2. Operate on an larger image compared with SizeMinBytes= ***"
|
2022-09-05 13:11:55 +00:00
|
|
|
rm -f "$imgs/zzz"
|
2023-06-05 13:29:47 +00:00
|
|
|
truncate -s 12g "$imgs/zzz"
|
2022-09-05 13:11:55 +00:00
|
|
|
sfdisk "$imgs/zzz" <"$imgs/partscript"
|
|
|
|
|
|
|
|
# This should succeed.
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--seed="$seed" \
|
|
|
|
--dry-run=no \
|
|
|
|
"$imgs/zzz"
|
2022-09-05 13:11:55 +00:00
|
|
|
|
|
|
|
output=$(sfdisk --dump "$imgs/zzz")
|
|
|
|
assert_in "$imgs/zzz2 : start= 524328, size= 24641456, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\"" "$output"
|
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** 3. Multiple partitions with Priority= (small disk) ***"
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/root.conf" <<EOF
|
2022-09-05 13:11:55 +00:00
|
|
|
[Partition]
|
|
|
|
Type=root
|
|
|
|
SizeMinBytes=10G
|
|
|
|
SizeMaxBytes=120G
|
|
|
|
Priority=100
|
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/usr.conf" <<EOF
|
2022-09-05 13:11:55 +00:00
|
|
|
[Partition]
|
|
|
|
Type=usr
|
|
|
|
SizeMinBytes=10M
|
|
|
|
Priority=10
|
|
|
|
EOF
|
|
|
|
|
|
|
|
rm -f "$imgs/zzz"
|
2023-06-05 13:29:47 +00:00
|
|
|
truncate -s 8g "$imgs/zzz"
|
2022-09-05 13:11:55 +00:00
|
|
|
sfdisk "$imgs/zzz" <"$imgs/partscript"
|
|
|
|
|
|
|
|
# This should also succeed, but root is not extended.
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--seed="$seed" \
|
|
|
|
--dry-run=no \
|
|
|
|
"$imgs/zzz"
|
2022-09-05 13:11:55 +00:00
|
|
|
|
|
|
|
output=$(sfdisk --dump "$imgs/zzz")
|
|
|
|
assert_in "$imgs/zzz2 : start= 524328, size= 14848000, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\"" "$output"
|
|
|
|
assert_in "$imgs/zzz3 : start= 15372328, size= 1404848, type=${usr_guid}, uuid=${usr_uuid}, name=\"usr-${architecture}\", attrs=\"GUID:59\"" "$output"
|
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** 4. Multiple partitions with Priority= (large disk) ***"
|
2022-09-05 13:11:55 +00:00
|
|
|
rm -f "$imgs/zzz"
|
2023-06-05 13:29:47 +00:00
|
|
|
truncate -s 12g "$imgs/zzz"
|
2022-09-05 13:11:55 +00:00
|
|
|
sfdisk "$imgs/zzz" <"$imgs/partscript"
|
|
|
|
|
|
|
|
# This should also succeed, and root is extended.
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--seed="$seed" \
|
|
|
|
--dry-run=no \
|
|
|
|
"$imgs/zzz"
|
2022-09-05 13:11:55 +00:00
|
|
|
|
|
|
|
output=$(sfdisk --dump "$imgs/zzz")
|
|
|
|
assert_in "$imgs/zzz2 : start= 524328, size= 20971520, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\"" "$output"
|
|
|
|
assert_in "$imgs/zzz3 : start= 21495848, size= 3669936, type=${usr_guid}, uuid=${usr_uuid}, name=\"usr-${architecture}\", attrs=\"GUID:59\"" "$output"
|
|
|
|
}
|
|
|
|
|
2023-05-22 14:02:43 +00:00
|
|
|
testcase_zero_uuid() {
|
2022-09-04 16:53:25 +00:00
|
|
|
local defs imgs output
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
|
2023-06-05 13:29:47 +00:00
|
|
|
imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
|
2022-09-04 16:53:25 +00:00
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "rm -rf '$defs' '$imgs'" RETURN
|
2023-08-11 09:30:11 +00:00
|
|
|
chmod 0755 "$defs"
|
2022-09-04 16:53:25 +00:00
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** Test image with zero UUID ***"
|
2022-09-04 16:53:25 +00:00
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/root.conf" <<EOF
|
2022-09-04 16:53:25 +00:00
|
|
|
[Partition]
|
|
|
|
Type=root-${architecture}
|
|
|
|
UUID=null
|
|
|
|
EOF
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--seed="$seed" \
|
|
|
|
--dry-run=no \
|
|
|
|
--empty=create \
|
|
|
|
--size=auto \
|
|
|
|
"$imgs/zero"
|
2022-09-04 16:53:25 +00:00
|
|
|
|
|
|
|
output=$(sfdisk --dump "$imgs/zero")
|
|
|
|
|
|
|
|
assert_in "$imgs/zero1 : start= 2048, size= 20480, type=${root_guid}, uuid=00000000-0000-0000-0000-000000000000" "$output"
|
|
|
|
}
|
|
|
|
|
2023-05-22 14:02:43 +00:00
|
|
|
testcase_verity() {
|
2022-09-05 22:45:32 +00:00
|
|
|
local defs imgs output
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
|
2023-06-05 13:29:47 +00:00
|
|
|
imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
|
2022-09-05 22:45:32 +00:00
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "rm -rf '$defs' '$imgs'" RETURN
|
2023-08-11 09:30:11 +00:00
|
|
|
chmod 0755 "$defs"
|
2022-09-05 22:45:32 +00:00
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** dm-verity ***"
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/verity-data.conf" <<EOF
|
2022-09-05 22:45:32 +00:00
|
|
|
[Partition]
|
|
|
|
Type=root-${architecture}
|
|
|
|
CopyFiles=${defs}
|
|
|
|
Verity=data
|
|
|
|
VerityMatchKey=root
|
2023-04-26 09:52:54 +00:00
|
|
|
Minimize=guess
|
2022-09-05 22:45:32 +00:00
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/verity-hash.conf" <<EOF
|
2022-09-05 22:45:32 +00:00
|
|
|
[Partition]
|
|
|
|
Type=root-${architecture}-verity
|
|
|
|
Verity=hash
|
|
|
|
VerityMatchKey=root
|
2023-04-26 09:52:54 +00:00
|
|
|
Minimize=yes
|
2022-09-05 22:45:32 +00:00
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/verity-sig.conf" <<EOF
|
2022-09-11 08:49:24 +00:00
|
|
|
[Partition]
|
|
|
|
Type=root-${architecture}-verity-sig
|
|
|
|
Verity=signature
|
|
|
|
VerityMatchKey=root
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Unfortunately OpenSSL insists on reading some config file, hence provide one with mostly placeholder contents
|
2023-05-29 18:52:33 +00:00
|
|
|
tee >"$defs/verity.openssl.cnf" <<EOF
|
2022-09-11 08:49:24 +00:00
|
|
|
[ req ]
|
|
|
|
prompt = no
|
|
|
|
distinguished_name = req_distinguished_name
|
|
|
|
|
|
|
|
[ req_distinguished_name ]
|
|
|
|
C = DE
|
|
|
|
ST = Test State
|
|
|
|
L = Test Locality
|
|
|
|
O = Org Name
|
|
|
|
OU = Org Unit Name
|
|
|
|
CN = Common Name
|
|
|
|
emailAddress = test@email.com
|
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
openssl req \
|
|
|
|
-config "$defs/verity.openssl.cnf" \
|
|
|
|
-new -x509 \
|
|
|
|
-newkey rsa:1024 \
|
|
|
|
-keyout "$defs/verity.key" \
|
|
|
|
-out "$defs/verity.crt" \
|
|
|
|
-days 365 \
|
|
|
|
-nodes
|
2022-09-11 08:49:24 +00:00
|
|
|
|
|
|
|
mkdir -p /run/verity.d
|
2023-06-05 13:29:47 +00:00
|
|
|
ln -sf "$defs/verity.crt" /run/verity.d/ok.crt
|
|
|
|
|
|
|
|
output=$(systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--seed="$seed" \
|
|
|
|
--dry-run=no \
|
|
|
|
--empty=create \
|
|
|
|
--size=auto \
|
|
|
|
--json=pretty \
|
|
|
|
--private-key="$defs/verity.key" \
|
|
|
|
--certificate="$defs/verity.crt" \
|
|
|
|
"$imgs/verity")
|
2022-09-05 22:45:32 +00:00
|
|
|
|
2023-05-29 18:54:44 +00:00
|
|
|
drh=$(jq -r ".[] | select(.type == \"root-${architecture}\") | .roothash" <<<"$output")
|
|
|
|
hrh=$(jq -r ".[] | select(.type == \"root-${architecture}-verity\") | .roothash" <<<"$output")
|
|
|
|
srh=$(jq -r ".[] | select(.type == \"root-${architecture}-verity-sig\") | .roothash" <<<"$output")
|
2023-01-25 14:56:30 +00:00
|
|
|
|
|
|
|
assert_eq "$drh" "$hrh"
|
|
|
|
assert_eq "$hrh" "$srh"
|
2022-09-05 22:45:32 +00:00
|
|
|
|
2022-11-10 16:33:31 +00:00
|
|
|
# Check that we can dissect, mount and unmount a repart verity image. (and that the image UUID is deterministic)
|
2022-09-05 22:45:32 +00:00
|
|
|
|
2022-11-10 14:40:00 +00:00
|
|
|
if systemd-detect-virt --quiet --container; then
|
|
|
|
echo "Skipping verity test dissect part in container."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2023-01-25 14:56:30 +00:00
|
|
|
systemd-dissect "$imgs/verity" --root-hash "$drh"
|
|
|
|
systemd-dissect "$imgs/verity" --root-hash "$drh" --json=short | grep -q '"imageUuid":"1d2ce291-7cce-4f7d-bc83-fdb49ad74ebd"'
|
|
|
|
systemd-dissect "$imgs/verity" --root-hash "$drh" -M "$imgs/mnt"
|
2022-09-05 22:45:32 +00:00
|
|
|
systemd-dissect -U "$imgs/mnt"
|
|
|
|
}
|
|
|
|
|
2023-08-11 09:30:11 +00:00
|
|
|
testcase_verity_explicit_block_size() {
|
|
|
|
local defs imgs loop
|
|
|
|
|
|
|
|
if systemd-detect-virt --quiet --container; then
|
|
|
|
echo "Skipping verity block size tests in container."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
echo "*** varying-dm-verity-block-sizes ***"
|
|
|
|
|
|
|
|
tee "$defs/verity-data.conf" <<EOF
|
|
|
|
[Partition]
|
|
|
|
Type=root-${architecture}
|
|
|
|
CopyFiles=${defs}
|
|
|
|
Verity=data
|
|
|
|
VerityMatchKey=root
|
|
|
|
Minimize=guess
|
|
|
|
EOF
|
|
|
|
|
|
|
|
tee "$defs/verity-hash.conf" <<EOF
|
|
|
|
[Partition]
|
|
|
|
Type=root-${architecture}-verity
|
|
|
|
Verity=hash
|
|
|
|
VerityMatchKey=root
|
|
|
|
VerityHashBlockSizeBytes=1024
|
|
|
|
VerityDataBlockSizeBytes=4096
|
|
|
|
Minimize=yes
|
|
|
|
EOF
|
|
|
|
|
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--seed="$seed" \
|
|
|
|
--dry-run=no \
|
|
|
|
--empty=create \
|
|
|
|
--size=auto \
|
|
|
|
--json=pretty \
|
|
|
|
"$imgs/verity"
|
|
|
|
|
|
|
|
loop="$(losetup --partscan --show --find "$imgs/verity")"
|
|
|
|
|
|
|
|
# Make sure the loopback device gets cleaned up
|
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "rm -rf '$defs' '$imgs' ; losetup -d '$loop'" RETURN ERR
|
|
|
|
|
2024-05-20 09:47:39 +00:00
|
|
|
udevadm wait --timeout 60 --settle "${loop:?}p1" "${loop:?}p2"
|
2023-08-11 09:30:11 +00:00
|
|
|
|
|
|
|
# Check that the verity block sizes are as expected
|
|
|
|
veritysetup dump "${loop}p2" | grep 'Data block size:' | grep -q '4096'
|
|
|
|
veritysetup dump "${loop}p2" | grep 'Hash block size:' | grep -q '1024'
|
|
|
|
}
|
|
|
|
|
2023-05-22 14:02:43 +00:00
|
|
|
testcase_exclude_files() {
|
2022-11-09 12:41:38 +00:00
|
|
|
local defs imgs root output
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
|
2023-06-05 13:29:47 +00:00
|
|
|
imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
|
|
|
|
root="$(mktemp --directory "/var/tmp/test-repart.root.XXXXXXXXXX")"
|
2022-11-09 12:41:38 +00:00
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "rm -rf '$defs' '$imgs' '$root'" RETURN
|
2023-08-11 09:30:11 +00:00
|
|
|
chmod 0755 "$defs"
|
2023-05-29 18:52:33 +00:00
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** file exclusion ***"
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
touch "$root/abc"
|
|
|
|
mkdir "$root/usr"
|
|
|
|
touch "$root/usr/def"
|
|
|
|
touch "$root/usr/qed"
|
|
|
|
mkdir "$root/tmp"
|
|
|
|
touch "$root/tmp/prs"
|
|
|
|
mkdir "$root/proc"
|
|
|
|
touch "$root/proc/prs"
|
|
|
|
mkdir "$root/zzz"
|
|
|
|
mkdir "$root/zzz/usr"
|
|
|
|
touch "$root/zzz/usr/prs"
|
|
|
|
mkdir "$root/zzz/proc"
|
|
|
|
touch "$root/zzz/proc/prs"
|
|
|
|
|
|
|
|
tee "$defs/00-root.conf" <<EOF
|
2022-11-09 12:41:38 +00:00
|
|
|
[Partition]
|
|
|
|
Type=root-${architecture}
|
|
|
|
CopyFiles=/
|
repart: Fix deny list logic
Until now, we always excluded the top level directories that were
covered by child partition mount points, regardless of the source
directory and the target directory of the copy files operation.
This means that even if we were populating a XBOOTLDR partition, if
there was an EFI partition in the image, we'd exclude /boot
unconditionally, leading to the XBOOTLDR partition to be empty.
Also, because of the same cause, if we were copying a nested source
directory (e.g. /abc/def) to the root directory in the root
partition, if /abc/def/usr existed and was populated with files and
directories, the root partition would have those files under /usr,
even if a /usr partition was defined.
To fix these issues, instead of unconditionally excluding the top
level partition mount points under <source>, let's make sure that
when we're copying files from any source directory to the root
directory of a root partition, that we exclude the partition mount
point directories under the source directory instead of the top
level ones.
2023-05-08 16:44:01 +00:00
|
|
|
CopyFiles=/zzz:/
|
2023-05-22 21:17:49 +00:00
|
|
|
CopyFiles=/:/oiu
|
|
|
|
ExcludeFilesTarget=/oiu/usr
|
2022-11-09 12:41:38 +00:00
|
|
|
EOF
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
tee "$defs/10-usr.conf" <<EOF
|
2022-11-09 12:41:38 +00:00
|
|
|
[Partition]
|
|
|
|
Type=usr-${architecture}
|
|
|
|
CopyFiles=/usr:/
|
2023-02-16 12:23:47 +00:00
|
|
|
ExcludeFiles=/usr/qed
|
2022-11-09 12:41:38 +00:00
|
|
|
EOF
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
output=$(systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--seed="$seed" \
|
|
|
|
--dry-run=no \
|
|
|
|
--empty=create \
|
|
|
|
--size=auto \
|
|
|
|
--json=pretty \
|
|
|
|
--root="$root" \
|
|
|
|
"$imgs/zzz")
|
2022-11-10 14:40:00 +00:00
|
|
|
|
|
|
|
if systemd-detect-virt --quiet --container; then
|
|
|
|
echo "Skipping issue 24786 test loop/mount parts in container."
|
|
|
|
return
|
|
|
|
fi
|
2022-11-09 12:41:38 +00:00
|
|
|
|
|
|
|
loop=$(losetup -P --show -f "$imgs/zzz")
|
2024-05-20 09:47:39 +00:00
|
|
|
udevadm wait --timeout 60 --settle "${loop:?}p1" "${loop:?}p2"
|
2022-11-09 12:41:38 +00:00
|
|
|
|
2023-02-20 19:30:44 +00:00
|
|
|
# Test that /usr/def did not end up in the root partition but other files did.
|
2022-11-09 12:41:38 +00:00
|
|
|
mkdir "$imgs/mnt"
|
|
|
|
mount -t ext4 "${loop}p1" "$imgs/mnt"
|
|
|
|
assert_rc 0 ls "$imgs/mnt/abc"
|
2023-02-20 19:30:44 +00:00
|
|
|
assert_rc 0 ls "$imgs/mnt/usr"
|
|
|
|
assert_rc 2 ls "$imgs/mnt/usr/def"
|
2023-02-16 12:23:47 +00:00
|
|
|
|
repart: Fix deny list logic
Until now, we always excluded the top level directories that were
covered by child partition mount points, regardless of the source
directory and the target directory of the copy files operation.
This means that even if we were populating a XBOOTLDR partition, if
there was an EFI partition in the image, we'd exclude /boot
unconditionally, leading to the XBOOTLDR partition to be empty.
Also, because of the same cause, if we were copying a nested source
directory (e.g. /abc/def) to the root directory in the root
partition, if /abc/def/usr existed and was populated with files and
directories, the root partition would have those files under /usr,
even if a /usr partition was defined.
To fix these issues, instead of unconditionally excluding the top
level partition mount points under <source>, let's make sure that
when we're copying files from any source directory to the root
directory of a root partition, that we exclude the partition mount
point directories under the source directory instead of the top
level ones.
2023-05-08 16:44:01 +00:00
|
|
|
# Test that /zzz/usr/prs did not end up in the root partition under /usr but did end up in /zzz/usr/prs
|
|
|
|
assert_rc 2 ls "$imgs/mnt/usr/prs"
|
|
|
|
assert_rc 0 ls "$imgs/mnt/zzz/usr/prs"
|
|
|
|
|
2023-02-20 15:39:34 +00:00
|
|
|
# Test that /tmp/prs did not end up in the root partition but /tmp did.
|
|
|
|
assert_rc 0 ls "$imgs/mnt/tmp"
|
|
|
|
assert_rc 2 ls "$imgs/mnt/tmp/prs"
|
|
|
|
|
2023-02-20 19:30:44 +00:00
|
|
|
# Test that /usr/qed did not end up in the usr partition but /usr/def did.
|
2022-11-09 12:41:38 +00:00
|
|
|
mount -t ext4 "${loop}p2" "$imgs/mnt/usr"
|
|
|
|
assert_rc 0 ls "$imgs/mnt/usr/def"
|
2023-02-16 12:23:47 +00:00
|
|
|
assert_rc 2 ls "$imgs/mnt/usr/qed"
|
2022-11-09 12:41:38 +00:00
|
|
|
|
repart: Fix deny list logic
Until now, we always excluded the top level directories that were
covered by child partition mount points, regardless of the source
directory and the target directory of the copy files operation.
This means that even if we were populating a XBOOTLDR partition, if
there was an EFI partition in the image, we'd exclude /boot
unconditionally, leading to the XBOOTLDR partition to be empty.
Also, because of the same cause, if we were copying a nested source
directory (e.g. /abc/def) to the root directory in the root
partition, if /abc/def/usr existed and was populated with files and
directories, the root partition would have those files under /usr,
even if a /usr partition was defined.
To fix these issues, instead of unconditionally excluding the top
level partition mount points under <source>, let's make sure that
when we're copying files from any source directory to the root
directory of a root partition, that we exclude the partition mount
point directories under the source directory instead of the top
level ones.
2023-05-08 16:44:01 +00:00
|
|
|
# Test that /zzz/proc/prs did not end up in the root partition but /proc did.
|
|
|
|
assert_rc 0 ls "$imgs/mnt/proc"
|
|
|
|
assert_rc 2 ls "$imgs/mnt/proc/prs"
|
|
|
|
|
|
|
|
# Test that /zzz/usr/prs did not end up in the usr partition.
|
|
|
|
assert_rc 2 ls "$imgs/mnt/usr/prs"
|
|
|
|
|
2023-05-22 21:17:49 +00:00
|
|
|
# Test that /oiu/ and /oiu/zzz ended up in the root partition but /oiu/usr did not.
|
|
|
|
assert_rc 0 ls "$imgs/mnt/oiu"
|
|
|
|
assert_rc 0 ls "$imgs/mnt/oiu/zzz"
|
|
|
|
assert_rc 2 ls "$imgs/mnt/oiu/usr"
|
|
|
|
|
2022-11-09 12:41:38 +00:00
|
|
|
umount -R "$imgs/mnt"
|
|
|
|
losetup -d "$loop"
|
|
|
|
}
|
|
|
|
|
2023-05-22 14:02:43 +00:00
|
|
|
testcase_minimize() {
|
2022-11-10 11:33:02 +00:00
|
|
|
local defs imgs output
|
|
|
|
|
|
|
|
if systemd-detect-virt --quiet --container; then
|
|
|
|
echo "Skipping minimize test in container."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** minimization ***"
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
|
|
|
|
imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
|
2022-11-10 11:33:02 +00:00
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "rm -rf '$defs' '$imgs'" RETURN
|
|
|
|
|
2022-12-09 15:08:54 +00:00
|
|
|
for format in ext4 vfat erofs; do
|
2022-11-10 11:33:02 +00:00
|
|
|
if ! command -v "mkfs.$format" >/dev/null; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2023-01-23 13:47:00 +00:00
|
|
|
tee "$defs/root-$format.conf" <<EOF
|
2022-11-10 11:33:02 +00:00
|
|
|
[Partition]
|
|
|
|
Type=root-${architecture}
|
|
|
|
Format=${format}
|
|
|
|
CopyFiles=${defs}
|
2022-12-15 12:01:35 +00:00
|
|
|
Minimize=guess
|
2022-11-10 11:33:02 +00:00
|
|
|
EOF
|
|
|
|
done
|
|
|
|
|
2023-03-14 09:06:39 +00:00
|
|
|
if command -v mksquashfs >/dev/null; then
|
2023-01-23 13:47:00 +00:00
|
|
|
tee "$defs/root-squashfs.conf" <<EOF
|
2022-11-10 11:33:02 +00:00
|
|
|
[Partition]
|
|
|
|
Type=root-${architecture}
|
|
|
|
Format=squashfs
|
|
|
|
CopyFiles=${defs}
|
2022-12-15 12:01:35 +00:00
|
|
|
Minimize=best
|
2022-11-10 11:33:02 +00:00
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
output=$(systemd-repart --offline="$OFFLINE" \
|
|
|
|
--definitions="$defs" \
|
2022-11-10 11:33:02 +00:00
|
|
|
--seed="$seed" \
|
|
|
|
--dry-run=no \
|
|
|
|
--empty=create \
|
|
|
|
--size=auto \
|
|
|
|
--json=pretty \
|
|
|
|
"$imgs/zzz")
|
|
|
|
|
|
|
|
# Check that we can dissect, mount and unmount a minimized image.
|
|
|
|
|
|
|
|
systemd-dissect "$imgs/zzz"
|
|
|
|
systemd-dissect "$imgs/zzz" -M "$imgs/mnt"
|
|
|
|
systemd-dissect -U "$imgs/mnt"
|
|
|
|
}
|
|
|
|
|
2023-07-03 03:11:50 +00:00
|
|
|
testcase_free_area_calculation() {
|
|
|
|
local defs imgs output
|
|
|
|
|
|
|
|
if ! command -v mksquashfs >/dev/null; then
|
|
|
|
echo "Skipping free area calculation test without squashfs."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
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
|
2023-08-11 09:30:11 +00:00
|
|
|
chmod 0755 "$defs"
|
2023-07-03 03:11:50 +00:00
|
|
|
|
|
|
|
# https://github.com/systemd/systemd/issues/28225
|
|
|
|
echo "*** free area calculation ***"
|
|
|
|
|
|
|
|
tee "$defs/00-ESP.conf" <<EOF
|
|
|
|
[Partition]
|
|
|
|
Type = esp
|
|
|
|
Label = ESP
|
|
|
|
Format = vfat
|
|
|
|
|
|
|
|
SizeMinBytes = 128M
|
|
|
|
SizeMaxBytes = 128M
|
|
|
|
|
|
|
|
# Sufficient for testing
|
|
|
|
CopyFiles = /etc:/
|
|
|
|
EOF
|
|
|
|
|
|
|
|
tee "$defs/10-os.conf" <<EOF
|
|
|
|
[Partition]
|
|
|
|
Type = root-${architecture}
|
|
|
|
Label = test
|
|
|
|
Format = squashfs
|
|
|
|
|
|
|
|
Minimize = best
|
|
|
|
# Sufficient for testing
|
|
|
|
CopyFiles = /etc/:/
|
|
|
|
|
|
|
|
VerityMatchKey = os
|
|
|
|
Verity = data
|
|
|
|
EOF
|
|
|
|
|
|
|
|
tee "$defs/11-os-verity.conf" <<EOF
|
|
|
|
[Partition]
|
|
|
|
Type = root-${architecture}-verity
|
|
|
|
Label = test
|
|
|
|
|
|
|
|
Minimize = best
|
|
|
|
|
|
|
|
VerityMatchKey = os
|
|
|
|
Verity = hash
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Set sector size for VFAT to 512 bytes because there will not be enough FAT clusters otherwise
|
|
|
|
output1=$(SYSTEMD_REPART_MKFS_OPTIONS_VFAT="-S 512" systemd-repart \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--seed="$seed" \
|
|
|
|
--dry-run=no \
|
|
|
|
--empty=create \
|
|
|
|
--size=auto \
|
|
|
|
--sector-size=4096 \
|
|
|
|
--defer-partitions=esp \
|
|
|
|
--json=pretty \
|
|
|
|
"$imgs/zzz")
|
|
|
|
|
2023-07-03 06:15:27 +00:00
|
|
|
# The second invocation
|
2023-07-03 03:11:50 +00:00
|
|
|
output2=$(SYSTEMD_REPART_MKFS_OPTIONS_VFAT="-S 512" systemd-repart \
|
|
|
|
--definitions="$defs" \
|
|
|
|
--seed="$seed" \
|
|
|
|
--dry-run=no \
|
|
|
|
--empty=allow \
|
|
|
|
--size=auto \
|
|
|
|
--sector-size=4096 \
|
|
|
|
--defer-partitions=esp \
|
|
|
|
--json=pretty \
|
2023-07-03 06:15:27 +00:00
|
|
|
"$imgs/zzz")
|
|
|
|
|
|
|
|
diff -u <(echo "$output1" | grep -E "(offset|raw_size|raw_padding)") <(echo "$output2" | grep -E "(offset|raw_size|raw_padding)")
|
2023-07-03 03:11:50 +00:00
|
|
|
}
|
|
|
|
|
2022-08-19 07:33:09 +00:00
|
|
|
test_sector() {
|
|
|
|
local defs imgs output loop
|
|
|
|
local start size ratio
|
|
|
|
local sector="${1?}"
|
|
|
|
|
2022-08-19 19:59:03 +00:00
|
|
|
if systemd-detect-virt --quiet --container; then
|
|
|
|
echo "Skipping sector size tests in container."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2023-05-29 18:54:20 +00:00
|
|
|
echo "*** sector sizes ***"
|
|
|
|
|
2023-05-29 18:52:33 +00:00
|
|
|
defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
|
|
|
|
imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
|
2022-08-19 07:33:09 +00:00
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "rm -rf '$defs' '$imgs'" RETURN
|
|
|
|
|
2023-01-23 13:47:00 +00:00
|
|
|
tee "$defs/a.conf" <<EOF
|
2022-02-07 13:35:40 +00:00
|
|
|
[Partition]
|
|
|
|
Type=root
|
|
|
|
SizeMaxBytes=15M
|
|
|
|
SizeMinBytes=15M
|
|
|
|
EOF
|
2023-01-23 13:47:00 +00:00
|
|
|
tee "$defs/b.conf" <<EOF
|
2022-02-07 13:35:40 +00:00
|
|
|
[Partition]
|
|
|
|
Type=linux-generic
|
|
|
|
Weight=250
|
|
|
|
EOF
|
|
|
|
|
2023-01-23 13:47:00 +00:00
|
|
|
tee "$defs/c.conf" <<EOF
|
2022-02-07 13:35:40 +00:00
|
|
|
[Partition]
|
|
|
|
Type=linux-generic
|
|
|
|
Weight=750
|
|
|
|
EOF
|
|
|
|
|
2022-08-19 07:33:09 +00:00
|
|
|
truncate -s 100m "$imgs/$sector.img"
|
|
|
|
loop=$(losetup -b "$sector" -P --show -f "$imgs/$sector.img" )
|
|
|
|
udevadm wait --timeout 60 --settle "${loop:?}"
|
2023-06-05 13:29:47 +00:00
|
|
|
|
|
|
|
systemd-repart --offline="$OFFLINE" \
|
|
|
|
--pretty=yes \
|
2022-08-19 07:33:09 +00:00
|
|
|
--definitions="$defs" \
|
|
|
|
--seed="$seed" \
|
|
|
|
--empty=require \
|
|
|
|
--dry-run=no \
|
|
|
|
"$loop"
|
|
|
|
|
|
|
|
sfdisk --verify "$loop"
|
|
|
|
output=$(sfdisk --dump "$loop")
|
|
|
|
losetup -d "$loop"
|
|
|
|
|
|
|
|
ratio=$(( sector / 512 ))
|
|
|
|
start=$(( 2048 / ratio ))
|
|
|
|
size=$(( 30720 / ratio ))
|
|
|
|
assert_in "${loop}p1 : start= *${start}, size= *${size}, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"" "$output"
|
|
|
|
start=$(( start + size ))
|
|
|
|
size=$(( 42992 / ratio ))
|
|
|
|
assert_in "${loop}p2 : start= *${start}, size= *${size}, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=DF71F5E3-080A-4D16-824B-18591B881380, name=\"linux-generic\"" "$output"
|
|
|
|
start=$(( start + size ))
|
|
|
|
size=$(( 129000 / ratio ))
|
|
|
|
assert_in "${loop}p3 : start= *${start}, size= *${size}, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=DB081670-07AE-48CA-9F5E-813D5E40B976, name=\"linux-generic-2\"" "$output"
|
2022-02-07 13:35:40 +00:00
|
|
|
}
|
|
|
|
|
2024-01-06 15:07:42 +00:00
|
|
|
testcase_dropped_partitions() {
|
|
|
|
local workdir image defs
|
|
|
|
|
|
|
|
workdir="$(mktemp --directory "/tmp/test-repart.dropped-partitions.XXXXXXXXXX")"
|
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "rm -rf '${workdir:?}'" RETURN
|
|
|
|
|
|
|
|
image="$workdir/image.img"
|
|
|
|
truncate -s 32M "$image"
|
|
|
|
|
|
|
|
defs="$workdir/defs"
|
|
|
|
mkdir "$defs"
|
|
|
|
echo -ne "[Partition]\nType=root\n" >"$defs/10-part1.conf"
|
|
|
|
echo -ne "[Partition]\nType=root\nSizeMinBytes=1T\nPriority=1\n" >"$defs/11-dropped-first.conf"
|
|
|
|
echo -ne "[Partition]\nType=root\n" >"$defs/12-part2.conf"
|
|
|
|
echo -ne "[Partition]\nType=root\nSizeMinBytes=1T\nPriority=2\n" >"$defs/13-dropped-second.conf"
|
|
|
|
|
|
|
|
systemd-repart --empty=allow --pretty=yes --dry-run=no --definitions="$defs" "$image"
|
|
|
|
|
|
|
|
sfdisk -q -l "$image"
|
|
|
|
[[ "$(sfdisk -q -l "$image" | grep -c "$image")" -eq 2 ]]
|
|
|
|
}
|
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
OFFLINE="yes"
|
2023-05-22 14:02:43 +00:00
|
|
|
run_testcases
|
2022-08-19 07:33:09 +00:00
|
|
|
|
2023-06-05 13:29:47 +00:00
|
|
|
# Online image builds need loop devices so we can't run them in nspawn.
|
|
|
|
if ! systemd-detect-virt --container; then
|
|
|
|
OFFLINE="no"
|
|
|
|
run_testcases
|
|
|
|
fi
|
|
|
|
|
2022-02-07 13:35:40 +00:00
|
|
|
# Valid block sizes on the Linux block layer are >= 512 and <= PAGE_SIZE, and
|
|
|
|
# must be powers of 2. Which leaves exactly four different ones to test on
|
|
|
|
# typical hardware
|
2022-08-19 07:33:09 +00:00
|
|
|
test_sector 512
|
|
|
|
test_sector 1024
|
|
|
|
test_sector 2048
|
|
|
|
test_sector 4096
|
2022-02-07 13:35:40 +00:00
|
|
|
|
2023-07-12 13:49:55 +00:00
|
|
|
touch /testok
|