]> git.ipfire.org Git - thirdparty/dracut.git/blame - test/TEST-04-FULL-SYSTEMD/test.sh
test: run-qemu refactor common qemu parameters
[thirdparty/dracut.git] / test / TEST-04-FULL-SYSTEMD / test.sh
CommitLineData
badda27f
HH
1#!/bin/bash
2
3TEST_DESCRIPTION="Full systemd serialization/deserialization test with /usr mount"
4
cc68f78d 5export KVERSION=${KVERSION-$(uname -r)}
badda27f
HH
6
7# Uncomment this to debug failures
b093aa2d 8#DEBUGFAIL="rd.shell rd.break"
3d115217
HH
9#DEBUGFAIL="rd.shell"
10#DEBUGOUT="quiet systemd.log_level=debug systemd.log_target=console loglevel=77 rd.info rd.debug"
1d84d694 11DEBUGOUT="loglevel=0 "
badda27f
HH
12client_run() {
13 local test_name="$1"; shift
14 local client_opts="$*"
15
16 echo "CLIENT TEST START: $test_name"
17
18 dd if=/dev/zero of=$TESTDIR/result bs=1M count=1
19 $testdir/run-qemu \
2f78bafa
HH
20 -drive format=raw,index=0,media=disk,file=$TESTDIR/root.btrfs \
21 -drive format=raw,index=1,media=disk,file=$TESTDIR/usr.btrfs \
22 -drive format=raw,index=2,media=disk,file=$TESTDIR/result \
2f78bafa
HH
23 -append "panic=1 systemd.crash_reboot root=LABEL=dracut $client_opts rd.retry=3 console=ttyS0,115200n81 selinux=0 $DEBUGOUT rd.shell=0 $DEBUGFAIL" \
24 -initrd $TESTDIR/initramfs.testing
badda27f
HH
25
26 if (($? != 0)); then
2f78bafa 27 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
badda27f
HH
28 return 1
29 fi
30
021b2fdd 31 if ! grep -F -m 1 -q dracut-root-block-success $TESTDIR/result; then
2f78bafa 32 echo "CLIENT TEST END: $test_name [FAILED]"
badda27f
HH
33 return 1
34 fi
35 echo "CLIENT TEST END: $test_name [OK]"
36
37}
38
39test_run() {
40 client_run "no option specified" || return 1
41 client_run "readonly root" "ro" || return 1
42 client_run "writeable root" "rw" || return 1
43 return 0
44}
45
46test_setup() {
32bd2fbb
HH
47 rm -f -- $TESTDIR/root.btrfs
48 rm -f -- $TESTDIR/usr.btrfs
badda27f
HH
49 # Create the blank file to use as a root filesystem
50 dd if=/dev/null of=$TESTDIR/root.btrfs bs=1M seek=320
51 dd if=/dev/null of=$TESTDIR/usr.btrfs bs=1M seek=320
52
cc68f78d 53 export kernel=$KVERSION
badda27f
HH
54 # Create what will eventually be our root filesystem onto an overlay
55 (
2f78bafa
HH
56 export initdir=$TESTDIR/overlay/source
57 mkdir -p $initdir
58 . $basedir/dracut-init.sh
badda27f 59
3d115217 60 for d in usr/bin usr/sbin bin etc lib "$libdir" sbin tmp usr var var/log dev proc sys sysroot root run; do
badda27f
HH
61 if [ -L "/$d" ]; then
62 inst_symlink "/$d"
63 else
64 inst_dir "/$d"
65 fi
66 done
67
68 ln -sfn /run "$initdir/var/run"
69 ln -sfn /run/lock "$initdir/var/lock"
70
2f78bafa
HH
71 inst_multiple sh df free ls shutdown poweroff stty cat ps ln ip \
72 mount dmesg mkdir cp ping \
73 umount strace less setsid tree systemctl reset
3d115217 74
2f78bafa 75 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
badda27f 76 [ -f ${_terminfodir}/l/linux ] && break
2f78bafa
HH
77 done
78 inst_multiple -o ${_terminfodir}/l/linux
79 inst_multiple grep
badda27f 80 inst_simple ./fstab /etc/fstab
ffc68f35 81 rpm -ql systemd | xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -o -a -l
83691c41
HH
82 inst /lib/systemd/system/systemd-remount-fs.service
83 inst /lib/systemd/systemd-remount-fs
badda27f
HH
84 inst /lib/systemd/system/systemd-journal-flush.service
85 inst /etc/sysconfig/init
2f78bafa
HH
86 inst /lib/systemd/system/slices.target
87 inst /lib/systemd/system/system.slice
88 inst_multiple -o /lib/systemd/system/dracut*
badda27f
HH
89
90 # make a journal directory
91 mkdir -p $initdir/var/log/journal
92
93 # install some basic config files
af119460 94 inst_multiple -o \
2f78bafa
HH
95 /etc/machine-id \
96 /etc/adjtime \
97 /etc/passwd \
98 /etc/shadow \
99 /etc/group \
100 /etc/shells \
101 /etc/nsswitch.conf \
102 /etc/pam.conf \
103 /etc/securetty \
104 /etc/os-release \
105 /etc/localtime
badda27f
HH
106
107 # we want an empty environment
108 > $initdir/etc/environment
badda27f
HH
109
110 # setup the testsuite target
2f78bafa 111 mkdir -p $initdir/etc/systemd/system
badda27f
HH
112 cat >$initdir/etc/systemd/system/testsuite.target <<EOF
113[Unit]
114Description=Testsuite target
3d115217
HH
115Requires=basic.target
116After=basic.target
badda27f
HH
117Conflicts=rescue.target
118AllowIsolate=yes
119EOF
120
121 inst ./test-init.sh /sbin/test-init
122
123 # setup the testsuite service
124 cat >$initdir/etc/systemd/system/testsuite.service <<EOF
125[Unit]
126Description=Testsuite service
3d115217 127After=basic.target
badda27f
HH
128
129[Service]
130ExecStart=/sbin/test-init
badda27f 131Type=oneshot
3d115217
HH
132StandardInput=tty
133StandardOutput=tty
badda27f
HH
134EOF
135 mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
136 ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
137
138 # make the testsuite the default target
139 ln -fs testsuite.target $initdir/etc/systemd/system/default.target
665b7e58 140
2f78bafa
HH
141 # mkdir -p $initdir/etc/rc.d
142 # cat >$initdir/etc/rc.d/rc.local <<EOF
143 # #!/bin/bash
144 # exit 0
145 # EOF
badda27f
HH
146
147 # install basic tools needed
af119460 148 inst_multiple sh bash setsid loadkeys setfont \
2f78bafa 149 login sushell sulogin gzip sleep echo mount umount
af119460 150 inst_multiple modprobe
badda27f
HH
151
152 # install libnss_files for login
153 inst_libdir_file "libnss_files*"
154
155 # install dbus and pam
156 find \
157 /etc/dbus-1 \
158 /etc/pam.d \
159 /etc/security \
160 /lib64/security \
161 /lib/security -xtype f \
6d58fa27 162 | while read file || [ -n "$file" ]; do
af119460 163 inst_multiple -o $file
badda27f
HH
164 done
165
166 # install dbus socket and service file
167 inst /usr/lib/systemd/system/dbus.socket
168 inst /usr/lib/systemd/system/dbus.service
2f78bafa
HH
169 inst /usr/lib/systemd/system/dbus-broker.service
170 inst /usr/lib/systemd/system/dbus-daemon.service
badda27f 171
9ee2f1e2 172 (
42d93d34 173 echo "FONT=eurlatgr"
9ee2f1e2
HH
174 echo "KEYMAP=us"
175 ) >$initrd/etc/vconsole.conf
176
badda27f
HH
177 # install basic keyboard maps and fonts
178 for i in \
b4fb539c 179 /usr/lib/kbd/consolefonts/eurlatgr* \
2f78bafa
HH
180 /usr/lib/kbd/keymaps/{legacy/,/}include/* \
181 /usr/lib/kbd/keymaps/{legacy/,/}i386/include/* \
182 /usr/lib/kbd/keymaps/{legacy/,/}i386/qwerty/us.*; do
183 [[ -f $i ]] || continue
184 inst $i
badda27f
HH
185 done
186
187 # some basic terminfo files
188 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
189 [ -f ${_terminfodir}/l/linux ] && break
190 done
af119460 191 inst_multiple -o ${_terminfodir}/l/linux
badda27f
HH
192
193 # softlink mtab
194 ln -fs /proc/self/mounts $initdir/etc/mtab
195
2a5a7fb6 196 # install any Execs from the service files
9430ae30 197 grep -Eho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
6d58fa27 198 | while read i || [ -n "$i" ]; do
badda27f 199 i=${i##Exec*=}; i=${i##-}
af119460 200 inst_multiple -o $i
badda27f
HH
201 done
202
203 # some helper tools for debugging
af119460 204 [[ $DEBUGTOOLS ]] && inst_multiple $DEBUGTOOLS
badda27f
HH
205
206 # install ld.so.conf* and run ldconfig
207 cp -a /etc/ld.so.conf* $initdir/etc
208 ldconfig -r "$initdir"
209 ddebug "Strip binaeries"
2a5a7fb6 210 find "$initdir" -perm /0111 -type f | xargs -r strip --strip-unneeded | ddebug
badda27f
HH
211
212 # copy depmod files
cc68f78d
HH
213 inst /lib/modules/$kernel/modules.order
214 inst /lib/modules/$kernel/modules.builtin
badda27f 215 # generate module dependencies
cc68f78d 216 if [[ -d $initdir/lib/modules/$kernel ]] && \
2f78bafa
HH
217 ! depmod -a -b "$initdir" $kernel; then
218 dfatal "\"depmod -a $kernel\" failed."
219 exit 1
badda27f 220 fi
2f78bafa
HH
221 # disable some services
222 systemctl --root "$initdir" mask systemd-update-utmp
223 systemctl --root "$initdir" mask systemd-tmpfiles-setup
badda27f 224 )
b0d844fa 225
badda27f
HH
226 # second, install the files needed to make the root filesystem
227 (
2f78bafa
HH
228 export initdir=$TESTDIR/overlay
229 . $basedir/dracut-init.sh
230 inst_multiple sfdisk mkfs.btrfs btrfs poweroff cp umount sync
231 inst_hook initqueue 01 ./create-root.sh
356333b3 232 inst_hook initqueue/finished 01 ./finished-false.sh
2f78bafa 233 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
badda27f
HH
234 )
235
236 # create an initramfs that will create the target root filesystem.
237 # We do it this way so that we do not risk trashing the host mdraid
238 # devices, volume groups, encrypted partitions, etc.
239 $basedir/dracut.sh -l -i $TESTDIR/overlay / \
2f78bafa
HH
240 -m "bash udev-rules btrfs base rootfs-block fs-lib kernel-modules qemu" \
241 -d "piix ide-gd_mod ata_piix btrfs sd_mod" \
242 --nomdadmconf \
243 --nohardlink \
244 --no-hostonly-cmdline -N \
245 -f $TESTDIR/initramfs.makeroot $KVERSION || return 1
badda27f
HH
246
247 # Invoke KVM and/or QEMU to actually create the target filesystem.
32bd2fbb 248 rm -rf -- $TESTDIR/overlay
badda27f
HH
249
250 $testdir/run-qemu \
2f78bafa
HH
251 -drive format=raw,index=0,media=disk,file=$TESTDIR/root.btrfs \
252 -drive format=raw,index=1,media=disk,file=$TESTDIR/usr.btrfs \
2f78bafa
HH
253 -append "root=/dev/fakeroot rw rootfstype=btrfs quiet console=ttyS0,115200n81 selinux=0" \
254 -initrd $TESTDIR/initramfs.makeroot || return 1
074ac625
HH
255 if ! grep -F -m 1 -q dracut-root-block-created $TESTDIR/root.btrfs; then
256 echo "Could not create root filesystem"
257 return 1
258 fi
badda27f
HH
259
260 (
2f78bafa
HH
261 export initdir=$TESTDIR/overlay
262 . $basedir/dracut-init.sh
263 inst_multiple poweroff shutdown
264 inst_hook shutdown-emergency 000 ./hard-off.sh
781f1971 265 inst_hook emergency 000 ./hard-off.sh
2f78bafa 266 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
badda27f 267 )
b8bccd39
HH
268
269 [ -e /etc/machine-id ] && EXTRA_MACHINE="/etc/machine-id"
270 [ -e /etc/machine-info ] && EXTRA_MACHINE+=" /etc/machine-info"
271
4bd0ab61 272 $basedir/dracut.sh -l -i $TESTDIR/overlay / \
2f78bafa
HH
273 -a "debug systemd i18n qemu" \
274 ${EXTRA_MACHINE:+-I "$EXTRA_MACHINE"} \
275 -o "dash network plymouth lvm mdraid resume crypt caps dm terminfo usrmount kernel-network-modules rngd" \
276 -d "piix ide-gd_mod ata_piix btrfs sd_mod i6300esb ib700wdt" \
277 --no-hostonly-cmdline -N \
278 -f $TESTDIR/initramfs.testing $KVERSION || return 1
badda27f 279
32bd2fbb 280 rm -rf -- $TESTDIR/overlay
badda27f
HH
281}
282
283test_cleanup() {
284 return 0
285}
286
287. $testdir/test-functions