TEST-12-RAID-DEG: check with root=LABEL=root
[platform/upstream/dracut.git] / test / TEST-12-RAID-DEG / test.sh
1 #!/bin/bash
2 TEST_DESCRIPTION="root filesystem on an encrypted LVM PV on a degraded RAID-5"
3
4 KVERSION=${KVERSION-$(uname -r)}
5
6 # Uncomment this to debug failures
7 #DEBUGFAIL="rdinitdebug rdnetdebug"
8
9 client_run() {
10     echo "CLIENT TEST START: $@"
11     $testdir/run-qemu -hda root.ext2 -m 256M -nographic \
12         -net none -kernel /boot/vmlinuz-$KVERSION \
13         -append "$@ root=LABEL=root rw quiet rdinfo console=ttyS0,115200n81 rdshell $DEBUGFAIL " \
14         -initrd initramfs.testing
15     if ! grep -m 1 -q dracut-root-block-success root.ext2; then
16         echo "CLIENT TEST END: $@ [FAIL]"
17         return 1;
18     fi
19
20     sed -i -e 's#dracut-root-block-success#dracut-root-block-xxxxxxx#' root.ext2
21     echo "CLIENT TEST END: $@ [OK]"
22     return 0
23 }
24
25 test_run() {
26     eval $(grep --binary-files=text -m 1 MD_UUID root.ext2)
27     echo "MD_UUID=$MD_UUID"
28
29     client_run || return 1
30
31     client_run rd_NO_LVM && return 1
32
33     client_run rd_LVM_VG=failme && return 1
34
35     client_run rd_LVM_VG=dracut || return 1
36
37     client_run rd_LVM_VG=dummy1 rd_LVM_VG=dracut rd_LVM_VG=dummy2 || return 1
38
39     client_run rd_MD_UUID=failme && return 1
40
41     client_run rd_NO_MD && return 1
42
43     client_run rd_MD_UUID=$MD_UUID || return 1
44
45     client_run rd_MD_UUID=dummy1 rd_MD_UUID=$MD_UUID rd_MD_UUID=dummy2 || return 1
46
47     return 0
48 }
49
50 test_setup() {
51     # Create the blank file to use as a root filesystem
52     dd if=/dev/zero of=root.ext2 bs=1M count=20
53
54     kernel=$KVERSION
55     # Create what will eventually be our root filesystem onto an overlay
56     (
57         initdir=overlay/source
58         . $basedir/dracut-functions
59         dracut_install sh df free ls shutdown poweroff stty cat ps ln ip route \
60             /lib/terminfo/l/linux mount dmesg ifconfig dhclient mkdir cp ping dhclient 
61         inst "$basedir/modules.d/40network/dhclient-script" "/sbin/dhclient-script"
62         inst "$basedir/modules.d/40network/ifup" "/sbin/ifup"
63         dracut_install grep
64         inst ./test-init /sbin/init
65         find_binary plymouth >/dev/null && dracut_install plymouth
66         (cd "$initdir"; mkdir -p dev sys proc etc var/run tmp )
67     )
68  
69     # second, install the files needed to make the root filesystem
70     (
71         initdir=overlay
72         . $basedir/dracut-functions
73         dracut_install sfdisk mke2fs poweroff cp umount dd
74         inst_simple ./create-root.sh /initqueue/01create-root.sh
75     )
76  
77     # create an initramfs that will create the target root filesystem.
78     # We do it this way so that we do not risk trashing the host mdraid
79     # devices, volume groups, encrypted partitions, etc.
80     $basedir/dracut -l -i overlay / \
81         -m "dash crypt lvm mdraid udev-rules base rootfs-block kernel-modules" \
82         -d "ata_piix ext2 sd_mod" \
83         -f initramfs.makeroot $KVERSION || return 1
84     rm -rf overlay
85     # Invoke KVM and/or QEMU to actually create the target filesystem.
86     $testdir/run-qemu -hda root.ext2 -m 256M -nographic -net none \
87         -kernel "/boot/vmlinuz-$kernel" \
88         -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81" \
89         -initrd initramfs.makeroot  || return 1
90     grep -m 1 -q dracut-root-block-created root.ext2 || return 1
91     (
92         initdir=overlay
93         . $basedir/dracut-functions
94         dracut_install poweroff shutdown
95         inst_simple ./hard-off.sh /emergency/01hard-off.sh
96         inst ./cryptroot-ask /sbin/cryptroot-ask
97     )
98     sudo $basedir/dracut -l -i overlay / \
99         -o "plymouth" \
100         -a "debug" \
101         -d "ata_piix ext2 sd_mod" \
102         -f initramfs.testing $KVERSION || return 1
103 }
104
105 test_cleanup() {
106     rm -fr overlay mnt
107     rm -f root.ext2 initramfs.makeroot initramfs.testing
108 }
109
110 . $testdir/test-functions