]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-04-FULL-SYSTEMD/test.sh
Use eurlatgr as default console font
[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 dhclient mkdir cp ping dhclient \
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 "$basedir/modules.d/35network-legacy/dhclient-script.sh" "/sbin/dhclient-script"
83 inst "$basedir/modules.d/35network-legacy/ifup.sh" "/sbin/ifup"
84 inst_multiple grep
85 inst_simple ./fstab /etc/fstab
86 rpm -ql systemd | xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -o -a -l
87 inst /lib/systemd/system/systemd-remount-fs.service
88 inst /lib/systemd/systemd-remount-fs
89 inst /lib/systemd/system/systemd-journal-flush.service
90 inst /etc/sysconfig/init
91 inst /lib/systemd/system/slices.target
92 inst /lib/systemd/system/system.slice
93 inst_multiple -o /lib/systemd/system/dracut*
94
95 # make a journal directory
96 mkdir -p $initdir/var/log/journal
97
98 # install some basic config files
99 inst_multiple -o \
100 /etc/machine-id \
101 /etc/adjtime \
102 /etc/sysconfig/init \
103 /etc/passwd \
104 /etc/shadow \
105 /etc/group \
106 /etc/shells \
107 /etc/nsswitch.conf \
108 /etc/pam.conf \
109 /etc/securetty \
110 /etc/os-release \
111 /etc/localtime
112
113 # we want an empty environment
114 > $initdir/etc/environment
115
116 # setup the testsuite target
117 cat >$initdir/etc/systemd/system/testsuite.target <<EOF
118 [Unit]
119 Description=Testsuite target
120 Requires=basic.target
121 After=basic.target
122 Conflicts=rescue.target
123 AllowIsolate=yes
124 EOF
125
126 inst ./test-init.sh /sbin/test-init
127
128 # setup the testsuite service
129 cat >$initdir/etc/systemd/system/testsuite.service <<EOF
130 [Unit]
131 Description=Testsuite service
132 After=basic.target
133
134 [Service]
135 ExecStart=/sbin/test-init
136 Type=oneshot
137 StandardInput=tty
138 StandardOutput=tty
139 EOF
140 mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
141 ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
142
143 # make the testsuite the default target
144 ln -fs testsuite.target $initdir/etc/systemd/system/default.target
145
146 # mkdir -p $initdir/etc/rc.d
147 # cat >$initdir/etc/rc.d/rc.local <<EOF
148 # #!/bin/bash
149 # exit 0
150 # EOF
151
152 # install basic tools needed
153 inst_multiple sh bash setsid loadkeys setfont \
154 login sushell sulogin gzip sleep echo mount umount
155 inst_multiple modprobe
156
157 # install libnss_files for login
158 inst_libdir_file "libnss_files*"
159
160 # install dbus and pam
161 find \
162 /etc/dbus-1 \
163 /etc/pam.d \
164 /etc/security \
165 /lib64/security \
166 /lib/security -xtype f \
167 | while read file || [ -n "$file" ]; do
168 inst_multiple -o $file
169 done
170
171 # install dbus socket and service file
172 inst /usr/lib/systemd/system/dbus.socket
173 inst /usr/lib/systemd/system/dbus.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
225 )
226
227 # second, install the files needed to make the root filesystem
228 (
229 export initdir=$TESTDIR/overlay
230 . $basedir/dracut-init.sh
231 inst_multiple sfdisk mkfs.btrfs btrfs poweroff cp umount sync
232 inst_hook initqueue 01 ./create-root.sh
233 inst_hook initqueue/finished 01 ./finished-false.sh
234 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
235 )
236
237 # create an initramfs that will create the target root filesystem.
238 # We do it this way so that we do not risk trashing the host mdraid
239 # devices, volume groups, encrypted partitions, etc.
240 $basedir/dracut.sh -l -i $TESTDIR/overlay / \
241 -m "dash udev-rules btrfs base rootfs-block fs-lib kernel-modules" \
242 -d "piix ide-gd_mod ata_piix btrfs sd_mod" \
243 --nomdadmconf \
244 --nohardlink \
245 --no-hostonly-cmdline -N \
246 -f $TESTDIR/initramfs.makeroot $KVERSION || return 1
247
248 # Invoke KVM and/or QEMU to actually create the target filesystem.
249 rm -rf -- $TESTDIR/overlay
250
251 $testdir/run-qemu \
252 -drive format=raw,index=0,media=disk,file=$TESTDIR/root.btrfs \
253 -drive format=raw,index=1,media=disk,file=$TESTDIR/usr.btrfs \
254 -m 512M -smp 2 -nographic -net none \
255 -append "root=/dev/fakeroot rw rootfstype=btrfs quiet console=ttyS0,115200n81 selinux=0" \
256 -initrd $TESTDIR/initramfs.makeroot || return 1
257 grep -F -m 1 -q dracut-root-block-created $TESTDIR/root.btrfs || return 1
258
259
260 (
261 export initdir=$TESTDIR/overlay
262 . $basedir/dracut-init.sh
263 inst_multiple poweroff shutdown
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 sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
273 -a "debug systemd i18n" \
274 ${EXTRA_MACHINE:+-I "$EXTRA_MACHINE"} \
275 -o "dash network plymouth lvm mdraid resume crypt caps dm terminfo usrmount kernel-network-modules" \
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