3 # shellcheck disable=SC2034
4 TEST_DESCRIPTION
="Full systemd serialization/deserialization test with /usr mount"
6 export KVERSION
=${KVERSION-$(uname -r)}
8 # Uncomment this to debug failures
9 #DEBUGFAIL="rd.shell rd.break"
11 #DEBUGOUT="quiet systemd.log_level=debug systemd.log_target=console loglevel=77 rd.info rd.debug"
12 DEBUGOUT
="loglevel=0 "
16 local client_opts
="$*"
18 echo "CLIENT TEST START: $test_name"
20 dd if=/dev
/zero of
="$TESTDIR"/marker.img bs
=1MiB count
=1
21 declare -a disk_args
=()
22 # shellcheck disable=SC2034
23 declare -i disk_index
=0
24 qemu_add_drive_args disk_index disk_args
"$TESTDIR"/marker.img marker
25 qemu_add_drive_args disk_index disk_args
"$TESTDIR"/root.btrfs root
26 qemu_add_drive_args disk_index disk_args
"$TESTDIR"/usr.btrfs usr
30 -append "panic=1 oops=panic softlockup_panic=1 systemd.crash_reboot root=LABEL=dracut $client_opts rd.retry=3 console=ttyS0,115200n81 selinux=0 $DEBUGOUT rd.shell=0 $DEBUGFAIL" \
31 -initrd "$TESTDIR"/initramfs.testing ||
return 1
33 if ! grep -U --binary-files=binary
-F -m 1 -q dracut-root-block-success
"$TESTDIR"/marker.img
; then
34 echo "CLIENT TEST END: $test_name [FAILED]"
37 echo "CLIENT TEST END: $test_name [OK]"
42 client_run
"no option specified" ||
return 1
43 client_run
"readonly root" "ro" ||
return 1
44 client_run
"writeable root" "rw" ||
return 1
49 # shellcheck disable=SC2064
50 trap "$(shopt -p nullglob globstar)" RETURN
51 shopt -q -s nullglob globstar
53 export kernel
=$KVERSION
54 # Create what will eventually be our root filesystem onto an overlay
56 # shellcheck disable=SC2030
57 export initdir
=$TESTDIR/overlay
/source
59 # shellcheck disable=SC1090
60 .
"$basedir"/dracut-init.sh
62 for d
in usr
/bin usr
/sbin bin etc lib
"$libdir" sbin tmp usr var var
/log dev proc sys sysroot root run
; do
70 ln -sfn /run
"$initdir/var/run"
71 ln -sfn /run
/lock
"$initdir/var/lock"
73 inst_multiple sh df free
ls shutdown poweroff stty
cat ps
ln ip \
74 mount dmesg mkdir
cp ping dd \
75 umount strace
less setsid systemctl
reset sync
77 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
78 [ -f ${_terminfodir}/l
/linux
] && break
80 inst_multiple
-o ${_terminfodir}/l
/linux
82 inst_simple .
/fstab
/etc
/fstab
83 if type -P rpm
&> /dev
/null
; then
84 rpm
-ql systemd |
xargs -r "$DRACUT_INSTALL" ${initdir:+-D "$initdir"} -o -a -l
85 elif type -P pacman
&> /dev
/null
; then
86 pacman
-Q -l systemd |
while read -r _ a
; do printf -- "%s\0" "$a"; done |
xargs -0 -r "$DRACUT_INSTALL" ${initdir:+-D "$initdir"} -o -a -l
87 rm "$initdir"/usr
/lib
/systemd
/system
/sysinit.target.wants
/systemd-firstboot.service
89 echo "Can't install systemd base"
93 inst_multiple
-o {,/usr
}/lib
/systemd
/system
/"dracut*"
95 inst_simple
"${basedir}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh"
96 inst_binary
"${basedir}/dracut-util" "/usr/bin/dracut-util"
97 ln -s dracut-util
"${initdir}/usr/bin/dracut-getarg"
98 ln -s dracut-util
"${initdir}/usr/bin/dracut-getargs"
100 # make a journal directory
101 mkdir
-p "$initdir"/var
/log
/journal
103 # install some basic config files
111 {,/usr
}/etc
/nsswitch.conf \
117 # we want an empty environment
118 : > "$initdir"/etc
/environment
120 # setup the testsuite target
121 mkdir
-p "$initdir"/etc
/systemd
/system
122 cat > "$initdir"/etc
/systemd
/system
/testsuite.target
<< EOF
124 Description=Testsuite target
125 Requires=basic.target
127 Conflicts=rescue.target
131 inst .
/test-init.sh
/sbin
/test-init
133 # setup the testsuite service
134 cat > "$initdir"/etc
/systemd
/system
/testsuite.service
<< EOF
136 Description=Testsuite service
140 ExecStart=/sbin/test-init
145 mkdir
-p "$initdir"/etc
/systemd
/system
/testsuite.target.wants
146 ln -fs ..
/testsuite.service
"$initdir"/etc
/systemd
/system
/testsuite.target.wants
/testsuite.service
148 # make the testsuite the default target
149 systemctl
--root="$initdir" set-default testsuite.target
151 # install basic tools needed
152 inst_multiple sh bash setsid loadkeys setfont \
153 login sulogin
gzip sleep echo mount umount
154 inst_multiple modprobe
156 # install libnss_files for login
157 inst_libdir_file
"libnss_files*"
159 # install dbus and pam
167 # install dbus socket and service file
169 /usr
/lib
/systemd
/system
/dbus.socket \
170 /usr
/lib
/systemd
/system
/dbus.service \
171 /usr
/lib
/systemd
/system
/dbus-broker.service \
172 /usr
/lib
/systemd
/system
/dbus-daemon.service
177 ) > "$initrd"/etc
/vconsole.conf
179 # install basic keyboard maps and fonts
181 /usr
/lib
/kbd
/consolefonts
/eurlatgr
* \
182 /usr
/lib
/kbd
/keymaps
/{legacy
/,/}include
/* \
183 /usr
/lib
/kbd
/keymaps
/{legacy
/,/}i386
/include
/* \
184 /usr
/lib
/kbd
/keymaps
/{legacy
/,/}i386
/qwerty
/us.
*; do
185 [[ -f $i ]] ||
continue
189 # some basic terminfo files
190 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
191 [ -f ${_terminfodir}/l
/linux
] && break
193 inst_multiple
-o ${_terminfodir}/l
/linux
196 ln -fs /proc
/self
/mounts
"$initdir"/etc
/mtab
198 # install any Execs from the service files
199 grep -Eho '^Exec[^ ]*=[^ ]+' "$initdir"{,/usr
}/lib
/systemd
/system
/*.service \
200 |
while read -r i ||
[ -n "$i" ]; do
203 inst_multiple
-o "$i"
206 # some helper tools for debugging
207 [[ $DEBUGTOOLS ]] && inst_multiple
"$DEBUGTOOLS"
209 # install ld.so.conf* and run ldconfig
210 cp -a /etc
/ld.so.conf
* "$initdir"/etc
211 ldconfig
-r "$initdir"
212 ddebug
"Strip binaeries"
213 find "$initdir" -perm /0111 -type f
-print0 |
xargs -0 -r strip
--strip-unneeded | ddebug
215 hostonly
='' instmods fuse
218 inst
/lib
/modules
/"$kernel"/modules.order
219 inst
/lib
/modules
/"$kernel"/modules.
builtin
220 # generate module dependencies
221 if [[ -d $initdir/lib
/modules
/$kernel ]] \
222 && ! depmod
-a -b "$initdir" "$kernel"; then
223 dfatal
"\"depmod -a $kernel\" failed."
226 # disable some services
227 systemctl
--root "$initdir" mask systemd-update-utmp
228 systemctl
--root "$initdir" mask systemd-tmpfiles-setup
231 # second, install the files needed to make the root filesystem
233 # shellcheck disable=SC2030
234 # shellcheck disable=SC2031
235 export initdir
=$TESTDIR/overlay
236 # shellcheck disable=SC1090
237 .
"$basedir"/dracut-init.sh
238 inst_multiple sfdisk mkfs.btrfs btrfs poweroff
cp umount sync
dd
239 inst_hook initqueue
01 .
/create-root.sh
240 inst_hook initqueue
/finished
01 .
/finished-false.sh
243 # create an initramfs that will create the target root filesystem.
244 # We do it this way so that we do not risk trashing the host mdraid
245 # devices, volume groups, encrypted partitions, etc.
246 "$basedir"/dracut.sh
-l -i "$TESTDIR"/overlay
/ \
247 -m "bash udev-rules btrfs base rootfs-block fs-lib kernel-modules qemu" \
248 -d "piix ide-gd_mod ata_piix btrfs sd_mod" \
251 --no-hostonly-cmdline -N \
252 -f "$TESTDIR"/initramfs.makeroot
"$KVERSION" ||
return 1
253 rm -rf -- "$TESTDIR"/overlay
255 # Create the blank file to use as a root filesystem
256 dd if=/dev
/zero of
="$TESTDIR"/root.btrfs bs
=1MiB count
=160
257 dd if=/dev
/zero of
="$TESTDIR"/usr.btrfs bs
=1MiB count
=160
258 dd if=/dev
/zero of
="$TESTDIR"/marker.img bs
=1MiB count
=1
259 declare -a disk_args
=()
260 # shellcheck disable=SC2034
261 declare -i disk_index
=0
262 qemu_add_drive_args disk_index disk_args
"$TESTDIR"/marker.img marker
263 qemu_add_drive_args disk_index disk_args
"$TESTDIR"/root.btrfs root
264 qemu_add_drive_args disk_index disk_args
"$TESTDIR"/usr.btrfs usr
266 # Invoke KVM and/or QEMU to actually create the target filesystem.
267 "$testdir"/run-qemu \
269 -append "root=/dev/fakeroot rw rootfstype=btrfs quiet console=ttyS0,115200n81 selinux=0" \
270 -initrd "$TESTDIR"/initramfs.makeroot ||
return 1
272 if ! grep -U --binary-files=binary
-F -m 1 -q dracut-root-block-created
"$TESTDIR"/marker.img
; then
273 echo "Could not create root filesystem"
278 # shellcheck disable=SC2031
279 export initdir
=$TESTDIR/overlay
280 # shellcheck disable=SC1090
281 .
"$basedir"/dracut-init.sh
282 inst_multiple poweroff shutdown
dd
283 inst_hook shutdown-emergency
000 .
/hard-off.sh
284 inst_hook emergency
000 .
/hard-off.sh
287 [ -e /etc
/machine-id
] && EXTRA_MACHINE
="/etc/machine-id"
288 [ -e /etc
/machine-info
] && EXTRA_MACHINE
+=" /etc/machine-info"
290 "$basedir"/dracut.sh
-l -i "$TESTDIR"/overlay
/ \
291 -a "debug systemd i18n qemu" \
292 ${EXTRA_MACHINE:+-I "$EXTRA_MACHINE"} \
293 -o "dash network plymouth lvm mdraid resume crypt caps dm terminfo usrmount kernel-network-modules rngd" \
294 -d "piix ide-gd_mod ata_piix btrfs sd_mod i6300esb ib700wdt" \
295 --no-hostonly-cmdline -N \
296 -f "$TESTDIR"/initramfs.testing
"$KVERSION" ||
return 1
298 rm -rf -- "$TESTDIR"/overlay
305 # shellcheck disable=SC1090
306 .
"$testdir"/test-functions