cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
bfung_2
Adventurer
Adventurer
770 Views
Registered: ‎07-02-2020

initrd vs. "real" rootFS w/ petalinux

Jump to solution

This is a question about proper "style" and best practices.

It seems that I can either mount a "real" root file system (the one in which userland programs run, and users read/write to), or I can make use of the initrd (initial ram disk, which typically precedes the mounting of the "real" root file system and prepares the kernel for this.

I'm thinking of just using the initrd as my "real" root file system instead.

Why shouldn't I do this? What would be the performance difference?

 

Thanks.

0 Kudos
1 Solution

Accepted Solutions
rfs613
Scholar
Scholar
732 Views
Registered: ‎05-28-2013

Both methods have their use cases, and which one is right for you depends on your application and hardware.

In an initrd, changes made at runtime (like writing data, modifying files) do not persist across reboot. This can be viewed as an advantage (you can't "mess up" the initrd) or a disadvantage (because you might want to store some data persistently).

The main downside of an initrd is memory use. The entire initrd will occupy RAM regardless if the programs/data therein are running or not. As your initrd becomes larger this can be a problem, especially if you have limited RAM on your system.

In contrast a "real" root, backed by some kind of storage (such as harddisk/SD/eMMC/USB), programs/data will be loaded into RAM as needed. Any unused RAM will be used as a cache, so essentially the data ends up in RAM (like initrd) but can be purged when space gets low.

Configuring a "real" root is more complicated, esp. for beginners, since there are many choices about the type of storage, how to partition it, which filesystem to use, etc. This is one of the reasons why initrd is often used for beginners, since it is simpler to get going.

Performance wise, RAM is typically faster than loading from disk. However in practise the difference is usually negligible, due to being CPU bound rather than I/O bound.

Historical note: initrd was initially designed as a pre-boot step, used to load device drivers, setup RAID, and so on, prior to switching over to the "real" root.

View solution in original post

3 Replies
rfs613
Scholar
Scholar
733 Views
Registered: ‎05-28-2013

Both methods have their use cases, and which one is right for you depends on your application and hardware.

In an initrd, changes made at runtime (like writing data, modifying files) do not persist across reboot. This can be viewed as an advantage (you can't "mess up" the initrd) or a disadvantage (because you might want to store some data persistently).

The main downside of an initrd is memory use. The entire initrd will occupy RAM regardless if the programs/data therein are running or not. As your initrd becomes larger this can be a problem, especially if you have limited RAM on your system.

In contrast a "real" root, backed by some kind of storage (such as harddisk/SD/eMMC/USB), programs/data will be loaded into RAM as needed. Any unused RAM will be used as a cache, so essentially the data ends up in RAM (like initrd) but can be purged when space gets low.

Configuring a "real" root is more complicated, esp. for beginners, since there are many choices about the type of storage, how to partition it, which filesystem to use, etc. This is one of the reasons why initrd is often used for beginners, since it is simpler to get going.

Performance wise, RAM is typically faster than loading from disk. However in practise the difference is usually negligible, due to being CPU bound rather than I/O bound.

Historical note: initrd was initially designed as a pre-boot step, used to load device drivers, setup RAID, and so on, prior to switching over to the "real" root.

View solution in original post

bfung_2
Adventurer
Adventurer
721 Views
Registered: ‎07-02-2020
@rfs613 thanks, this really helped!

And just to finish up, how does initramfs then compare with these two?
0 Kudos
rfs613
Scholar
Scholar
705 Views
Registered: ‎05-28-2013

And just to finish up, how does initramfs then compare with these two?

I had assumed you were using initramfs and initrd interchangeably. The answer is largely the same: initramfs is non-persistent, it has fewer settings to twiddle than a 'real' rootfs, etc. However it still takes up RAM.

The main practical difference between initrd and initramfs lies in how it uses memory when running programs. The newer initramfs avoids making additional memory copy of each program that you run. It instead does what you would expect, namely to use the RAM already used by the initramfs.

So, initramfs is better at memory usage than initrd. However in both cases you are are dedicating a portion of your RAM to hold code/data, even though you are unlikely to be using all of that code/data at once.