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