]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
test(DMSQUASH): add test for NTFS
authorLaszlo Gombos <laszlo.gombos@gmail.com>
Sat, 17 Dec 2022 01:00:28 +0000 (01:00 +0000)
committerAntonio Álvarez Feijoo <antonio.feijoo@suse.com>
Mon, 26 Jun 2023 07:37:19 +0000 (09:37 +0200)
Add a test case for mounting the root filesystem from
a squashfs image file that is store on an NTFS drive.

The test case is using ntfs3 module to mount the NTFS drive.

test/TEST-16-DMSQUASH/create-root.sh
test/TEST-16-DMSQUASH/test.sh

index d0e409e9100b12d206eed4f4c9e551e99902f012..f17b22f9ce9de4119167a07906555b2cc7ac1c82 100755 (executable)
@@ -26,6 +26,16 @@ mkdir -p /root/run /root/testdir
 cp -a -t /root /source/*
 echo "Creating squashfs"
 mksquashfs /source /root/testdir/rootfs.img -quiet
+
+# Copy rootfs.img to the NTFS drive if exists
+if [ -e "/dev/disk/by-id/ata-disk_root_ntfs" ]; then
+    mkfs.ntfs -F -L dracut_ntfs /dev/disk/by-id/ata-disk_root_ntfs
+    mkdir -p /root_ntfs
+    mount -t ntfs3 /dev/disk/by-id/ata-disk_root_ntfs /root_ntfs
+    mkdir -p /root_ntfs/run /root_ntfs/testdir
+    cp /root/testdir/rootfs.img /root_ntfs/testdir/rootfs.img
+fi
+
 umount /root
 echo "dracut-root-block-created" | dd oflag=direct,dsync of=/dev/disk/by-id/ata-disk_marker
 poweroff -f
index 1535386d9dd2b6934caec0a7e601e39eb74f5a8a..af9440172ad489c456914f373a128081485cd5c3 100755 (executable)
@@ -12,6 +12,11 @@ test_run() {
     qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
     qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.img root
 
+    # NTFS drive
+    if modprobe --dry-run ntfs3 &> /dev/null && command -v mkfs.ntfs &> /dev/null; then
+        qemu_add_drive_args disk_index disk_args "$TESTDIR"/root_ntfs.img root_ntfs
+    fi
+
     test_marker_reset
     "$testdir"/run-qemu \
         "${disk_args[@]}" \
@@ -39,6 +44,18 @@ test_run() {
 
     test_marker_check || return 1
 
+    # Run the NTFS test only if mkfs.ntfs is available
+    if modprobe --dry-run ntfs3 &> /dev/null && command -v mkfs.ntfs &> /dev/null; then
+        dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1
+        "$testdir"/run-qemu \
+            "${disk_args[@]}" \
+            -boot order=d \
+            -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" \
+            -initrd "$TESTDIR"/initramfs.testing
+
+        test_marker_check || return 1
+    fi
+
     test_marker_reset
     rootPartitions=$(sfdisk -d "$TESTDIR"/root.img | grep -c 'root\.img[0-9]')
     [ "$rootPartitions" -eq 1 ] || return 1
@@ -79,7 +96,8 @@ test_setup() {
     # devices, volume groups, encrypted partitions, etc.
     "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
         --modules "test-makeroot" \
-        --install "sfdisk mkfs.ext4 mksquashfs" \
+        --install "sfdisk mkfs.ext4 mkfs.ntfs mksquashfs" \
+        --drivers "ntfs3" \
         --include ./create-root.sh /lib/dracut/hooks/initqueue/01-create-root.sh \
         --no-hostonly --no-hostonly-cmdline --no-early-microcode --nofscks --nomdadmconf --nohardlink --nostrip \
         --force "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1
@@ -91,6 +109,12 @@ test_setup() {
     qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker 1
     qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.img root 160
 
+    # NTFS drive
+    if modprobe --dry-run ntfs3 &> /dev/null && command -v mkfs.ntfs &> /dev/null; then
+        dd if=/dev/zero of="$TESTDIR"/root_ntfs.img bs=1MiB count=160
+        qemu_add_drive_args disk_index disk_args "$TESTDIR"/root_ntfs.img root_ntfs
+    fi
+
     # Invoke KVM and/or QEMU to actually create the target filesystem.
     "$testdir"/run-qemu \
         "${disk_args[@]}" \
@@ -102,11 +126,17 @@ test_setup() {
         return 1
     fi
 
+    # mount NTFS with ntfs3 driver inside the generated initramfs
+    cat > /tmp/ntfs3.rules << 'EOF'
+SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="ntfs", ENV{ID_FS_TYPE}="ntfs3"
+EOF
+
     "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
         --modules "test dash dmsquash-live qemu" \
         --omit "rngd" \
-        --drivers "ext4 sd_mod" \
+        --drivers "ext4 ntfs3 sd_mod" \
         --install "mkfs.ext4" \
+        --include /tmp/ntfs3.rules /lib/udev/rules.d/ntfs3.rules \
         --no-hostonly --no-hostonly-cmdline \
         --force "$TESTDIR"/initramfs.testing "$KVERSION" || return 1