Skip to content

Commit

Permalink
test(DMSQUASH): add test for NTFS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LaszloGombos authored and aafeijoo-suse committed Jun 26, 2023
1 parent d96754e commit 995ac6f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
10 changes: 10 additions & 0 deletions test/TEST-16-DMSQUASH/create-root.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 32 additions & 2 deletions test/TEST-16-DMSQUASH/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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[@]}" \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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[@]}" \
Expand All @@ -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

Expand Down

0 comments on commit 995ac6f

Please sign in to comment.