79644989

Date: 2025-05-30 06:26:31
Score: 1
Natty:
Report link

The Linux kernel cannot directly mount a RAM address as rootfs via root=. The kernel expects root= to specify a device (e.g., /dev/ram0, /dev/mapper/, /dev/mmcblk, etc.), not a physical address in RAM.

  1. Can you pass a RAM address as root=? No. root= only supports block devices, not memory addresses. You cannot tell the kernel "the rootfs lives at RAM address 0x1C0000000" via the kernel command line.

  2. How can you connect a rootfs in RAM with /dev/ramX? You need to make the rootfs appear as /dev/ram0 or another block device. Usual approaches:

Copy rootfs into a ramdisk device (e.g., /dev/ram0) during initramfs/init phase.

Use a preload/initramfs script to copy or map the memory into /dev/ram0, then pivot_root or switch_root to it.

Example: In your initramfs shell, manually copy/mount the rootfs:

text dd if=/dev/mem bs=1M skip= count=<size_in_MB> of=/dev/ram0 mount -o ro /dev/ram0 /mnt exec switch_root /mnt /sbin/init : Number of megs to skip to reach your RAM address (0x1C0000000 / 1M).

<size_in_MB>: Size of your rootfs file in MB.

Security note: You need access to /dev/mem (which is often restricted or requires boot param iomem=relaxed).

  1. Why does dd if=/dev/mem ... fail with "Operation not permitted"? /dev/mem is typically restricted for security reasons.

You may need to:

Boot with iomem=relaxed, or

Lower kernel security settings (not recommended for production).

Or, ideally, avoid /dev/mem and use QEMU's support for -initrd or custom devices.

  1. How to ensure your rootfs RAM region isn't overwritten by the kernel? memmap kernel boot option is NOT available on RISC-V (as you noted).

In QEMU, if you -device loader,file=...,addr=0x1C0000000, QEMU places the file in RAM, but the kernel may overwrite it if not reserved.

Alternative: Embed your rootfs as an initramfs or use QEMU's -initrd option (safest).

Workaround: Use a reserved memory region (in DTB), but this is complex on RISC-V and not portable.

Best Practice/Solution Use QEMU's -initrd option if you can (loads to a safe spot, kernel finds it).

If you must load rootfs into RAM at a specific address:

Use an initramfs/init script to copy the data from unknown memory to /dev/ram0.

Ensure early in boot that no kernel code/page uses or overwrites your chosen address (risky).

Strongly recommend converting your rootfs to an initramfs (cpio archive) and passing with -initrd, or use a disk image mounted as a virtual drive.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Naik Pratham