0

I'm stuck trying to run Linux in QEMU with a few requirements. Any help or ideas is greatly appreciated! My goal, the problem, and how I setup everything up is shown below.

Goal
I am trying to setup QEMU in a way that I can step through XFS filesystem code for an aarch64 processor.

Problem
Linux starts to boot, but then the kernel panics. Linux provides the error below through QEMU's serial window. It explains that the filesystem cannot be mounted.

[ 3.456122] No filesystem could mount root, tried: [ 3.456142] ext3 [ 3.456207] ext2 [ 3.456240] ext4 [ 3.456270] squashfs [ 3.456299] vfat [ 3.456331] xfs [ 3.456364] [ 3.456572] Kernel panic - not syncing: VFS: Unable to mount root fs on "/dev/ram" or unknown-block(1,0) [ 3.456997] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.14.0 #2 [ 3.457163] Hardware name: linux,dummy-virt (DT) [ 3.457341] Call trace: [ 3.457494] show_stack+0x18/0x24 (C) [ 3.458100] dump_stack_lvl+0x34/0x8c [ 3.458202] dump_stack+0x18/0x24 [ 3.458257] panic+0x388/0x3e8 [ 3.458310] mount_root_generic+0x33c/0x354 [ 3.458375] mount_root+0x170/0x334 [ 3.458427] prepare_namespace+0x6c/0x2a8 [ 3.458483] kernel_init_freeable+0x250/0x290 [ 3.458549] kernel_init+0x20/0x1d8 [ 3.458664] ret_from_fork+0x10/0x20 [ 3.459074] Kernel Offset: 0x3ef1a8200000 from 0xffff800080000000 [ 3.459167] PHYS_OFFSET: 0xfff0de4180000000 [ 3.459232] CPU features: 0x200,00000170,00801250,0200720b [ 3.459324] Memory Limit: none [ 3.459813] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on "/dev/ram" or unknown-block(1,0) ]--- 

Process
First, I am building Linux from source using these commands.

make ARCH=arm64 defconfig make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j$(nproc) 

As part of the menu config I am turning off:

Compile-time checks and compiler options > Reduce debugging information 

And I turn on:

File systems > XFS filesystem support File systems > XFS Debugging support Device Drivers > Block Devices > RAM block device support General Setup > Initial Ram Filesystem and Ram Disk (initramfs/initrd) support 

Then I run this bash script to create an XFS filesystem and run QEMU.

# Init script that linux runs after booting LINUX_INIT_SCRIPT=init # Make a rootfs for linux (XFS filesystem) dd if=/dev/zero of=rootfs.img bs=1M count=1024 mkfs.xfs rootfs.img # Mount the an XFS filesystem a rootfs directory sudo mkdir -p rootfs sudo mount -o loop rootfs.img rootfs sudo cp ${LINUX_INIT_SCRIPT} rootfs/ cd rootfs sudo mkdir dev sudo mknod dev/ram b 1 0 sudo mknod dev/console c 5 1 cd .. sudo umount rootfs # Start QEMU qemu-system-aarch64 \ -kernel "kernel_image" \ -append "root=/dev/ram init=/init" \ -initrd rootfs.img \ -display gtk,show-tabs=on -serial vc \ -machine virt \ -cpu cortex-a76 \ -m 8G \ -S \ -gdb tcp::1234 & # Setup GDB for remote debugging gdb-multiarch vmlinux \ -ex "set architecture aarch64" -ex "target remote 127.0.0.1:1234" 

Here's is the init program I want Linux to run:

#include <stdio.h> #include <unistd.h> int main() { while (1) { printf("Hello\n"); sleep(1); } } 

I have some experience with QEMU but have never setup a disk or provided a filesystem before. I feel like how I'm providing the filesystem to both QEMU and Linux is wrong

1 Answer 1

0

You should not specify your image as "-initrd". The initrd is not a real image, but a cpio archive which is unpacked by the kernel in disk-cache (i.e. no file-system).

In your case I think it may be enough to skip the "-initrd" and instead specify a disk:

-drive if=none,file=rootfs.img,format=raw,id=hd" -device virtio-blk-device,drive=hd" 

(assuming a virtio device here)

Side-remark

Never use dd to create a raw disk image! Instead use:

truncate -s 1M rootfs.img ls -lhs rootfs.img 0 -rw-rw-r-- 1 guest guest 1.0M Nov 18 14:13 rootfs.img 

This is a "sparse" file. It look like 1M, but occupies 0 (zero) bytes on disk.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.