]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-04-FULL-SYSTEMD/test.sh
test: use dd to write status to marker disk
[thirdparty/dracut.git] / test / TEST-04-FULL-SYSTEMD / test.sh
1 #!/bin/bash
2
3 TEST_DESCRIPTION="Full systemd serialization/deserialization test with /usr mount"
4
5 export KVERSION=${KVERSION-$(uname -r)}
6
7 # Uncomment this to debug failures
8 #DEBUGFAIL="rd.shell rd.break"
9 #DEBUGFAIL="rd.shell"
10 #DEBUGOUT="quiet systemd.log_level=debug systemd.log_target=console loglevel=77 rd.info rd.debug"
11 DEBUGOUT="loglevel=0 "
12 client_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 \
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 \
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
25
26 if (($? != 0)); then
27 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
28 return 1
29 fi
30
31 if ! grep -F -m 1 -q dracut-root-block-success $TESTDIR/result; then
32 echo "CLIENT TEST END: $test_name [FAILED]"
33 return 1
34 fi
35 echo "CLIENT TEST END: $test_name [OK]"
36
37 }
38
39 test_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
46 test_setup() {
47 rm -f -- $TESTDIR/root.btrfs
48 rm -f -- $TESTDIR/usr.btrfs
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
53 export kernel=$KVERSION
54 # Create what will eventually be our root filesystem onto an overlay
55 (
56 export initdir=$TESTDIR/overlay/source
57 mkdir -p $initdir
58 . $basedir/dracut-init.sh
59
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
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
71 inst_multiple sh df free ls shutdown poweroff stty cat ps ln ip \
72 mount dmesg mkdir cp ping dd \
73 umount strace less setsid tree systemctl reset
74
75 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
76 [ -f ${_terminfodir}/l/linux ] && break
77 done
78 inst_multiple -o ${_terminfodir}/l/linux
79 inst_multiple grep
80 inst_simple ./fstab /etc/fstab
81 rpm -ql systemd | xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -o -a -l
82 inst /lib/systemd/system/systemd-remount-fs.service
83 inst /lib/systemd/systemd-remount-fs
84 inst /lib/systemd/system/systemd-journal-flush.service
85 inst /etc/sysconfig/init
86 inst /lib/systemd/system/slices.target
87 inst /lib/systemd/system/system.slice
88 inst_multiple -o /lib/systemd/system/dracut*
89
90 # make a journal directory
91 mkdir -p $initdir/var/log/journal
92
93 # install some basic config files
94 inst_multiple -o \
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
106
107 # we want an empty environment
108 > $initdir/etc/environment
109
110 # setup the testsuite target
111 mkdir -p $initdir/etc/systemd/system
112 cat >$initdir/etc/systemd/system/testsuite.target <<EOF
113 [Unit]
114 Description=Testsuite target
115 Requires=basic.target
116 After=basic.target
117 Conflicts=rescue.target
118 AllowIsolate=yes
119 EOF
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]
126 Description=Testsuite service
127 After=basic.target
128
129 [Service]
130 ExecStart=/sbin/test-init
131 Type=oneshot
132 StandardInput=tty
133 StandardOutput=tty
134 EOF
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
140
141 # mkdir -p $initdir/etc/rc.d
142 # cat >$initdir/etc/rc.d/rc.local <<EOF
143 # #!/bin/bash
144 # exit 0
145 # EOF
146
147 # install basic tools needed
148 inst_multiple sh bash setsid loadkeys setfont \
149 login sushell sulogin gzip sleep echo mount umount
150 inst_multiple modprobe
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 \
162 | while read file || [ -n "$file" ]; do
163 inst_multiple -o $file
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
169 inst /usr/lib/systemd/system/dbus-broker.service
170 inst /usr/lib/systemd/system/dbus-daemon.service
171
172 (
173 echo "FONT=eurlatgr"
174 echo "KEYMAP=us"
175 ) >$initrd/etc/vconsole.conf
176
177 # install basic keyboard maps and fonts
178 for i in \
179 /usr/lib/kbd/consolefonts/eurlatgr* \
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
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
191 inst_multiple -o ${_terminfodir}/l/linux
192
193 # softlink mtab
194 ln -fs /proc/self/mounts $initdir/etc/mtab
195
196 # install any Execs from the service files
197 grep -Eho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
198 | while read i || [ -n "$i" ]; do
199 i=${i##Exec*=}; i=${i##-}
200 inst_multiple -o $i
201 done
202
203 # some helper tools for debugging
204 [[ $DEBUGTOOLS ]] && inst_multiple $DEBUGTOOLS
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"
210 find "$initdir" -perm /0111 -type f | xargs -r strip --strip-unneeded | ddebug
211
212 # copy depmod files
213 inst /lib/modules/$kernel/modules.order
214 inst /lib/modules/$kernel/modules.builtin
215 # generate module dependencies
216 if [[ -d $initdir/lib/modules/$kernel ]] && \
217 ! depmod -a -b "$initdir" $kernel; then
218 dfatal "\"depmod -a $kernel\" failed."
219 exit 1
220 fi
221 # disable some services
222 systemctl --root "$initdir" mask systemd-update-utmp
223 systemctl --root "$initdir" mask systemd-tmpfiles-setup
224 )
225
226 # second, install the files needed to make the root filesystem
227 (
228 export initdir=$TESTDIR/overlay
229 . $basedir/dracut-init.sh
230 inst_multiple sfdisk mkfs.btrfs btrfs poweroff cp umount sync dd
231 inst_hook initqueue 01 ./create-root.sh
232 inst_hook initqueue/finished 01 ./finished-false.sh
233 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
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 / \
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
246
247 # Invoke KVM and/or QEMU to actually create the target filesystem.
248 rm -rf -- $TESTDIR/overlay
249
250 $testdir/run-qemu \
251 -drive format=raw,index=0,media=disk,file=$TESTDIR/root.btrfs \
252 -drive format=raw,index=1,media=disk,file=$TESTDIR/usr.btrfs \
253 -append "root=/dev/fakeroot rw rootfstype=btrfs quiet console=ttyS0,115200n81 selinux=0" \
254 -initrd $TESTDIR/initramfs.makeroot || return 1
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
259
260 (
261 export initdir=$TESTDIR/overlay
262 . $basedir/dracut-init.sh
263 inst_multiple poweroff shutdown dd
264 inst_hook shutdown-emergency 000 ./hard-off.sh
265 inst_hook emergency 000 ./hard-off.sh
266 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
267 )
268
269 [ -e /etc/machine-id ] && EXTRA_MACHINE="/etc/machine-id"
270 [ -e /etc/machine-info ] && EXTRA_MACHINE+=" /etc/machine-info"
271
272 $basedir/dracut.sh -l -i $TESTDIR/overlay / \
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
279
280 rm -rf -- $TESTDIR/overlay
281 }
282
283 test_cleanup() {
284 return 0
285 }
286
287 . $testdir/test-functions