TSG
TSG

Reputation: 887

Booting Linux on QEMU/RISC-V64/Busybox leads to error finding `/init` post boot

I'm trying to boot Linux on QEMU for RISC-V. I have set up my own toolchain described below:

For Linux and Busybox, I am using basically the default config. I have compiled all of these projects from scratch. I also created a initramfs image following the instructions here (step 8). I have remembered to make the init script executable.

Finally, I am trying to run with the command

qemu-system-riscv64 -m 4096M -nographic -machine virt -kernel linux/arch/riscv/boot/Image -initrd initramfs.cpio.gz -append "console=ttyS0 init=/init"

The kernel mostly boots fine, but fails to execute /init. The full boot log is below. The error (-2 == ENOENT) suggests that the file was not found. This makes no sense if the initramfs is used. I have used a similar command on previous busybox runs with QEMU and it works fine. The provided initramfs image is used as the root/ for the run. I have also tried to replace the /init script with a statically linked ELF binary, but that yields the same results. It seems to me that somehow, the filesystem is not being correctly mounted.

Alternately, I have also tried the instructions at the official tutorial, but the final run command is clearly wrong, as it tries to use the busybox folder as an image (file=busybox).

OpenSBI v0.8
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name       : riscv-virtio,qemu
Platform Features   : timer,mfdeleg
Platform HART Count : 1
Boot HART ID        : 0
Boot HART ISA       : rv64imafdcsu
BOOT HART Features  : pmp,scounteren,mcounteren,time
BOOT HART PMP Count : 16
Firmware Base       : 0x80000000
Firmware Size       : 92 KB
Runtime SBI Version : 0.2

