Search code examples
embedded-linuxyoctou-bootinitramfs

Yocto rootfs allocation when booting from RAM


I'm currently working on a test build for an embedded yocto build that runs from RAM.

Using yocto I generate a fitimage containing an initramfs which is run from RAM on boot. In the past this has worked as expected however, over time as more features are needed in the initramfs continues to grow and I have now hit a space limit. In the past I have encountered space limits that could be rectified by adjusting yocto variables such as INITRAMFS_MAXSIZE & IMAGE_OVERHEAD_FACTOR but these no longer take any effect as I seem to have hit some other limit.

The device has 2GB of physical memory, when booted into the initramfs and looking at disk usage we can see that the rootfs is at 100% usage of 557MB while there is 1+GB of empty tmpfs storage.

Futhermore, if we another package to the initramfs we can compile without errors as we do not hit INITRAMFS_MAXSIZE but we can no longer boot as we encounter the following kernel panic:

[   10.918626] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
[   10.926889] CPU: 2 PID: 1 Comm: swapper/0 Not tainted 5.15.52 #1
[   10.934110] Hardware name: i.MX8MPlus
[   10.940026] Call trace:
[   10.942470]  dump_backtrace+0x0/0x1a0
[   10.946138]  show_stack+0x18/0x70
[   10.949452]  dump_stack_lvl+0x68/0x84
[   10.953116]  dump_stack+0x18/0x34
[   10.956431]  panic+0x160/0x30c
[   10.959485]  mount_block_root+0x180/0x234
[   10.963496]  mount_root+0x178/0x198
[   10.966984]  prepare_namespace+0x130/0x170
[   10.971081]  kernel_init_freeable+0x24c/0x290
[   10.975437]  kernel_init+0x28/0x12c
[   10.978927]  ret_from_fork+0x10/0x20
[   10.982503] SMP: stopping secondary CPUs
[   10.986709] Kernel Offset: 0x80000 from 0xffff800008000000
[   10.992192] PHYS_OFFSET: 0x40000000
[   10.995677] CPU features: 0x00002401,20000842
[   11.000031] Memory Limit: none
[   11.003086] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) ]--- 

How I can reallocate the unused tmpfs space so that it can be utilized by the initramfs?

  • Attempted to increase INITRAMFS_MAXSIZE, IMAGE_OVERHEAD_FACTOR
  • Attempted to increase space using IMAGE_ROOTFS_SIZE and IMAGE_ROOTFS_EXTRA_SPACE
  • Attempted to track down space limitation in uboot and kernel configurations with no luck

Solution

  • Marking as answered as we have had a fix in place for sometime and it seems to work well.

    I ended up coming across the following blog post https://www.lightofdawn.org/blog/?viewDetailed=00128 (The same one linked by Sawdust in the comments, thanks Sawdust)

    As recommended in the blog post I added an extra u-boot bootarg "rootfstype=ramfs" which allows me to use the full space. Although this solution is probably not suitable for a production system, it works perfectly fine for this specific test build.