]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-03-USR-MOUNT/test.sh
test: move common dependencies from test case to test-makeroot module
[thirdparty/dracut.git] / test / TEST-03-USR-MOUNT / test.sh
1 #!/bin/bash
2
3 # shellcheck disable=SC2034
4 TEST_DESCRIPTION="root filesystem on a btrfs filesystem with /usr subvolume"
5
6 KVERSION=${KVERSION-$(uname -r)}
7
8 # Uncomment this to debug failures
9 #DEBUGFAIL="rd.shell rd.break"
10
11 client_run() {
12 local test_name="$1"
13 shift
14 local client_opts="$*"
15
16 echo "CLIENT TEST START: $test_name"
17
18 dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1
19 declare -a disk_args=()
20 # shellcheck disable=SC2034
21 declare -i disk_index=0
22 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
23 qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.btrfs root
24 qemu_add_drive_args disk_index disk_args "$TESTDIR"/usr.btrfs usr
25
26 "$testdir"/run-qemu \
27 "${disk_args[@]}" \
28 -watchdog i6300esb -watchdog-action poweroff \
29 -append "panic=1 oops=panic softlockup_panic=1 systemd.crash_reboot root=LABEL=dracut $client_opts loglevel=7 rd.retry=3 rd.info console=ttyS0,115200n81 selinux=0 rd.debug rd.shell=0 $DEBUGFAIL" \
30 -initrd "$TESTDIR"/initramfs.testing || return 1
31
32 if ! grep -U --binary-files=binary -F -m 1 -q dracut-root-block-success "$TESTDIR"/marker.img; 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 kernel=$KVERSION
49 # Create what will eventually be our root filesystem onto an overlay
50 (
51 # shellcheck disable=SC2030
52 export initdir=$TESTDIR/overlay/source
53 mkdir -p "$initdir"
54 # shellcheck disable=SC1090
55 . "$basedir"/dracut-init.sh
56 (
57 cd "$initdir" || exit
58 mkdir -p -- dev sys proc etc var/run tmp
59 mkdir -p root usr/bin usr/lib usr/lib64 usr/sbin
60 )
61 inst_multiple sh df free ls poweroff stty cat ps ln \
62 mount dmesg mkdir cp \
63 umount strace less setsid dd sync
64 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
65 [ -f ${_terminfodir}/l/linux ] && break
66 done
67 inst_multiple -o ${_terminfodir}/l/linux
68
69 inst_simple "${basedir}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh"
70 inst_simple "${basedir}/modules.d/99base/dracut-dev-lib.sh" "/lib/dracut-dev-lib.sh"
71 inst_binary "${basedir}/dracut-util" "/usr/bin/dracut-util"
72 ln -s dracut-util "${initdir}/usr/bin/dracut-getarg"
73 ln -s dracut-util "${initdir}/usr/bin/dracut-getargs"
74
75 inst_multiple grep df
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 # shellcheck disable=SC2031
87 # shellcheck disable=SC2030
88 export initdir=$TESTDIR/overlay
89 # shellcheck disable=SC1090
90 . "$basedir"/dracut-init.sh
91 inst_multiple sfdisk mkfs.btrfs btrfs
92 inst_hook initqueue 01 ./create-root.sh
93 inst_hook initqueue/finished 01 ./finished-false.sh
94 )
95
96 # create an initramfs that will create the target root filesystem.
97 # We do it this way so that we do not risk trashing the host mdraid
98 # devices, volume groups, encrypted partitions, etc.
99 "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
100 -m "test-makeroot dash btrfs rootfs-block kernel-modules" \
101 -d "piix ide-gd_mod ata_piix btrfs sd_mod" \
102 --nomdadmconf \
103 --nohardlink \
104 --no-hostonly-cmdline -N \
105 -f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1
106 rm -rf -- "$TESTDIR"/overlay
107
108 # Create the blank file to use as a root filesystem
109 dd if=/dev/zero of="$TESTDIR"/root.btrfs bs=1MiB count=160
110 dd if=/dev/zero of="$TESTDIR"/usr.btrfs bs=1MiB count=160
111 dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1
112 declare -a disk_args=()
113 # shellcheck disable=SC2034
114 declare -i disk_index=0
115 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
116 qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.btrfs root
117 qemu_add_drive_args disk_index disk_args "$TESTDIR"/usr.btrfs usr
118
119 # Invoke KVM and/or QEMU to actually create the target filesystem.
120 "$testdir"/run-qemu \
121 "${disk_args[@]}" \
122 -append "root=/dev/dracut/root rw rootfstype=btrfs quiet console=ttyS0,115200n81 selinux=0" \
123 -initrd "$TESTDIR"/initramfs.makeroot || return 1
124
125 if ! grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created "$TESTDIR"/marker.img; then
126 echo "Could not create root filesystem"
127 return 1
128 fi
129
130 (
131 # shellcheck disable=SC2031
132 export initdir=$TESTDIR/overlay
133 # shellcheck disable=SC1090
134 . "$basedir"/dracut-init.sh
135 inst_multiple dd
136 )
137 "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
138 -a "test watchdog" \
139 -o "network kernel-network-modules" \
140 -d "piix ide-gd_mod ata_piix btrfs sd_mod i6300esb ib700wdt" \
141 --no-hostonly-cmdline -N \
142 -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1
143
144 rm -rf -- "$TESTDIR"/overlay
145 }
146
147 test_cleanup() {
148 return 0
149 }
150
151 # shellcheck disable=SC1090
152 . "$testdir"/test-functions