MIDELEG : 0x0000000000000222
MEDELEG : 0x000000000000b109
PMP0    : 0x0000000080000000-0x000000008001ffff (A)
PMP1    : 0x0000000000000000-0xffffffffffffffff (A,R,W,X)
[    0.000000] Linux version 5.11.0 (abhattac@abhattac-HexHive) (riscv64-unknown-linux-gnu-gcc (GCC) 11.1.0, GNU ld (GNU Binutils) 2.36.1) #5 SMP Mon Jul 19 14:40:38 CEST 2021
[    0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000
[    0.000000] efi: UEFI not found.
[    0.000000] Initial ramdisk at: 0x(____ptrval____) (6488064 bytes)
[    0.000000] Zone ranges:
[    0.000000]   DMA32    [mem 0x0000000080200000-0x00000000ffffffff]
[    0.000000]   Normal   [mem 0x0000000100000000-0x000000017fffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000080200000-0x000000017fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x000000017fffffff]
[    0.000000] SBI specification v0.2 detected
[    0.000000] SBI implementation ID=0x1 Version=0x8
[    0.000000] SBI v0.2 TIME extension detected
[    0.000000] SBI v0.2 IPI extension detected
[    0.000000] SBI v0.2 RFENCE extension detected
[    0.000000] software IO TLB: mapped [mem 0x00000000fbe00000-0x00000000ffe00000] (64MB)
[    0.000000] SBI v0.2 HSM extension detected
[    0.000000] riscv: ISA extensions acdfimsu
[    0.000000] riscv: ELF capabilities acdfim
[    0.000000] percpu: Embedded 17 pages/cpu s32488 r8192 d28952 u69632
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 1033735
[    0.000000] Kernel command line: console=ttyS0 init=/init nokaslr
[    0.000000] Dentry cache hash table entries: 524288 (order: 10, 4194304 bytes, linear)
[    0.000000] Inode-cache hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[    0.000000] Sorting __ex_table...
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 4036748K/4192256K available (7107K kernel code, 4905K rwdata, 4096K rodata, 2147K init, 305K bss, 155508K reserved, 0K cma-reserved)
[    0.000000] Virtual kernel memory layout:
[    0.000000]       fixmap : 0xffffffcefee00000 - 0xffffffceff000000   (2048 kB)
[    0.000000]       pci io : 0xffffffceff000000 - 0xffffffcf00000000   (  16 MB)
[    0.000000]      vmemmap : 0xffffffcf00000000 - 0xffffffcfffffffff   (4095 MB)
[    0.000000]      vmalloc : 0xffffffd000000000 - 0xffffffdfffffffff   (65535 MB)
[    0.000000]       lowmem : 0xffffffe000000000 - 0xffffffe0ffe00000   (4094 MB)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] rcu: Hierarchical RCU implementation.
[    0.000000] rcu:     RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
[    0.000000] rcu:     RCU debug extended QS entry/exit.
[    0.000000]  Tracing variant of Tasks RCU enabled.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
[    0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
[    0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[    0.000000] riscv-intc: 64 local interrupts mapped
[    0.000000] plic: plic@c000000: mapped 53 interrupts with 1 handlers for 2 contexts.
[    0.000000] random: get_random_bytes called from start_kernel+0x3b8/0x58c with crng_init=0
[    0.000000] riscv_timer_init_dt: Registering clocksource cpuid [0] hartid [0]
[    0.000000] clocksource: riscv_clocksource: mask: 0xffffffffffffffff max_cycles: 0x24e6a1710, max_idle_ns: 440795202120 ns
[    0.000071] sched_clock: 64 bits at 10MHz, resolution 100ns, wraps every 4398046511100ns
[    0.002538] Console: colour dummy device 80x25
[    0.003999] Calibrating delay loop (skipped), value calculated using timer frequency.. 20.00 BogoMIPS (lpj=40000)
[    0.004128] pid_max: default: 32768 minimum: 301
[    0.006600] Mount-cache hash table entries: 8192 (order: 4, 65536 bytes, linear)
[    0.006649] Mountpoint-cache hash table entries: 8192 (order: 4, 65536 bytes, linear)
[    0.026393] rcu: Hierarchical SRCU implementation.
[    0.027592] EFI services will not be available.
[    0.029054] smp: Bringing up secondary CPUs ...
[    0.029128] smp: Brought up 1 node, 1 CPU
[    0.036109] devtmpfs: initialized
[    0.041159] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.041293] futex hash table entries: 256 (order: 2, 16384 bytes, linear)
[    0.044939] NET: Registered protocol family 16
[    0.085510] vgaarb: loaded
[    0.086364] SCSI subsystem initialized
[    0.087587] usbcore: registered new interface driver usbfs
[    0.087807] usbcore: registered new interface driver hub
[    0.087910] usbcore: registered new device driver usb
[    0.095866] clocksource: Switched to clocksource riscv_clocksource
[    0.106461] NET: Registered protocol family 2
[    0.109687] tcp_listen_portaddr_hash hash table entries: 2048 (order: 4, 81920 bytes, linear)
[    0.110926] TCP established hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.111209] TCP bind hash table entries: 32768 (order: 8, 1048576 bytes, linear)
[    0.112195] TCP: Hash tables configured (established 32768 bind 32768)
[    0.113016] UDP hash table entries: 2048 (order: 5, 196608 bytes, linear)
[    0.113355] UDP-Lite hash table entries: 2048 (order: 5, 196608 bytes, linear)
[    0.114514] NET: Registered protocol family 1
[    0.117744] RPC: Registered named UNIX socket transport module.
[    0.117797] RPC: Registered udp transport module.
[    0.117812] RPC: Registered tcp transport module.
[    0.117825] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.117909] PCI: CLS 0 bytes, default 64
[    0.120124] Unpacking initramfs...
[    0.842259] Freeing initrd memory: 6332K
[    0.844543] workingset: timestamp_bits=62 max_order=20 bucket_order=0
[    0.856180] NFS: Registering the id_resolver key type
[    0.856788] Key type id_resolver registered
[    0.856824] Key type id_legacy registered
[    0.857070] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.857560] 9p: Installing v9fs 9p2000 file system support
[    0.858506] NET: Registered protocol family 38
[    0.858704] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251)
[    0.858804] io scheduler mq-deadline registered
[    0.858862] io scheduler kyber registered
[    0.864434] pci-host-generic 30000000.pci: host bridge /soc/pci@30000000 ranges:
[    0.865077] pci-host-generic 30000000.pci:       IO 0x0003000000..0x000300ffff -> 0x0000000000
[    0.865412] pci-host-generic 30000000.pci:      MEM 0x0040000000..0x007fffffff -> 0x0040000000
[    0.866661] pci-host-generic 30000000.pci: ECAM at [mem 0x30000000-0x3fffffff] for [bus 00-ff]
[    0.867495] pci-host-generic 30000000.pci: PCI host bridge to bus 0000:00
[    0.867683] pci_bus 0000:00: root bus resource [bus 00-ff]
[    0.867749] pci_bus 0000:00: root bus resource [io  0x0000-0xffff]
[    0.867803] pci_bus 0000:00: root bus resource [mem 0x40000000-0x7fffffff]
[    0.868668] pci 0000:00:00.0: [1b36:0008] type 00 class 0x060000
[    0.917700] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    0.921998] printk: console [ttyS0] disabled
[    0.923181] 10000000.uart: ttyS0 at MMIO 0x10000000 (irq = 2, base_baud = 230400) is a 16550A
[    0.938948] printk: console [ttyS0] enabled
[    0.940558] [drm] radeon kernel modesetting enabled.
[    0.952711] loop: module loaded
[    0.954830] libphy: Fixed MDIO Bus: probed
[    0.955856] e1000e: Intel(R) PRO/1000 Network Driver
[    0.955976] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
[    0.956330] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    0.956504] ehci-pci: EHCI PCI platform driver
[    0.956737] ehci-platform: EHCI generic platform driver
[    0.956944] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    0.957153] ohci-pci: OHCI PCI platform driver
[    0.957374] ohci-platform: OHCI generic platform driver
[    0.958183] usbcore: registered new interface driver uas
[    0.958427] usbcore: registered new interface driver usb-storage
[    0.959096] mousedev: PS/2 mouse device common for all mice
[    0.961287] goldfish_rtc 101000.rtc: registered as rtc0
[    0.961750] goldfish_rtc 101000.rtc: setting system clock to 2021-07-20T08:25:12 UTC (1626769512)
[    0.963529] syscon-poweroff soc:poweroff: pm_power_off already claimed for sbi_shutdown
[    0.963870] syscon-poweroff: probe of soc:poweroff failed with error -16
[    0.964728] usbcore: registered new interface driver usbhid
[    0.964866] usbhid: USB HID core driver
[    0.966119] NET: Registered protocol family 10
[    0.973579] Segment Routing with IPv6
[    0.973959] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    0.975972] NET: Registered protocol family 17
[    0.977014] 9pnet: Installing 9P2000 support
[    0.977341] Key type dns_resolver registered
[    0.977863] debug_vm_pgtable: [debug_vm_pgtable         ]: Validating architecture page table helpers
[    1.001918] Freeing unused kernel memory: 2144K
[    1.007901] Run /init as init process
[    1.010056] Failed to execute /init (error -2)
[    1.010204] Run /init as init process
[    1.010634] Kernel panic - not syncing: Requested init /init failed (error -2).
[    1.010916] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.11.0 #5
[    1.011184] Call Trace:
[    1.011311] [<ffffffe0000047b2>] walk_stackframe+0x0/0xaa
[    1.011893] ---[ end Kernel panic - not syncing: Requested init /init failed (error -2). ]---
QEMU: Terminated

Upvotes: 0

Views: 1629

Answers (1)

Florin
Florin

Reputation: 1

I think I had that issue in the past. In my case it was because the initramfs was missing the prepended microcode(see more details here: https://wiki.debian.org/initramfs). I would recommend using buildroot and choose the option that the initramfs is embedded into the kernel Image. Buildroot will prepend that microcode for you.

Upvotes: 0

Related Questions