How do I have Linux boot with a rootfs in RAM?

The rootfs is a squashfs image and my bootloader is loading it into some address in SDRAM. What parameters do I need to pass to the kernel so It can mount the rootfs from there? Squashfs support is built-in and it already works with

root=/dev/mtdblock2 rootfstype=squashfs

for booting from the flash.

EDIT: This is a MIPS based embedded device, using a custom bootloader. Normally, the bootloader extracts the compressed kernel from the flash into the SDRAM, and then kernel mounts /dev/mtdblock2 as the rootfs.
I am trying to improve the bootloader so it can download an image to its RAM and boot without writing to the flash.

I cannot figure out how to make Linux mount a filesystem image in the RAM as the rootfs.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I would use an initramfs. (http://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt)

Many Linux distributions use an initramfs (not to be confused with an initrd, they are different) during the boot process, mostly to be able to start userspace programs very early in the boot process. However, you can use it for whatever you want.

The benefit of an initramfs over an initrd is that an initramfs uses a tmpfs filesystem while an initrd uses a ram block device. The key difference here is that for an initrd, you must preallocate all the space for the filesystem, even if you’re not going to use all that space. So if you don’t use the filesystem space, you waste ram, which on an embedded device, is often a scarce resource. Tmpfs is a filesystem which runs out of ram, but only uses as much ram as is currently in use on the filesystem. So if you delete a file from a tmpfs, that ram is immediately freed up.

Now normally an initramfs is temporary, only used to run some programs extremely early in the boot process. After those programs run, control is turned over to the real filesystem running on a physical disk. However, you do not have to do that. There is nothing stopping you from running out of the initramfs indefinitely.

Method 2

Are the rd_start and rd_size options sufficient?

It seems the ARM port may have a syntax for the initrd option:

root=/dev/ram0 rw initrd=0x87000000,8M

Method 3

I use the phram driver for this purpose: it emulates an MTD device using physical memory, meaning you can use exactly the same rootfs image for testing/development that you are later going to burn to the real flash. The necesary magic on the kernel command line would be something like

phram.phram=rootfs,0x100000,9Mi root=/dev/mtdblock0 memmap=9M$100000

Note that you also need the memmap argument to make sure the kernel doesn’t try to use that memory for itself. 9MB is how big my rootfs is (or was). The before $ is needed in my bootloader, may not be in yours. The address I’ve chosen there is arbitrary, because I don’t know how physical memory is laid out on your device, so pick one that makes sense for you. I assume you previously used tftp or something to load your rootfs in at that address


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x