]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-04-FULL-SYSTEMD/test.sh
Merge pull request #122 from scop/fixes
[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 256M -smp 2 -nographic \
24 -net none \
25 -append "root=LABEL=dracut $client_opts rd.retry=3 console=ttyS0,115200n81 selinux=0 $DEBUGOUT $DEBUGFAIL" \
26 -initrd $TESTDIR/initramfs.testing
27
28 if (($? != 0)); then
29 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
30 return 1
31 fi
32
33 if ! grep -F -m 1 -q dracut-root-block-success $TESTDIR/result; then
34 echo "CLIENT TEST END: $test_name [FAILED]"
35 return 1
36 fi
37 echo "CLIENT TEST END: $test_name [OK]"
38
39 }
40
41 test_run() {
42 client_run "no option specified" || return 1
43 client_run "readonly root" "ro" || return 1
44 client_run "writeable root" "rw" || return 1
45 return 0
46 }
47
48 test_setup() {
49 rm -f -- $TESTDIR/root.btrfs
50 rm -f -- $TESTDIR/usr.btrfs
51 # Create the blank file to use as a root filesystem
52 dd if=/dev/null of=$TESTDIR/root.btrfs bs=1M seek=320
53 dd if=/dev/null of=$TESTDIR/usr.btrfs bs=1M seek=320
54
55 export kernel=$KVERSION
56 # Create what will eventually be our root filesystem onto an overlay
57 (
58 export initdir=$TESTDIR/overlay/source
59 mkdir -p $initdir
60 . $basedir/dracut-init.sh
61
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
63 if [ -L "/$d" ]; then
64 inst_symlink "/$d"
65 else
66 inst_dir "/$d"
67 fi
68 done
69
70 ln -sfn /run "$initdir/var/run"
71 ln -sfn /run/lock "$initdir/var/lock"
72
73 inst_multiple sh df free ls shutdown poweroff stty cat ps ln ip route \
74 mount dmesg ifconfig dhclient mkdir cp ping dhclient \
75 umount strace less setsid tree systemctl reset
76
77 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
78 [ -f ${_terminfodir}/l/linux ] && break
79 done
80 inst_multiple -o ${_terminfodir}/l/linux
81 inst "$basedir/modules.d/40network/dhclient-script.sh" "/sbin/dhclient-script"
82 inst "$basedir/modules.d/40network/ifup.sh" "/sbin/ifup"
83 inst_multiple grep
84 inst_simple ./fstab /etc/fstab
85 rpm -ql systemd | xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -o -a -l
86 inst /lib/systemd/system/systemd-remount-fs.service
87 inst /lib/systemd/systemd-remount-fs
88 inst /lib/systemd/system/systemd-journal-flush.service
89 inst /etc/sysconfig/init
90 inst /lib/systemd/system/slices.target
91 inst /lib/systemd/system/system.slice
92 inst_multiple -o /lib/systemd/system/dracut*
93
94 # make a journal directory
95 mkdir -p $initdir/var/log/journal
96
97 # install some basic config files
98 inst_multiple -o \
99 /etc/machine-id \
100 /etc/adjtime \
101 /etc/sysconfig/init \
102 /etc/passwd \
103 /etc/shadow \
104 /etc/group \
105 /etc/shells \
106 /etc/nsswitch.conf \
107 /etc/pam.conf \
108 /etc/securetty \
109 /etc/os-release \
110 /etc/localtime
111
112 # we want an empty environment
113 > $initdir/etc/environment
114
115 # setup the testsuite target
116 cat >$initdir/etc/systemd/system/testsuite.target <<EOF
117 [Unit]
118 Description=Testsuite target
119 Requires=basic.target
120 After=basic.target
121 Conflicts=rescue.target
122 AllowIsolate=yes
123 EOF
124
125 inst ./test-init.sh /sbin/test-init
126
127 # setup the testsuite service
128 cat >$initdir/etc/systemd/system/testsuite.service <<EOF
129 [Unit]
130 Description=Testsuite service
131 After=basic.target
132
133 [Service]
134 ExecStart=/sbin/test-init
135 Type=oneshot
136 StandardInput=tty
137 StandardOutput=tty
138 EOF
139 mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
140 ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
141
142 # make the testsuite the default target
143 ln -fs testsuite.target $initdir/etc/systemd/system/default.target
144
145 # mkdir -p $initdir/etc/rc.d
146 # cat >$initdir/etc/rc.d/rc.local <<EOF
147 # #!/bin/bash
148 # exit 0
149 # EOF
150
151 # install basic tools needed
152 inst_multiple sh bash setsid loadkeys setfont \
153 login sushell sulogin gzip sleep echo mount umount
154 inst_multiple modprobe
155
156 # install libnss_files for login
157 inst_libdir_file "libnss_files*"
158
159 # install dbus and pam
160 find \
161 /etc/dbus-1 \
162 /etc/pam.d \
163 /etc/security \
164 /lib64/security \
165 /lib/security -xtype f \
166 | while read file || [ -n "$file" ]; do
167 inst_multiple -o $file
168 done
169
170 # install dbus socket and service file
171 inst /usr/lib/systemd/system/dbus.socket
172 inst /usr/lib/systemd/system/dbus.service
173
174 (
175 echo "FONT=latarcyrheb-sun16"
176 echo "KEYMAP=us"
177 ) >$initrd/etc/vconsole.conf
178
179 # install basic keyboard maps and fonts
180 for i in \
181 /usr/lib/kbd/consolefonts/eurlatgr* \
182 /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
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 256M -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 emergency 000 ./hard-off.sh
265 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
266 )
267
268 [ -e /etc/machine-id ] && EXTRA_MACHINE="/etc/machine-id"
269 [ -e /etc/machine-info ] && EXTRA_MACHINE+=" /etc/machine-info"
270
271 sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
272 -a "debug systemd i18n" \
273 ${EXTRA_MACHINE:+-I "$EXTRA_MACHINE"} \
274 -o "dash network plymouth lvm mdraid resume crypt caps dm terminfo usrmount kernel-network-modules" \
275 -d "piix ide-gd_mod ata_piix btrfs sd_mod i6300esb ib700wdt" \
276 --no-hostonly-cmdline -N \
277 -f $TESTDIR/initramfs.testing $KVERSION || return 1
278
279 rm -rf -- $TESTDIR/overlay
280 }
281
282 test_cleanup() {
283 return 0
284 }
285
286 . $testdir/test-functions