]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-03-USR-MOUNT/test.sh
dracut-functions.sh: inst_multiple == dracut_install
[thirdparty/dracut.git] / test / TEST-03-USR-MOUNT / test.sh
1 #!/bin/bash
2
3 TEST_DESCRIPTION="root filesystem on a btrfs filesystem with /usr subvolume"
4
5 KVERSION=${KVERSION-$(uname -r)}
6
7 # Uncomment this to debug failures
8 #DEBUGFAIL="rd.shell rd.break"
9
10 client_run() {
11 local test_name="$1"; shift
12 local client_opts="$*"
13
14 echo "CLIENT TEST START: $test_name"
15
16 dd if=/dev/zero of=$TESTDIR/result bs=1M count=1
17 $testdir/run-qemu \
18 -hda $TESTDIR/root.btrfs \
19 -hdb $TESTDIR/usr.btrfs \
20 -hdc $TESTDIR/result \
21 -m 256M -smp 2 -nographic \
22 -net none -kernel /boot/vmlinuz-$KVERSION \
23 -watchdog i6300esb -watchdog-action poweroff \
24 -append "root=LABEL=dracut $client_opts quiet rd.retry=3 rd.info console=ttyS0,115200n81 selinux=0 rd.debug $DEBUGFAIL" \
25 -initrd $TESTDIR/initramfs.testing
26
27 if (($? != 0)); then
28 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
29 return 1
30 fi
31
32 if ! grep -F -m 1 -q dracut-root-block-success $TESTDIR/result; then
33 echo "CLIENT TEST END: $test_name [FAILED]"
34 return 1
35 fi
36 echo "CLIENT TEST END: $test_name [OK]"
37
38 }
39
40 test_run() {
41 client_run "no option specified" || return 1
42 client_run "readonly root" "ro" || return 1
43 client_run "writeable root" "rw" || return 1
44 return 0
45 }
46
47 test_setup() {
48 rm -f -- $TESTDIR/root.btrfs
49 rm -f -- $TESTDIR/usr.btrfs
50 # Create the blank file to use as a root filesystem
51 dd if=/dev/null of=$TESTDIR/root.btrfs bs=1M seek=160
52 dd if=/dev/null of=$TESTDIR/usr.btrfs bs=1M seek=160
53
54 kernel=$KVERSION
55 # Create what will eventually be our root filesystem onto an overlay
56 (
57 export initdir=$TESTDIR/overlay/source
58 mkdir -p $initdir
59 . $basedir/dracut-functions.sh
60 inst_multiple sh df free ls shutdown poweroff stty cat ps ln ip route \
61 mount dmesg ifconfig dhclient mkdir cp ping dhclient \
62 umount strace less setsid
63 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
64 [ -f ${_terminfodir}/l/linux ] && break
65 done
66 inst_multiple -o ${_terminfodir}/l/linux
67 inst "$basedir/modules.d/40network/dhclient-script.sh" "/sbin/dhclient-script"
68 inst "$basedir/modules.d/40network/ifup.sh" "/sbin/ifup"
69 inst_multiple grep
70 inst_simple ./fstab /etc/fstab
71 inst_simple /etc/os-release
72 inst ./test-init.sh /sbin/init
73 find_binary plymouth >/dev/null && inst_multiple plymouth
74 (cd "$initdir"; mkdir -p dev sys proc etc var/run tmp )
75 cp -a /etc/ld.so.conf* $initdir/etc
76 sudo ldconfig -r "$initdir"
77 )
78
79 # second, install the files needed to make the root filesystem
80 (
81 export initdir=$TESTDIR/overlay
82 . $basedir/dracut-functions.sh
83 inst_multiple sfdisk mkfs.btrfs btrfs poweroff cp umount sync
84 inst_hook initqueue 01 ./create-root.sh
85 inst_hook initqueue/finished 01 ./finished-false.sh
86 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
87 )
88
89 # create an initramfs that will create the target root filesystem.
90 # We do it this way so that we do not risk trashing the host mdraid
91 # devices, volume groups, encrypted partitions, etc.
92 $basedir/dracut.sh -l -i $TESTDIR/overlay / \
93 -m "dash udev-rules btrfs base rootfs-block kernel-modules" \
94 -d "piix ide-gd_mod ata_piix btrfs sd_mod" \
95 --nomdadmconf \
96 --nohardlink \
97 -f $TESTDIR/initramfs.makeroot $KVERSION || return 1
98
99 # Invoke KVM and/or QEMU to actually create the target filesystem.
100
101 # echo $TESTDIR/overlay
102 # echo $TESTDIR/initramfs.makeroot
103 #exit 1
104 rm -rf -- $TESTDIR/overlay
105
106 $testdir/run-qemu \
107 -hda $TESTDIR/root.btrfs \
108 -hdb $TESTDIR/usr.btrfs \
109 -m 256M -smp 2 -nographic -net none \
110 -kernel "/boot/vmlinuz-$kernel" \
111 -append "root=/dev/dracut/root rw rootfstype=btrfs quiet console=ttyS0,115200n81 selinux=0" \
112 -initrd $TESTDIR/initramfs.makeroot || return 1
113 grep -F -m 1 -q dracut-root-block-created $TESTDIR/root.btrfs || return 1
114
115
116 (
117 export initdir=$TESTDIR/overlay
118 . $basedir/dracut-functions.sh
119 inst_multiple poweroff shutdown
120 inst_hook emergency 000 ./hard-off.sh
121 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
122 )
123 sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
124 -a "debug watchdog" \
125 -o "network" \
126 -d "piix ide-gd_mod ata_piix btrfs sd_mod i6300esb ib700wdt" \
127 -f $TESTDIR/initramfs.testing $KVERSION || return 1
128
129 rm -rf -- $TESTDIR/overlay
130
131 # -o "plymouth network md dmraid multipath fips caps crypt btrfs resume dmsquash-live dm"
132 }
133
134 test_cleanup() {
135 return 0
136 }
137
138 . $testdir/test-functions