LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux From Scratch (https://www.linuxquestions.org/questions/linux-from-scratch-13/)
-   -   initramfs - why do we need "init" in root instead of /sbin/init? (https://www.linuxquestions.org/questions/linux-from-scratch-13/initramfs-why-do-we-need-init-in-root-instead-of-sbin-init-4175643160/)

ranshalit 11-27-2018 12:54 AM

initramfs - why do we need "init" in root instead of /sbin/init?
 
Hello,

after a lot of struggle to make initramfs functional, I had 2 discoveries:
1. I *must* put init in the root "/init" before creating the cpio.
2. I need to add to bootargs root=/dev/ram

As to (1) above, I did not find it documented anywhere and I also find it strange that I need to change the rootfs just for the creation of cpio for initramfs.

Does it make sense to copy /sbin/init to /init or do I miss something in my understanding ?

Thanks,
Ran

spiky0011 11-27-2018 03:59 AM

Did you follow the blfs initramfs
http://www.linuxfromscratch.org/blfs...initramfs.html

Jamie Ramone 01-02-2019 06:00 PM

Quote:

Originally Posted by ranshalit (Post 5930482)
Hello,

after a lot of struggle to make initramfs functional, I had 2 discoveries:
1. I *must* put init in the root "/init" before creating the cpio.
2. I need to add to bootargs root=/dev/ram

As to (1) above, I did not find it documented anywhere and I also find it strange that I need to change the rootfs just for the creation of cpio for initramfs.

Does it make sense to copy /sbin/init to /init or do I miss something in my understanding ?

Thanks,
Ran

Hey Ran, I had some trouble building initramfs for the fist time. First: you don't need to do anything to the ACTUAL root file system (i.e. '/'). What you need to do is build a cut down copy of the root file system in a directory of your own (e.g. $HOME/my-initrd/, /tmp/my-initrd, whatever). The init binary needs to be in the root of THAT file system, meaning directly under it. Then you can build the image using cpio, making sure you use the '-newc' parameter (that was my nemesis) or it won't be loaded by the kernel.

This isn't a rigid rule, however. You CAN put init in a subdirectory, but you'll have to use the 'rdinit=' parameter to indicate to the kernel where it is. For example, if your init is in the etc directory, you have to add the following option to the kernel command line:

Code:

... rdinit=/etc/init ...
Insofar as the kernel parameters, using 'root=/dev/ram' will use a ram disk for the file system. This means it uses a block device, meaning it'll use the block cache. This is redundant for a ram based file system, which is why tmpfs was created: it implements a file system in memory with no block cache. All writes are synchronous which, in this case, is actually faster as you don't actually need to cache the data since you're not accessing a container that's slower than RAM, as in the case of a disk. It also does away with the hard limit imposed by a block device. It just grows and shrinks according to the size of the actual data, though it does have a maximum value of half the available RAM or an explicit limit if one was set at mount time.

To use tmpfs, forget about the root= parameter. Use the 'rootfstype=' parameter, and specify tmpfs. You can also specify the simpler ramfs file system type if you like. Here's an example for grub2:

Code:

kernel /boot/kernel/vmlinux rootfstype=tmpfs rw quiet
initrd my-initrd.cpio

Hope that helps! :)


All times are GMT -5. The time now is 12:38 AM.