]> git.ipfire.org Git - thirdparty/dracut.git/blame - test/TEST-16-DMSQUASH/test.sh
test: make dracut directory configurable
[thirdparty/dracut.git] / test / TEST-16-DMSQUASH / test.sh
CommitLineData
ea8e543b 1#!/bin/bash
6ee2baf3 2
92798d7d 3# shellcheck disable=SC2034
6ee2baf3 4TEST_DESCRIPTION="live root on a squash filesystem"
ea8e543b 5
a3c67d27
MC
6# Uncomment these to debug failures
7#DEBUGFAIL="rd.shell rd.debug rd.live.debug loglevel=7"
c79f3883 8
ea8e543b 9test_run() {
b80ee080 10 declare -a disk_args=()
b80ee080
HH
11 declare -i disk_index=0
12 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
6ee2baf3 13 qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.img root
b80ee080 14
995ac6f8
LG
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
f1346763 20 test_marker_reset
40dd5c90
LG
21 "$testdir"/run-qemu \
22 "${disk_args[@]}" \
23 -boot order=d \
d96754ea 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" \
40dd5c90
LG
25 -initrd "$TESTDIR"/initramfs.testing
26
d96754ea
LG
27 test_marker_check || return 1
28
29 test_marker_reset
027eee90
LG
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
d96754ea
LG
36 test_marker_check || return 1
37
38 test_marker_reset
b093aa2d 39 "$testdir"/run-qemu \
b80ee080 40 "${disk_args[@]}" \
9a52c3fd 41 -boot order=d \
6ee2baf3 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" \
9a52c3fd 43 -initrd "$TESTDIR"/initramfs.testing
90ac2d24 44
f1346763 45 test_marker_check || return 1
a3c67d27 46
995ac6f8
LG
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
d96754ea 59 test_marker_reset
a3c67d27
MC
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
ea8e543b
HH
80}
81
82test_setup() {
ea8e543b 83 # Create what will eventually be our root filesystem onto an overlay
f9939d0e 84 "$DRACUT" -l --keep --tmpdir "$TESTDIR" \
ab23d89a
LG
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.*
6ee2baf3
LG
92
93 # second, install the files needed to make the root filesystem
6ee2baf3
LG
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.
f9939d0e 97 "$DRACUT" -l -i "$TESTDIR"/overlay / \
c5e036b1 98 --modules "test-makeroot" \
995ac6f8
LG
99 --install "sfdisk mkfs.ext4 mkfs.ntfs mksquashfs" \
100 --drivers "ntfs3" \
ab23d89a 101 --include ./create-root.sh /lib/dracut/hooks/initqueue/01-create-root.sh \
6ee2baf3
LG
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
6ee2baf3 107 declare -a disk_args=()
6ee2baf3 108 declare -i disk_index=0
f1346763
HG
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
6ee2baf3 111
995ac6f8
LG
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
6ee2baf3
LG
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
f1346763 124 if ! test_marker_check dracut-root-block-created; then
6ee2baf3
LG
125 echo "Could not create root filesystem"
126 return 1
127 fi
128
995ac6f8
LG
129 # mount NTFS with ntfs3 driver inside the generated initramfs
130 cat > /tmp/ntfs3.rules << 'EOF'
131SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="ntfs", ENV{ID_FS_TYPE}="ntfs3"
132EOF
133
f9939d0e 134 "$DRACUT" -l -i "$TESTDIR"/overlay / \
ab23d89a 135 --modules "test dash dmsquash-live qemu" \
6ee2baf3 136 --omit "rngd" \
995ac6f8 137 --drivers "ext4 ntfs3 sd_mod" \
ab23d89a 138 --install "mkfs.ext4" \
995ac6f8 139 --include /tmp/ntfs3.rules /lib/udev/rules.d/ntfs3.rules \
6ee2baf3
LG
140 --no-hostonly --no-hostonly-cmdline \
141 --force "$TESTDIR"/initramfs.testing "$KVERSION" || return 1
142
f9939d0e 143 "$DRACUT" -l -i "$TESTDIR"/overlay / \
ab23d89a 144 --modules "test dmsquash-live-autooverlay qemu" \
a3c67d27
MC
145 --omit "rngd" \
146 --drivers "ext4 sd_mod" \
ab23d89a 147 --install "mkfs.ext4" \
a3c67d27
MC
148 --no-hostonly --no-hostonly-cmdline \
149 --force "$TESTDIR"/initramfs.testing-autooverlay "$KVERSION" || return 1
150
6ee2baf3 151 rm -rf -- "$TESTDIR"/overlay
ea8e543b
HH
152}
153
92798d7d 154# shellcheck disable=SC1090
b093aa2d 155. "$testdir"/test-functions