linux: running self compiled kernel in qemu: VFS: Unable to mount root fs on unknown wn-block(0,0)

StackOverflow https://stackoverflow.com/questions/17242403

문제

I try to get this running and don't know what I'm doing wrong. I have created an Debian.img (disk in raw format with virtual device manager - gui to libvirt I guess) and installed debian with no troubles. Now I want to get this running with a self compiled kernel. I copied the .config-file from my working (virtual) debian and made no more changes at all. This is what I do:

    qemu-system-x86_64 -m 1024M -kernel /path/to/bzImage -hda /var/lib/libvirt/images/Debian.img -append "root=/dev/sda1 console=ttyS0" -enable-kvm -nographic

But during boot I always get this error message.

    [    0.195285] Initializing network drop monitor service
    [    0.196177] List of all partitions:
    [    0.196641] No filesystem could mount root, tried: 
    [    0.197292] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
    [    0.198355] Pid: 1, comm: swapper/0 Not tainted 3.2.46 #7
    [    0.199055] Call Trace:
    [    0.199386]  [<ffffffff81318c30>] ? panic+0x95/0x19e
    [    0.200049]  [<ffffffff81680f7d>] ? mount_block_root+0x245/0x271
    [    0.200834]  [<ffffffff8168112f>] ? prepare_namespace+0x133/0x169
    [    0.201590]  [<ffffffff81680c94>] ? kernel_init+0x14c/0x151
    [    0.202273]  [<ffffffff81325a34>] ? kernel_thread_helper+0x4/0x10
    [    0.203022]  [<ffffffff81680b48>] ? start_kernel+0x3c1/0x3c1
    [    0.203716]  [<ffffffff81325a30>] ? gs_change+0x13/0x13

What I'm doing wrong? Please someone help. Do I need to pass the -initrd option? I tried this already but had no luck yet.

도움이 되었습니까?

해결책

I figured it out by myself. Some time has passed, but as I recall the solution was to provide an initial ramdisk. This is how I got it working with hardware acceleration.

Compiling

make defconfig

CONFIG_EXT4_FS=y
CONFIG_IA32_EMULATION=y
CONFIG_VIRTIO_PCI=y (Virtualization -> PCI driver for virtio devices)
CONFIG_VIRTIO_BALLOON=y (Virtualization -> Virtio balloon driver)
CONFIG_VIRTIO_BLK=y (Device Drivers -> Block -> Virtio block driver)
CONFIG_VIRTIO_NET=y (Device Drivers -> Network device support -> Virtio network driver)
CONFIG_VIRTIO=y (automatically selected)
CONFIG_VIRTIO_RING=y (automatically selected)

---> see http://www.linux-kvm.org/page/Virtio

Enable paravirt in config

Disable NMI watchdog on HOST for using performance counters on GUEST. You may ignore this.

cat /proc/sys/kernel/nmi_watchdog

---> see http://kvm.et.redhat.com/page/Guest_PMU

Start in Qemu

sudo qemu-system-x86_64 -m 1024M -hda /var/lib/libvirt/images/DEbian.img -enable-kvm -initrd /home/username/compiled_kernel/initrd.img-3.2.46 -kernel /home/username/compiled_kernel/bzImage -append "root=/dev/sda1 console=ttyS0" -nographic -redir tcp:2222::22 -cpu host -smp cores=2

Start in KVM

Kernal path: /home/username/compiled_kernel/bzImage
Initrd path: /home/username/compiled_kernel/initrd.img-3.2.46
Kernel arguments: root=/dev/sda1

Hope this helps if someone has the same issues.

다른 팁

This is for AArch64 (arm64) on QEMU case.

I was following this good tutorial: https://ibug.io/blog/2019/04/os-lab-1/

In my case I was met with this error message:

---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(1,0) ]---

I did mknod dev/ram b 1 0 in the initrd.

Later I noticed there was an error message above that line implying the kernel didn't support the ram disk. So I edited .config and set these items:

CONFIG_BLK_DEV_RAM=y
CONFIG_BLK_DEV_RAM_COUNT=1
CONFIG_BLK_DEV_RAM_SIZE=131072 (= 128MB, the number is in unit of 1014B)

And then the problem was gone! The initrd was mounted on /dev/ram and the first init process ran well.

It turns out running make defconfig didn't set thses values by default for me.

maybe your system image file is bad and can not be mounted. You may try these command to mount the image file and check if it is a valid root file system for linux.

losetup /dev/loop0 /var/lib/libvirt/images/Debian.img
kpartx -av /dev/loop0
mount /dev/mapper/loop0p1 /mnt/tmp

The most likely thing is that the kernel doesn't know the correct device to boot from.
You can supply this explicitly from the qemu command line. So if the root is on partition 2, you can say:

qemu -kernel /path/to/bzImage \
     -append root=/dev/sda2 \
     -hda /path/to/hda.img \
     .
     .
     .

Notice I use /dev/sda2 even though the disk is IDE. Even virtual machines seem to use SATA nowadays.

The other possibilities are that as @Houcheng says, your root FS is corrupted, or else that the kernel does not have that particular FS type built in. But I think you would get a different error if that were the case.

QEMU version

QEMU emulator version 2.5.0 (Debian 1:2.5+dfsg-5ubuntu10.11), Copyright (c) 2003-2008 Fabrice Bellard

running build-root 4.9.6 with the following arguments to be passed

qemu-system-x86_64 -kernel output/images/bzImage -hda output/images/rootfs.qcow2 -boot c -m 128 -append root=/dev/sda -localtime -no-reboot -name rtlinux -net nic -net user -redir tcp:2222::22 -redir tcp:3333::3333

was accepting only /dev/sda as an option for the root fs to mount (it will show you a little hint for the root fs option once it will boot and hang with the following error):

VFS: Cannot open root device "hda" or unknown-block(0,0): error -6
Please append a correct "root=" boot option; here are the available partitions:
0800 61440 sda driver: sd
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top