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