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