]> git.ipfire.org Git - thirdparty/dracut.git/blame - test/TEST-04-FULL-SYSTEMD/test.sh
Merge pull request #180 from danimo/tests_find_kvm_on_suse
[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 \
4358ace4
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 \
bdd62605 23 -m 256M -smp 2 -nographic \
1d84d694 24 -net none \
36867f1a
HH
25 -no-reboot \
26 -append "panic=1 root=LABEL=dracut $client_opts rd.retry=3 console=ttyS0,115200n81 selinux=0 $DEBUGOUT rd.shell=0 $DEBUGFAIL" \
badda27f
HH
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
021b2fdd 34 if ! grep -F -m 1 -q dracut-root-block-success $TESTDIR/result; then
badda27f
HH
35 echo "CLIENT TEST END: $test_name [FAILED]"
36 return 1
37 fi
38 echo "CLIENT TEST END: $test_name [OK]"
39
40}
41
42test_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
49test_setup() {
32bd2fbb
HH
50 rm -f -- $TESTDIR/root.btrfs
51 rm -f -- $TESTDIR/usr.btrfs
badda27f
HH
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
cc68f78d 56 export kernel=$KVERSION
badda27f
HH
57 # Create what will eventually be our root filesystem onto an overlay
58 (
59 export initdir=$TESTDIR/overlay/source
60 mkdir -p $initdir
777f2db0 61 . $basedir/dracut-init.sh
badda27f 62
3d115217 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
badda27f
HH
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
fd790546
DM
74 inst_multiple sh df free ls shutdown poweroff stty cat ps ln ip \
75 mount dmesg dhclient mkdir cp ping dhclient \
1d84d694 76 umount strace less setsid tree systemctl reset
3d115217 77
badda27f
HH
78 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
79 [ -f ${_terminfodir}/l/linux ] && break
80 done
af119460 81 inst_multiple -o ${_terminfodir}/l/linux
badda27f
HH
82 inst "$basedir/modules.d/40network/dhclient-script.sh" "/sbin/dhclient-script"
83 inst "$basedir/modules.d/40network/ifup.sh" "/sbin/ifup"
af119460 84 inst_multiple grep
badda27f 85 inst_simple ./fstab /etc/fstab
ffc68f35 86 rpm -ql systemd | xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -o -a -l
83691c41
HH
87 inst /lib/systemd/system/systemd-remount-fs.service
88 inst /lib/systemd/systemd-remount-fs
badda27f
HH
89 inst /lib/systemd/system/systemd-journal-flush.service
90 inst /etc/sysconfig/init
1d84d694
HH
91 inst /lib/systemd/system/slices.target
92 inst /lib/systemd/system/system.slice
af119460 93 inst_multiple -o /lib/systemd/system/dracut*
badda27f
HH
94
95 # make a journal directory
96 mkdir -p $initdir/var/log/journal
97
98 # install some basic config files
af119460 99 inst_multiple -o \
1d84d694
HH
100 /etc/machine-id \
101 /etc/adjtime \
badda27f
HH
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
badda27f
HH
115
116 # setup the testsuite target
117 cat >$initdir/etc/systemd/system/testsuite.target <<EOF
118[Unit]
119Description=Testsuite target
3d115217
HH
120Requires=basic.target
121After=basic.target
badda27f
HH
122Conflicts=rescue.target
123AllowIsolate=yes
124EOF
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]
131Description=Testsuite service
3d115217 132After=basic.target
badda27f
HH
133
134[Service]
135ExecStart=/sbin/test-init
badda27f 136Type=oneshot
3d115217
HH
137StandardInput=tty
138StandardOutput=tty
badda27f
HH
139EOF
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
665b7e58
HH
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
badda27f
HH
151
152 # install basic tools needed
af119460 153 inst_multiple sh bash setsid loadkeys setfont \
badda27f 154 login sushell sulogin gzip sleep echo mount umount
af119460 155 inst_multiple modprobe
badda27f
HH
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 \
6d58fa27 167 | while read file || [ -n "$file" ]; do
af119460 168 inst_multiple -o $file
badda27f
HH
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
9ee2f1e2
HH
175 (
176 echo "FONT=latarcyrheb-sun16"
177 echo "KEYMAP=us"
178 ) >$initrd/etc/vconsole.conf
179
badda27f
HH
180 # install basic keyboard maps and fonts
181 for i in \
b4fb539c 182 /usr/lib/kbd/consolefonts/eurlatgr* \
badda27f 183 /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
9ee2f1e2
HH
184 /usr/lib/kbd/keymaps/{legacy/,/}include/* \
185 /usr/lib/kbd/keymaps/{legacy/,/}i386/include/* \
186 /usr/lib/kbd/keymaps/{legacy/,/}i386/qwerty/us.*; do
badda27f
HH
187 [[ -f $i ]] || continue
188 inst $i
189 done
190
191 # some basic terminfo files
192 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
193 [ -f ${_terminfodir}/l/linux ] && break
194 done
af119460 195 inst_multiple -o ${_terminfodir}/l/linux
badda27f
HH
196
197 # softlink mtab
198 ln -fs /proc/self/mounts $initdir/etc/mtab
199
2a5a7fb6 200 # install any Execs from the service files
9430ae30 201 grep -Eho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
6d58fa27 202 | while read i || [ -n "$i" ]; do
badda27f 203 i=${i##Exec*=}; i=${i##-}
af119460 204 inst_multiple -o $i
badda27f
HH
205 done
206
207 # some helper tools for debugging
af119460 208 [[ $DEBUGTOOLS ]] && inst_multiple $DEBUGTOOLS
badda27f
HH
209
210 # install ld.so.conf* and run ldconfig
211 cp -a /etc/ld.so.conf* $initdir/etc
212 ldconfig -r "$initdir"
213 ddebug "Strip binaeries"
2a5a7fb6 214 find "$initdir" -perm /0111 -type f | xargs -r strip --strip-unneeded | ddebug
badda27f
HH
215
216 # copy depmod files
cc68f78d
HH
217 inst /lib/modules/$kernel/modules.order
218 inst /lib/modules/$kernel/modules.builtin
badda27f 219 # generate module dependencies
cc68f78d
HH
220 if [[ -d $initdir/lib/modules/$kernel ]] && \
221 ! depmod -a -b "$initdir" $kernel; then
222 dfatal "\"depmod -a $kernel\" failed."
badda27f
HH
223 exit 1
224 fi
225
226 )
b0d844fa 227
badda27f
HH
228 # second, install the files needed to make the root filesystem
229 (
230 export initdir=$TESTDIR/overlay
777f2db0 231 . $basedir/dracut-init.sh
af119460 232 inst_multiple sfdisk mkfs.btrfs btrfs poweroff cp umount sync
badda27f 233 inst_hook initqueue 01 ./create-root.sh
356333b3 234 inst_hook initqueue/finished 01 ./finished-false.sh
badda27f
HH
235 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
236 )
237
238 # create an initramfs that will create the target root filesystem.
239 # We do it this way so that we do not risk trashing the host mdraid
240 # devices, volume groups, encrypted partitions, etc.
241 $basedir/dracut.sh -l -i $TESTDIR/overlay / \
eda73c0a 242 -m "dash udev-rules btrfs base rootfs-block fs-lib kernel-modules" \
badda27f
HH
243 -d "piix ide-gd_mod ata_piix btrfs sd_mod" \
244 --nomdadmconf \
245 --nohardlink \
e3e1f406 246 --no-hostonly-cmdline -N \
badda27f
HH
247 -f $TESTDIR/initramfs.makeroot $KVERSION || return 1
248
249 # Invoke KVM and/or QEMU to actually create the target filesystem.
32bd2fbb 250 rm -rf -- $TESTDIR/overlay
badda27f
HH
251
252 $testdir/run-qemu \
4358ace4
HH
253 -drive format=raw,index=0,media=disk,file=$TESTDIR/root.btrfs \
254 -drive format=raw,index=1,media=disk,file=$TESTDIR/usr.btrfs \
bdd62605 255 -m 256M -smp 2 -nographic -net none \
bb278147 256 -append "root=/dev/fakeroot rw rootfstype=btrfs quiet console=ttyS0,115200n81 selinux=0" \
badda27f 257 -initrd $TESTDIR/initramfs.makeroot || return 1
021b2fdd 258 grep -F -m 1 -q dracut-root-block-created $TESTDIR/root.btrfs || return 1
badda27f
HH
259
260
261 (
262 export initdir=$TESTDIR/overlay
777f2db0 263 . $basedir/dracut-init.sh
af119460 264 inst_multiple poweroff shutdown
4e882b80 265 inst_hook shutdown-emergency 000 ./hard-off.sh
781f1971 266 inst_hook emergency 000 ./hard-off.sh
badda27f
HH
267 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
268 )
b8bccd39
HH
269
270 [ -e /etc/machine-id ] && EXTRA_MACHINE="/etc/machine-id"
271 [ -e /etc/machine-info ] && EXTRA_MACHINE+=" /etc/machine-info"
272
badda27f 273 sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
9ee2f1e2 274 -a "debug systemd i18n" \
b8bccd39 275 ${EXTRA_MACHINE:+-I "$EXTRA_MACHINE"} \
9ee2f1e2 276 -o "dash network plymouth lvm mdraid resume crypt caps dm terminfo usrmount kernel-network-modules" \
665b7e58 277 -d "piix ide-gd_mod ata_piix btrfs sd_mod i6300esb ib700wdt" \
e3e1f406 278 --no-hostonly-cmdline -N \
badda27f
HH
279 -f $TESTDIR/initramfs.testing $KVERSION || return 1
280
32bd2fbb 281 rm -rf -- $TESTDIR/overlay
badda27f
HH
282}
283
284test_cleanup() {
285 return 0
286}
287
288. $testdir/test-functions