LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Boot process; execution of init; initramfs (https://www.linuxquestions.org/questions/linux-general-1/boot-process%3B-execution-of-init%3B-initramfs-945788/)

0x53h 05-18-2012 03:46 PM

Boot process; execution of init; initramfs
 
This is my first post, so please point me in the right direction if needed. My studies have focused on embedded systems and right now gaining a full understanding of the Linux boot process. I would like to be able to create a BusyBox environment mostly from scratch.

My understanding so far is that after the kernel loads, init is executed. The default location of init is /sbin/init. The BusyBox faq states that you should be able to statically compile a simple 'Hello World' program and use it in place of init to see the message displayed.

1. Is it true that a statically compiled Hello World program should execute at the end of the kernel loading if I simply place it in /sbin/init (or point to it with an init=/sbin/init boot parameter)? Because that hasn't worked for me yet.

2. In beginning to research this problem I've come across how-to documents showing the creation if an initramfs. I don't want to go down a deprecated path again; done that too many times. Is initramfs still relevant?

Any additional sage advice would be super-appreciated. I've spent a week learning so much already, but could definitely have used guidance in avoiding some of the outdated materials I've found.

Ser Olmy 05-18-2012 05:12 PM

Don't know if this qualifies as "sage advice", but the boot process works like this:
  1. A boot loader loads the Linux kernel file into memory. It may also load an initrd/initramfs image, depending on the configuration.
  2. The boot loader executes the kernel file, possibly also passing on some boot parameters.
  3. The kernel file decompresses itself, and initializes the hardware. Devices are served by built-in drivers, if available.
  4. The kernel attempts to mount the root file system. The name of the root device may have been given as a parameter by the boot loader. If not, defaults given at compile time are used. The root device may be a physical disk or the file system from step 1. The file system driver must be compiled into the kernel for this to work.
  5. Assuming the previous step succeded, /sbin/init is executed. I've heard rumours that some systems with initrds start /linuxrc instead, but my Slackware initrd uses the standard /sbin/init.
And yes, using a statically compiled "Hello world" executable as /sbin/init should work (for very small quantities of "work").

Initramfs is just a (compressed) cpio archive that gets copied to a tempfs file system in RAM and then used as a root file system. It's an alternative to the older initrd concept, where a (compressed) image file containing a file system is used. Since initramfs is the more recent of the two, it's not likely to be deprecated any time soon (but then neither is initrd).

0x53h 05-19-2012 11:26 AM

It does work! At least, as you described, for limited quantities of "work". I had been compiling on a 64-bit system, but booting x86. The kernel only complains that init couldn't be found and to try passing the init= parameter; not a mention about inability to run. Thank you - I had been questioning whether the file system was mounting, I was putting the file in the wrong place, everything - you helped narrow it down.

I'll have to look further into the differences between the two (initramfs and initrd) to evaluate which would be a better fit for the hardware I'm targeting.


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