]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-13-ENC-RAID-LVM/test.sh
93d48a59a0ec6bd440ff7083b06c735de233706f
[thirdparty/dracut.git] / test / TEST-13-ENC-RAID-LVM / test.sh
1 #!/bin/bash
2 TEST_DESCRIPTION="root filesystem on LVM on encrypted partitions of a RAID-5"
3
4 KVERSION=${KVERSION-$(uname -r)}
5
6 # Uncomment this to debug failures
7 #DEBUGFAIL="rd.shell rd.break" # udev.log-priority=debug
8 #DEBUGFAIL="rd.shell rd.udev.log-priority=debug loglevel=70 systemd.log_target=kmsg systemd.log_target=debug"
9 #DEBUGFAIL="rd.shell loglevel=70 systemd.log_target=kmsg systemd.log_target=debug"
10
11 test_run() {
12 LUKSARGS=$(cat $TESTDIR/luks.txt)
13
14 dd if=/dev/zero of=$TESTDIR/check-success.img bs=1M count=1
15
16 echo "CLIENT TEST START: $LUKSARGS"
17 $testdir/run-qemu \
18 -hda $TESTDIR/root.ext2 \
19 -hdb $TESTDIR/check-success.img \
20 -m 256M -smp 2 -nographic \
21 -net none -kernel /boot/vmlinuz-$KVERSION \
22 -append "root=/dev/dracut/root rw rd.auto rd.retry=20 console=ttyS0,115200n81 selinux=0 rd.debug rootwait $LUKSARGS $DEBUGFAIL" \
23 -initrd $TESTDIR/initramfs.testing
24 grep -F -m 1 -q dracut-root-block-success $TESTDIR/check-success.img || return 1
25 echo "CLIENT TEST END: [OK]"
26
27 dd if=/dev/zero of=$TESTDIR/check-success.img bs=1M count=1
28
29 echo "CLIENT TEST START: Any LUKS"
30 $testdir/run-qemu \
31 -hda $TESTDIR/root.ext2 \
32 -hdb $TESTDIR/check-success.img \
33 -m 256M -smp 2 -nographic \
34 -net none -kernel /boot/vmlinuz-$KVERSION \
35 -append "root=/dev/dracut/root rw quiet rd.auto rd.retry=20 rd.info console=ttyS0,115200n81 selinux=0 rd.debug $DEBUGFAIL" \
36 -initrd $TESTDIR/initramfs.testing
37 grep -F -m 1 -q dracut-root-block-success $TESTDIR/check-success.img || return 1
38 echo "CLIENT TEST END: [OK]"
39
40 dd if=/dev/zero of=$TESTDIR/check-success.img bs=1M count=1
41
42 echo "CLIENT TEST START: Wrong LUKS UUID"
43 $testdir/run-qemu \
44 -hda $TESTDIR/root.ext2 \
45 -hdb $TESTDIR/check-success.img \
46 -m 256M -smp 2 -nographic \
47 -net none -kernel /boot/vmlinuz-$KVERSION \
48 -append "root=/dev/dracut/root rw quiet rd.auto rd.retry=10 rd.info console=ttyS0,115200n81 selinux=0 rd.debug $DEBUGFAIL rd.luks.uuid=failme" \
49 -initrd $TESTDIR/initramfs.testing
50 grep -F -m 1 -q dracut-root-block-success $TESTDIR/check-success.img && return 1
51 echo "CLIENT TEST END: [OK]"
52
53 return 0
54 }
55
56 test_setup() {
57 # Create the blank file to use as a root filesystem
58 rm -f $TESTDIR/root.ext2
59 dd if=/dev/null of=$TESTDIR/root.ext2 bs=1M seek=80
60
61 kernel=$KVERSION
62 # Create what will eventually be our root filesystem onto an overlay
63 (
64 export initdir=$TESTDIR/overlay/source
65 . $basedir/dracut-functions.sh
66 dracut_install sh df free ls shutdown poweroff stty cat ps ln ip route \
67 mount dmesg ifconfig dhclient mkdir cp ping dhclient
68 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
69 [ -f ${_terminfodir}/l/linux ] && break
70 done
71 dracut_install -o ${_terminfodir}/l/linux
72 inst "$basedir/modules.d/40network/dhclient-script.sh" "/sbin/dhclient-script"
73 inst "$basedir/modules.d/40network/ifup.sh" "/sbin/ifup"
74 dracut_install grep
75 inst_simple /etc/os-release
76 inst ./test-init.sh /sbin/init
77 find_binary plymouth >/dev/null && dracut_install plymouth
78 (cd "$initdir"; mkdir -p dev sys proc etc var/run tmp )
79 cp -a /etc/ld.so.conf* $initdir/etc
80 sudo ldconfig -r "$initdir"
81 )
82
83 # second, install the files needed to make the root filesystem
84 (
85 export initdir=$TESTDIR/overlay
86 . $basedir/dracut-functions.sh
87 dracut_install sfdisk mke2fs poweroff cp umount grep
88 inst_hook initqueue 01 ./create-root.sh
89 inst_hook initqueue/finished 01 ./finished-false.sh
90 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
91 )
92
93 # create an initramfs that will create the target root filesystem.
94 # We do it this way so that we do not risk trashing the host mdraid
95 # devices, volume groups, encrypted partitions, etc.
96 $basedir/dracut.sh -l -i $TESTDIR/overlay / \
97 -m "dash crypt lvm mdraid udev-rules base rootfs-block kernel-modules" \
98 -d "piix ide-gd_mod ata_piix ext2 sd_mod" \
99 -f $TESTDIR/initramfs.makeroot $KVERSION || return 1
100 rm -rf $TESTDIR/overlay
101 # Invoke KVM and/or QEMU to actually create the target filesystem.
102 $testdir/run-qemu -hda $TESTDIR/root.ext2 -m 256M -smp 2 -nographic -net none \
103 -kernel "/boot/vmlinuz-$kernel" \
104 -append "root=/dev/fakeroot rw rootfstype=ext2 quiet console=ttyS0,115200n81 selinux=0" \
105 -initrd $TESTDIR/initramfs.makeroot || return 1
106 grep -F -m 1 -q dracut-root-block-created $TESTDIR/root.ext2 || return 1
107 cryptoUUIDS=$(grep -F --binary-files=text -m 3 ID_FS_UUID $TESTDIR/root.ext2)
108 for uuid in $cryptoUUIDS; do
109 eval $uuid
110 printf ' rd.luks.uuid=luks-%s ' $ID_FS_UUID
111 done > $TESTDIR/luks.txt
112
113
114 (
115 export initdir=$TESTDIR/overlay
116 . $basedir/dracut-functions.sh
117 dracut_install poweroff shutdown
118 inst_hook emergency 000 ./hard-off.sh
119 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
120 inst ./cryptroot-ask.sh /sbin/cryptroot-ask
121 mkdir -p $initdir/etc
122 i=2
123 for uuid in $cryptoUUIDS; do
124 eval $uuid
125 printf 'luks-%s /dev/sda%s /etc/key timeout=0\n' $ID_FS_UUID $i
126 ((i+=1))
127 done > $initdir/etc/crypttab
128 echo -n test > $initdir/etc/key
129 )
130 sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
131 -o "plymouth network" \
132 -a "debug" \
133 -d "piix ide-gd_mod ata_piix ext2 sd_mod" \
134 -f $TESTDIR/initramfs.testing $KVERSION || return 1
135 }
136
137 test_cleanup() {
138 return 0
139 }
140
141 . $testdir/test-functions