2 # SPDX-License-Identifier: LGPL-2.1-or-later
6 if systemd-detect-virt
--quiet --container; then
7 echo "running on container, skipping."
11 if ! command -v bootctl
>/dev
/null
; then
12 echo "bootctl not found, skipping."
16 # shellcheck source=test/units/util.sh
17 .
"$(dirname "$0")"/util.sh
19 # shellcheck source=test/units/test-control.sh
20 .
"$(dirname "$0")"/test-control.sh
24 bootctl
"$@" --version
26 bootctl
"$@" install --make-entry-directory=yes
27 bootctl
"$@" remove
--make-entry-directory=yes
29 bootctl
"$@" install --all-architectures
30 bootctl
"$@" remove
--all-architectures
32 bootctl
"$@" install --make-entry-directory=yes --all-architectures
33 bootctl
"$@" remove
--make-entry-directory=yes --all-architectures
36 (! bootctl
"$@" update
)
37 bootctl
"$@" update
--graceful
39 bootctl
"$@" is-installed
40 bootctl
"$@" is-installed
--graceful
41 bootctl
"$@" random-seed
45 bootctl
"$@" status
--quiet
47 bootctl
"$@" list
--quiet
48 bootctl
"$@" list
--json=short
49 bootctl
"$@" list
--json=pretty
52 (! bootctl
"$@" is-installed
)
53 (! bootctl
"$@" is-installed
--graceful)
56 testcase_bootctl_basic
() {
57 assert_eq
"$(bootctl --print-esp-path)" "/efi"
58 assert_eq
"$(bootctl --print-boot-path)" "/boot"
59 bootctl
--print-root-device
67 if [[ -z "${IMAGE_DIR:-}" ]]; then
71 umount
"${IMAGE_DIR}/root"
73 if [[ -n "${LOOPDEV:-}" ]]; then
74 losetup
-d "${LOOPDEV}"
86 testcase_bootctl_image
() {
87 IMAGE_DIR
="$(mktemp --directory /tmp/test-bootctl.XXXXXXXXXX)"
88 trap cleanup_image RETURN
90 truncate
-s 256m
"${IMAGE_DIR}/image"
92 cat >"${IMAGE_DIR}/partscript" <<EOF
94 type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B name=esp size=64M
95 type=0FC63DAF-8483-4772-8E79-3D69D8477DE4 name=root size=64M bootable
96 type=BC13C2FF-59E6-4262-A352-B275FD6F7172 name=boot
99 LOOPDEV
="$(losetup --show -P -f "${IMAGE_DIR}/image
")"
100 sfdisk
"$LOOPDEV" <"${IMAGE_DIR}/partscript"
104 mkfs.vfat
-n esp
"${LOOPDEV}p1"
105 mkfs.ext4
-L root
"${LOOPDEV}p2"
106 mkfs.ext4
-L boot
"${LOOPDEV}p3"
108 mkdir
-p "${IMAGE_DIR}/root"
109 mount
-t ext4
"${LOOPDEV}p2" "${IMAGE_DIR}/root"
111 mkdir
-p "${IMAGE_DIR}/root/efi"
112 mkdir
-p "${IMAGE_DIR}/root/boot"
113 mkdir
-p "${IMAGE_DIR}/root/etc"
114 mkdir
-p "${IMAGE_DIR}/root/usr/lib"
115 if [[ -f /usr
/lib
/os-release
]]; then
116 cp /usr
/lib
/os-release
"${IMAGE_DIR}/root/usr/lib/."
117 ln -s ..
/usr
/lib
/os-release
"${IMAGE_DIR}/root/etc/os-release"
119 cp -a /etc
/os-release
"${IMAGE_DIR}/root/etc/."
122 umount
"${IMAGE_DIR}/root"
124 assert_eq
"$(bootctl --image "${IMAGE_DIR}/image
" --print-esp-path)" "/run/systemd/mount-rootfs/efi"
125 assert_eq
"$(bootctl --image "${IMAGE_DIR}/image
" --print-esp-path --esp-path=/efi)" "/run/systemd/mount-rootfs/efi"
126 assert_eq
"$(bootctl --image "${IMAGE_DIR}/image
" --print-boot-path)" "/run/systemd/mount-rootfs/boot"
127 assert_eq
"$(bootctl --image "${IMAGE_DIR}/image
" --print-boot-path --boot-path=/boot)" "/run/systemd/mount-rootfs/boot"
129 # FIXME: This provides spurious result.
130 bootctl
--image "${IMAGE_DIR}/image" --print-root-device ||
:
132 basic_tests
--image "${IMAGE_DIR}/image"
138 if [[ -z "${IMAGE_DIR:-}" ]]; then
142 systemd-umount
"${IMAGE_DIR}/root/efi"
143 systemd-umount
"${IMAGE_DIR}/root/boot"
144 systemd-umount
"${IMAGE_DIR}/root"
146 mdadm
--misc --stop /dev
/md
/raid-esp
147 mdadm
--misc --stop /dev
/md
/raid-root
149 if [[ -n "${LOOPDEV1:-}" ]]; then
150 mdadm
--misc --force --zero-superblock "${LOOPDEV1}p1"
151 mdadm
--misc --force --zero-superblock "${LOOPDEV1}p2"
154 if [[ -n "${LOOPDEV2:-}" ]]; then
155 mdadm
--misc --force --zero-superblock "${LOOPDEV2}p1"
156 mdadm
--misc --force --zero-superblock "${LOOPDEV2}p2"
161 if [[ -n "${LOOPDEV1:-}" ]]; then
162 mdadm
--misc --force --zero-superblock "${LOOPDEV1}p1"
163 mdadm
--misc --force --zero-superblock "${LOOPDEV1}p2"
164 losetup
-d "${LOOPDEV1}"
168 if [[ -n "${LOOPDEV2:-}" ]]; then
169 mdadm
--misc --force --zero-superblock "${LOOPDEV2}p1"
170 mdadm
--misc --force --zero-superblock "${LOOPDEV2}p2"
171 losetup
-d "${LOOPDEV2}"
177 rm -rf "${IMAGE_DIR}"
182 testcase_bootctl_raid
() {
183 if ! command -v mdadm
>/dev
/null
; then
184 echo "mdadm not found, skipping."
188 if ! command -v mkfs.btrfs
>/dev
/null
; then
189 echo "mkfs.btrfs not found, skipping."
193 IMAGE_DIR
="$(mktemp --directory /tmp/test-bootctl.XXXXXXXXXX)"
194 trap cleanup_raid RETURN
196 truncate
-s 256m
"${IMAGE_DIR}/image1"
197 truncate
-s 256m
"${IMAGE_DIR}/image2"
199 cat >"${IMAGE_DIR}/partscript" <<EOF
201 type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B name=esp size=64M
202 type=0FC63DAF-8483-4772-8E79-3D69D8477DE4 name=root size=64M bootable
203 type=BC13C2FF-59E6-4262-A352-B275FD6F7172 name=boot
206 LOOPDEV1
="$(losetup --show -P -f "${IMAGE_DIR}/image1
")"
207 LOOPDEV2
="$(losetup --show -P -f "${IMAGE_DIR}/image2
")"
208 sfdisk
"$LOOPDEV1" <"${IMAGE_DIR}/partscript"
209 sfdisk
"$LOOPDEV2" <"${IMAGE_DIR}/partscript"
213 echo y | mdadm
--create /dev
/md
/raid-esp
--name "raid-esp" "${LOOPDEV1}p1" "${LOOPDEV2}p1" -v -f --level=1 --raid-devices=2
214 mkfs.vfat
/dev
/md
/raid-esp
215 echo y | mdadm
--create /dev
/md
/raid-root
--name "raid-root" "${LOOPDEV1}p2" "${LOOPDEV2}p2" -v -f --level=1 --raid-devices=2
216 mkfs.ext4
/dev
/md
/raid-root
217 mkfs.btrfs
-f -M -d raid1
-m raid1
-L "raid-boot" "${LOOPDEV1}p3" "${LOOPDEV2}p3"
219 mkdir
-p "${IMAGE_DIR}/root"
220 mount
-t ext4
/dev
/md
/raid-root
"${IMAGE_DIR}/root"
221 mkdir
-p "${IMAGE_DIR}/root/efi"
222 mount
-t vfat
/dev
/md
/raid-esp
"${IMAGE_DIR}/root/efi"
223 mkdir
-p "${IMAGE_DIR}/root/boot"
224 mount
-t btrfs
"${LOOPDEV1}p3" "${IMAGE_DIR}/root/boot"
226 mkdir
-p "${IMAGE_DIR}/root/etc"
227 mkdir
-p "${IMAGE_DIR}/root/usr/lib"
228 if [[ -f /usr
/lib
/os-release
]]; then
229 cp /usr
/lib
/os-release
"${IMAGE_DIR}/root/usr/lib/."
230 ln -s ..
/usr
/lib
/os-release
"${IMAGE_DIR}/root/etc/os-release"
232 cp -a /etc
/os-release
"${IMAGE_DIR}/root/etc/."
235 # find_esp() does not support md RAID partition.
236 (! bootctl
--root "${IMAGE_DIR}/root" --print-esp-path)
237 (! bootctl
--root "${IMAGE_DIR}/root" --print-esp-path --esp-path=/efi
)
239 # If the verification is relaxed, it accepts md RAID partition.
240 assert_eq
"$(SYSTEMD_RELAX_ESP_CHECKS=yes bootctl --root "${IMAGE_DIR}/root
" --print-esp-path)" "${IMAGE_DIR}/root/efi"
241 assert_eq
"$(SYSTEMD_RELAX_ESP_CHECKS=yes bootctl --root "${IMAGE_DIR}/root
" --print-esp-path --esp-path=/efi)" "${IMAGE_DIR}/root/efi"
243 # find_xbootldr() does not support btrfs RAID, and bootctl tries to fall back to use ESP.
244 # (but as in the above, the ESP verification is also failed in this case).
245 (! bootctl
--root "${IMAGE_DIR}/root" --print-boot-path)
246 (! bootctl
--root "${IMAGE_DIR}/root" --print-boot-path --boot-path=/boot
)
248 # If the verification for ESP is relaxed, bootctl falls back to use ESP.
249 assert_eq
"$(SYSTEMD_RELAX_ESP_CHECKS=yes bootctl --root "${IMAGE_DIR}/root
" --print-boot-path)" "${IMAGE_DIR}/root/efi"
251 # If the verification is relaxed, it accepts the xbootldr partition.
252 assert_eq
"$(SYSTEMD_RELAX_XBOOTLDR_CHECKS=yes bootctl --root "${IMAGE_DIR}/root
" --print-boot-path)" "${IMAGE_DIR}/root/boot"
253 assert_eq
"$(SYSTEMD_RELAX_XBOOTLDR_CHECKS=yes bootctl --root "${IMAGE_DIR}/root
" --print-boot-path --boot-path=/boot)" "${IMAGE_DIR}/root/boot"
255 # FIXME: This provides spurious result.
256 bootctl
--root "${IMAGE_DIR}/root" --print-root-device ||
:
258 SYSTEMD_RELAX_ESP_CHECKS
=yes SYSTEMD_RELAX_XBOOTLDR_CHECKS
=yes basic_tests
--root "${IMAGE_DIR}/root"