2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4 TEST_DESCRIPTION="cryptsetup systemd setup"
6 KVERSION=${KVERSION-$(uname -r)}
9 # Uncomment this to debug failures
10 #DEBUGFAIL="systemd.unit=multi-user.target"
11 DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort"
14 # TODO: qemu wrapper script: http://www.spinics.net/lists/kvm/msg72389.html
16 -hda $TESTDIR/rootdisk.img \
18 -net none -kernel /boot/vmlinuz-$KERNEL_VER \
19 -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd ro console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" || return 1
22 mkdir -p $TESTDIR/root
23 mount ${LOOPDEV}p1 $TESTDIR/root
24 [[ -e $TESTDIR/root/testok ]] && ret=0
25 cp -a $TESTDIR/root/failed $TESTDIR
26 cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile
27 mount /dev/mapper/varcrypt $TESTDIR/root/var
28 cp -a $TESTDIR/root/var/log/journal $TESTDIR
29 umount $TESTDIR/root/var
31 cryptsetup luksClose /dev/mapper/varcrypt
33 ls -l $TESTDIR/journal/*/*.journal
34 test -s $TESTDIR/failed && ret=$(($ret+1))
43 dwarn "can't run qemu-kvm, skipping"
49 rm -f $TESTDIR/rootdisk.img
50 # Create the blank file to use as a root filesystem
51 dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=200
52 LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
53 [ -b $LOOPDEV ] || return 1
54 echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
55 sfdisk -C 6400 -H 2 -S 32 -L $LOOPDEV <<EOF
60 mkfs.ext3 -L systemd ${LOOPDEV}p1
61 echo -n test >$TESTDIR/keyfile
62 cryptsetup -q luksFormat ${LOOPDEV}p2 $TESTDIR/keyfile
63 cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile
64 mkfs.ext3 -L var /dev/mapper/varcrypt
65 mkdir -p $TESTDIR/root
66 mount ${LOOPDEV}p1 $TESTDIR/root
67 mkdir -p $TESTDIR/root/run
68 mkdir -p $TESTDIR/root/var
69 mount /dev/mapper/varcrypt $TESTDIR/root/var
71 # Create what will eventually be our root filesystem onto an overlay
76 # create the basic filesystem layout
79 # install compiled files
80 (cd ../..; make DESTDIR=$initdir install)
82 # remove unneeded documentation
83 rm -fr $initdir/usr/share/{man,doc,gtk-doc}
85 # install possible missing libraries
86 for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
90 # make a journal directory
91 mkdir -p $initdir/var/log/journal
93 # install some basic config files
94 inst /etc/sysconfig/init
99 inst /etc/nsswitch.conf
104 # we want an empty environment
105 > $initdir/etc/environment
106 > $initdir/etc/machine-id
109 echo systemd-testsuite > $initdir/etc/hostname
111 eval $(udevadm info --export --query=env --name=/dev/mapper/varcrypt)
112 eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
114 cat >$initdir/etc/crypttab <<EOF
115 $DM_NAME UUID=$ID_FS_UUID /etc/varkey
117 echo -n test > $initdir/etc/varkey
118 cat $initdir/etc/crypttab | ddebug
120 cat >$initdir/etc/fstab <<EOF
121 LABEL=systemd / ext3 rw 0 1
122 /dev/mapper/varcrypt /var ext3 defaults 0 1
125 # setup the testsuite target
126 cat >$initdir/etc/systemd/system/testsuite.target <<EOF
128 Description=Testsuite target
129 Requires=multi-user.target
130 After=multi-user.target
131 Conflicts=rescue.target
135 # setup the testsuite service
136 cat >$initdir/etc/systemd/system/testsuite.service <<EOF
138 Description=Testsuite service
139 After=multi-user.target
142 ExecStart=/bin/bash -c 'set -x; systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok; while : ;do systemd-cat echo "testsuite service waiting for /var/log/journal" ; echo "testsuite service waiting for journal to move to /var/log/journal" > /dev/console ; for i in /var/log/journal/*;do [ -d "\$i" ] && echo "\$i" && break 2; done; sleep 1; done; sleep 1; exit 0;'
143 ExecStopPost=/usr/bin/systemctl poweroff
146 mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
147 ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
149 # make the testsuite the default target
150 ln -fs testsuite.target $initdir/etc/systemd/system/default.target
151 mkdir -p $initdir/etc/rc.d
152 cat >$initdir/etc/rc.d/rc.local <<EOF
156 chmod 0755 $initdir/etc/rc.d/rc.local
157 # install basic tools needed
158 dracut_install sh bash setsid loadkeys setfont \
159 login sushell sulogin gzip sleep echo mount umount cryptsetup
160 dracut_install dmsetup modprobe
162 instmods dm_crypt =crypto
164 type -P dmeventd >/dev/null && dracut_install dmeventd
166 inst_libdir_file "libdevmapper-event.so*"
168 inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
170 # install libnss_files for login
171 inst_libdir_file "libnss_files*"
173 # install dbus and pam
179 /lib/security -xtype f \
180 | while read file; do
184 # install dbus socket and service file
185 inst /usr/lib/systemd/system/dbus.socket
186 inst /usr/lib/systemd/system/dbus.service
188 # install basic keyboard maps and fonts
190 /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
191 /usr/lib/kbd/keymaps/include/* \
192 /usr/lib/kbd/keymaps/i386/include/* \
193 /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
194 [[ -f $i ]] || continue
198 # some basic terminfo files
199 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
200 [ -f ${_terminfodir}/l/linux ] && break
202 dracut_install -o ${_terminfodir}/l/linux
205 ln -fs /proc/self/mounts $initdir/etc/mtab
207 # install any Exec's from the service files
208 egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
210 i=${i##Exec*=}; i=${i##-}
214 # install plymouth, if found... else remove plymouth service files
215 # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
216 # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
217 # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
218 # dracut_install plymouth plymouthd
220 rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
223 # some helper tools for debugging
224 [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
226 # install ld.so.conf* and run ldconfig
227 cp -a /etc/ld.so.conf* $initdir/etc
228 ldconfig -r "$initdir"
229 ddebug "Strip binaeries"
230 find "$initdir" -perm +111 -type f | xargs strip --strip-unneeded | ddebug
233 inst /lib/modules/$KERNEL_VER/modules.order
234 inst /lib/modules/$KERNEL_VER/modules.builtin
235 # generate module dependencies
236 if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
237 ! depmod -a -b "$initdir" $KERNEL_VER; then
238 dfatal "\"depmod -a $KERNEL_VER\" failed."
242 rm -fr $TESTDIR/nspawn-root
243 ddebug "cp -ar $TESTDIR/root $TESTDIR/nspawn-root"
244 cp -ar $TESTDIR/root $TESTDIR/nspawn-root
245 # we don't mount in the nspawn root
246 rm -fr $TESTDIR/nspawn-root/etc/fstab
248 ddebug "umount $TESTDIR/root/var"
249 umount $TESTDIR/root/var
250 cryptsetup luksClose /dev/mapper/varcrypt
251 ddebug "umount $TESTDIR/root"
256 umount $TESTDIR/root/var 2>/dev/null
257 [[ -b /dev/mapper/varcrypt ]] && cryptsetup luksClose /dev/mapper/varcrypt
258 umount $TESTDIR/root 2>/dev/null
259 [[ $LOOPDEV ]] && losetup -d $LOOPDEV
263 . $TEST_BASE_DIR/test-functions