LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices


Reply
  Search this Thread
Old 11-27-2018, 12:54 AM   #1
ranshalit
LQ Newbie
 
Registered: Apr 2011
Posts: 10

Rep: Reputation: 0
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
 
Old 11-27-2018, 03:59 AM   #2
spiky0011
Senior Member
 
Registered: Jan 2011
Location: PLANET-SPIKE
Distribution: /LFS/Debian
Posts: 2,511
Blog Entries: 1

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
Did you follow the blfs initramfs
http://www.linuxfromscratch.org/blfs...initramfs.html
 
1 members found this post helpful.
Old 01-02-2019, 06:00 PM   #3
Jamie Ramone
Member
 
Registered: Jul 2018
Posts: 35

Rep: Reputation: 11
Quote:
Originally Posted by ranshalit View Post
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!
 
  


Reply

Tags
boot, init, initramfs



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rootdev not found by /sbin/init from initramfs Bourdieu Slackware 32 09-14-2015 09:36 AM
/etc/acpi/acpi_handler.sh uses /sbin/init instead of /sbin/shutdown xj25vm Slackware 2 04-07-2013 04:10 AM
Chkroot scan - /sbin/init & /sbin/ifconfig INFECTED bicoba Linux - Security 4 06-07-2006 09:16 AM
Want2use /sbin cmds undr non-root account w/o sudo. Is it safe 2 add /sbin 2 my PATH? kornerr Linux - General 4 02-25-2005 09:29 AM
As root, not seeing /sbin and /usr/sbin in path weghman Linux - Newbie 3 04-25-2004 01:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch

All times are GMT -5. The time now is 02:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration