]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-16-DMSQUASH/test.sh
test(DMSQUASH): add test for NTFS
[thirdparty/dracut.git] / test / TEST-16-DMSQUASH / test.sh
1 #!/bin/bash
2
3 # shellcheck disable=SC2034
4 TEST_DESCRIPTION="live root on a squash filesystem"
5
6 # Uncomment these to debug failures
7 #DEBUGFAIL="rd.shell rd.debug rd.live.debug loglevel=7"
8
9 test_run() {
10 declare -a disk_args=()
11 declare -i disk_index=0
12 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
13 qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.img root
14
15 # NTFS drive
16 if modprobe --dry-run ntfs3 &> /dev/null && command -v mkfs.ntfs &> /dev/null; then
17 qemu_add_drive_args disk_index disk_args "$TESTDIR"/root_ntfs.img root_ntfs
18 fi
19
20 test_marker_reset
21 "$testdir"/run-qemu \
22 "${disk_args[@]}" \
23 -boot order=d \
24 -append "rd.live.overlay.overlayfs=1 root=live:/dev/disk/by-label/dracut console=ttyS0,115200n81 quiet selinux=0 rd.info rd.shell=0 panic=1 oops=panic softlockup_panic=1 $DEBUGFAIL" \
25 -initrd "$TESTDIR"/initramfs.testing
26
27 test_marker_check || return 1
28
29 test_marker_reset
30 "$testdir"/run-qemu \
31 "${disk_args[@]}" \
32 -boot order=d \
33 -append "rd.live.image rd.live.overlay.overlayfs=1 root=LABEL=dracut console=ttyS0,115200n81 quiet selinux=0 rd.info rd.shell=0 panic=1 oops=panic softlockup_panic=1 $DEBUGFAIL" \
34 -initrd "$TESTDIR"/initramfs.testing
35
36 test_marker_check || return 1
37
38 test_marker_reset
39 "$testdir"/run-qemu \
40 "${disk_args[@]}" \
41 -boot order=d \
42 -append "rd.live.image rd.live.overlay.overlayfs=1 rd.live.dir=testdir root=LABEL=dracut console=ttyS0,115200n81 quiet selinux=0 rd.info rd.shell=0 panic=1 oops=panic softlockup_panic=1 $DEBUGFAIL" \
43 -initrd "$TESTDIR"/initramfs.testing
44
45 test_marker_check || return 1
46
47 # Run the NTFS test only if mkfs.ntfs is available
48 if modprobe --dry-run ntfs3 &> /dev/null && command -v mkfs.ntfs &> /dev/null; then
49 dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1
50 "$testdir"/run-qemu \
51 "${disk_args[@]}" \
52 -boot order=d \
53 -append "rd.live.image rd.live.overlay.overlayfs=1 rd.live.dir=testdir root=LABEL=dracut_ntfs console=ttyS0,115200n81 quiet selinux=0 rd.info rd.shell=0 panic=1 oops=panic softlockup_panic=1 $DEBUGFAIL" \
54 -initrd "$TESTDIR"/initramfs.testing
55
56 test_marker_check || return 1
57 fi
58
59 test_marker_reset
60 rootPartitions=$(sfdisk -d "$TESTDIR"/root.img | grep -c 'root\.img[0-9]')
61 [ "$rootPartitions" -eq 1 ] || return 1
62
63 "$testdir"/run-qemu \
64 "${disk_args[@]}" \
65 -boot order=d \
66 -append "rd.live.image rd.live.overlay.overlayfs=1 rd.live.overlay=LABEL=persist rd.live.dir=testdir root=LABEL=dracut console=ttyS0,115200n81 quiet selinux=0 rd.info rd.shell=0 panic=1 oops=panic softlockup_panic=1 $DEBUGFAIL" \
67 -initrd "$TESTDIR"/initramfs.testing-autooverlay
68
69 rootPartitions=$(sfdisk -d "$TESTDIR"/root.img | grep -c 'root\.img[0-9]')
70 [ "$rootPartitions" -eq 2 ] || return 1
71
72 (
73 # Ensure that this test works when run with the `V=1` parameter, which runs the script with `set -o pipefail`.
74 set +o pipefail
75
76 # Verify that the string "dracut-autooverlay-success" occurs in the second partition in the image file.
77 dd if="$TESTDIR"/root.img bs=1MiB skip=80 status=none \
78 | grep -U --binary-files=binary -F -m 1 -q dracut-autooverlay-success
79 ) || return 1
80 }
81
82 test_setup() {
83 # Create what will eventually be our root filesystem onto an overlay
84 "$basedir"/dracut.sh -l --keep --tmpdir "$TESTDIR" \
85 -m "test-root" \
86 -i ./test-init.sh /sbin/init \
87 -i "${basedir}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh" \
88 -i "${basedir}/modules.d/99base/dracut-dev-lib.sh" "/lib/dracut-dev-lib.sh" \
89 --no-hostonly --no-hostonly-cmdline --nomdadmconf --nohardlink \
90 -f "$TESTDIR"/initramfs.root "$KVERSION" || return 1
91 mkdir -p "$TESTDIR"/overlay/source && mv "$TESTDIR"/dracut.*/initramfs/* "$TESTDIR"/overlay/source && rm -rf "$TESTDIR"/dracut.*
92
93 # second, install the files needed to make the root filesystem
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 --modules "test-makeroot" \
99 --install "sfdisk mkfs.ext4 mkfs.ntfs mksquashfs" \
100 --drivers "ntfs3" \
101 --include ./create-root.sh /lib/dracut/hooks/initqueue/01-create-root.sh \
102 --no-hostonly --no-hostonly-cmdline --no-early-microcode --nofscks --nomdadmconf --nohardlink --nostrip \
103 --force "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1
104 rm -rf -- "$TESTDIR"/overlay
105
106 # Create the blank file to use as a root filesystem
107 declare -a disk_args=()
108 declare -i disk_index=0
109 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker 1
110 qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.img root 160
111
112 # NTFS drive
113 if modprobe --dry-run ntfs3 &> /dev/null && command -v mkfs.ntfs &> /dev/null; then
114 dd if=/dev/zero of="$TESTDIR"/root_ntfs.img bs=1MiB count=160
115 qemu_add_drive_args disk_index disk_args "$TESTDIR"/root_ntfs.img root_ntfs
116 fi
117
118 # Invoke KVM and/or QEMU to actually create the target filesystem.
119 "$testdir"/run-qemu \
120 "${disk_args[@]}" \
121 -append "root=/dev/dracut/root rw rootfstype=ext4 quiet console=ttyS0,115200n81 selinux=0" \
122 -initrd "$TESTDIR"/initramfs.makeroot || return 1
123
124 if ! test_marker_check dracut-root-block-created; then
125 echo "Could not create root filesystem"
126 return 1
127 fi
128
129 # mount NTFS with ntfs3 driver inside the generated initramfs
130 cat > /tmp/ntfs3.rules << 'EOF'
131 SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="ntfs", ENV{ID_FS_TYPE}="ntfs3"
132 EOF
133
134 "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
135 --modules "test dash dmsquash-live qemu" \
136 --omit "rngd" \
137 --drivers "ext4 ntfs3 sd_mod" \
138 --install "mkfs.ext4" \
139 --include /tmp/ntfs3.rules /lib/udev/rules.d/ntfs3.rules \
140 --no-hostonly --no-hostonly-cmdline \
141 --force "$TESTDIR"/initramfs.testing "$KVERSION" || return 1
142
143 "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
144 --modules "test dmsquash-live-autooverlay qemu" \
145 --omit "rngd" \
146 --drivers "ext4 sd_mod" \
147 --install "mkfs.ext4" \
148 --no-hostonly --no-hostonly-cmdline \
149 --force "$TESTDIR"/initramfs.testing-autooverlay "$KVERSION" || return 1
150
151 rm -rf -- "$TESTDIR"/overlay
152 }
153
154 # shellcheck disable=SC1090
155 . "$testdir"/test-functions