Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
rescue shells in initramfs
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
sublogic
Apprentice
Apprentice


Joined: 21 Mar 2022
Posts: 222
Location: Pennsylvania, USA

PostPosted: Thu Oct 05, 2023 12:21 am    Post subject: rescue shells in initramfs Reply with quote

(This from a discussion between pietinger and me.)
In the forums and in several wiki pages about hand-crafting an initramfs, we see a shell function like this:
Code:
rescue_shell() {
    echo "$@"
    echo "Something went wrong. Dropping you to a shell."
    busybox --install -s
    exec /bin/sh
}
The /init script invokes this function with an explanatory message when something goes wrong, for example
Code:
mount -t proc none /proc || rescue_shell "mount /proc failed."
In this case the user has to figure out why "mount /proc failed", fix the problem, and exit the rescue shell to let the /init script continue.

But it can't work ! exec /bin/sh replaces the running script by a shell, the shell has pid=1 and if you exit, the kernel panics ! The only way out of such a shell is to exec something else that finishes what the /init script has left undone --or finish all the steps manually.

The function should be
Code:
rescue_shell() {
    echo "$@"
    echo "Something went wrong. Dropping you to a shell."
    busybox --install -s
    /bin/sh
}
without an exec !

(If you think otherwise, and you have an initramfs with such code: I, um, dare you to try it ! An early panic should be a harmless learning experience, right ?)

Time to correct the wiki pages ?
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9691
Location: almost Mile High in the USA

PostPosted: Thu Oct 05, 2023 1:53 am    Post subject: Reply with quote

your observations are correct, but the question is whether or not you want the initramfs script to keep going or not, whether you figured out how to fix the problem that the script was running into (if you can even tell, sometimes the script is so poorly written you can't tell.)

Usually it is best to exec the shell because now it has pid 1. Because of this, you can eventually exec the new init (switch_root) manually and continue the boot, else you have to depend on the script to do the right thing which may be tricky if the script is in bad shape, you don't know where it is, or has a lot of spaghetti logic.
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54308
Location: 56N 3W

PostPosted: Thu Oct 05, 2023 7:30 am    Post subject: Reply with quote

sublogic,

This wiki page started out in my user area.

It contains
Code:
rescue_shell() {
    echo "$@"
    echo "Something went wrong. Dropping you to a shell."
    # The symlinks are not required any longer
    # but it helps tab completion
    /bin/busybox --install -s
    exec /bin/sh
}


When all is well, rescue_shell is never called, so the point you raise does not matter.
With the
Code:
/bin/busybox --install -s
line, user space tools like mount have been destroyed by symbolic links to busybox so mount by UUID no longer works.

The idea was (it wasn't original to me) to be able to poke about in the rescue shell to see what had gone wrong, fix it, make a new initrd and try again.

If you are really lucky, you can do
Code:
more init
or
Code:
cat init
and enter the commands that the init script would have run, at the shell, remembering to mount root by its device name, and bring up the system on top of a broken initrd.

I'm a hardware engineer (maybe it shows in the bits that I did create) , so I'll just say that it works for me.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1549
Location: South America

PostPosted: Thu Oct 05, 2023 4:34 pm    Post subject: Reply with quote

I agree with eccerr0r's post, but I want to highlight this:

eccerr0r wrote:
Usually it is best to exec the shell because now it has pid 1. Because of this, you can eventually exec the new init (switch_root) manually and continue the boot, [...]

switch_root, or at least BusyBox's version, does its thing only when its PID is 1, otherwise it exits with an error. So the only way to be able to switch_root from a rescue shell, if the user could fix whatever prevented the rootfs from being mounted, is doing exec switch_root if the shell is already process 1!
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3357
Location: Rasi, Finland

PostPosted: Thu Oct 05, 2023 4:50 pm    Post subject: Reply with quote

I have this in my /init:
Code:
esh() {
        if [ "$1" = "switch" ]
        then
                ewarn "Switching PID 1 to an emergency shell."
                ewarn "Exiting the shell $(printc 1 'WILL KILL PID 1')."
                local switch=1
                shift
        fi

        [ "$1" ] && eerror "$*"

        ebegin "Starting an emergency shell"
        installenv
        if [ "$switch" ]
        then
                exec setsid cttyhack sh -i
        else
                setsid cttyhack sh -i
        fi
        eend 0
}


So, normally esh() is run without switch, for user to manually correct something and then let /init continue.
However, if things go south enough /init will run esh switch.

That function needs a little more adjustments, but you'll get the idea.

EDIT: installenv() is my custom function to prepare the environment for the shell.
EDIT2: ... as is printc() for coloured text.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
sublogic
Apprentice
Apprentice


Joined: 21 Mar 2022
Posts: 222
Location: Pennsylvania, USA

PostPosted: Sat Oct 07, 2023 12:19 am    Post subject: Reply with quote

eccerr0r wrote:
... Usually it is best to exec the shell because now it has pid 1. ...
I understand, and that seems to be the consensus so far, but I argue that this goes against common practice. For example, both dracut and genkernel go the other way, their rescue shells return to the /init script. Users may expect that behavior if they built their first initramfs that way, or if they have been exposed to them by other distributions. If they now create an initramfs using advice from the wiki they risk an unexpected kernel panic. I think the wiki pages should clarify their choice.

Also the rest of the code in the wiki samples seems to be written for a non-exec rescue shell, for example
Code:
mount -t proc none /proc || rescue_shell "mount /proc failed."
mount -t sysfs none /sys || rescue_shell "mount /sys failed."
mount -t devtmpfs none /dev || rescue_shell "mount /dev failed."
or
Code:
# activate lvm
#  create /dev/mapper/control
lvm vgscan --mknodes || rescue_shell "vgscan failed."
#  activate all LVM volumes
lvm vgchange --sysinit -a ly || rescue_shell "vgchange failed."
#  create device nodes for the volumes
lvm vgscan --mknodes || rescue_shell "vgscan failed."
Both snippets (from Custom_Initramfs/Examples) make more sense if the /init script continues after the shell exits.

(Well, it's a wiki so what am I waiting for ? I'll think about it and stick a pointer to this topic in the discussion pages.)

I like Zucca's approach, by the way. Here there is no risk of confusion because Zucca did it on purpose and knows what to do with either kind of rescue shell.
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9691
Location: almost Mile High in the USA

PostPosted: Sat Oct 07, 2023 1:10 am    Post subject: Reply with quote

See the problem is, what if the problem was none of the above and you actually needed to skip a whole bunch of subsequent steps... or some of the options of the subsequent steps are wrong? If you depend on the script without execing the shell, you're forced to let the script, as wrong as it could be, to finish up boot.

I'd think it's easier to manually finish up the rest of the mounting and then manually exec switch_root.

Either way the script needs to be fixed and really can't be done in rescue shell anyway (well... it *could...*)
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
pingtoo
l33t
l33t


Joined: 10 Sep 2021
Posts: 932
Location: Richmond Hill, Canada

PostPosted: Sat Oct 07, 2023 6:43 pm    Post subject: Reply with quote

I wonder if this discussion is a semantic issue. Is it because the function name is rescue_shell therefor we want to know if the post rescue action should be continue or restart?

I studied few init scripts from some will known names like, alpinelinux, archlinux, debian, genkernel, dracut as well as some less known like better-initramfs and bless-initramfs.

Some of them name the similar function as "Fail", "emergency_shell" or simple "debug". So to me it seems to be that function's role need to be seen in the context of the entire script.

For example What do you expect when switch_root failed? Do you want system halt, reboot or pause and wait for your command? Or if you want to allow network boot from kernel but fail to establish network due to network problem at the moment? it is a rescue operation? or is it a retry operation?

So if you customise a init script you should already know the "context" when the error raise and you already design you options into your script. However if you borrow the function from someone/somewhere you really out to learn the context from the source. Because I think taking the function out of context and discuss what it should or should not is fruitless.

BTW, I believe busybox's ash support alias, so you can write just one function possible with command argument then use alias to create appropriated name for each context,
Back to top
View user's profile Send private message
sublogic
Apprentice
Apprentice


Joined: 21 Mar 2022
Posts: 222
Location: Pennsylvania, USA

PostPosted: Sun Oct 08, 2023 12:36 am    Post subject: Reply with quote

pingtoo wrote:
I studied few init scripts from some will known names like, alpinelinux, archlinux, debian, genkernel, dracut as well as some less known like better-initramfs and bless-initramfs.

Some of them name the similar function as "Fail", "emergency_shell" or simple "debug". So to me it seems to be that function's role need to be seen in the context of the entire script.

Agreed, but when I see code like this near the top of /init,
Code:
mount -t proc none /proc || rescue_shell "mount /proc failed."
mount -t sysfs none /sys || rescue_shell "mount /sys failed."
mount -t devtmpfs none /dev || rescue_shell "mount /dev failed."
I'm thinking they want a rescue subshell. And yet they exec the rescue shell. This is from the third example in Custom_Initramfs/Examples. (Very cool code on that page, BTW.)

Pingtoo, did you find widely used /init scripts that exec their rescue-or-whatever shells ? I only looked at genkernel and dracut, and now better-initramfs and bless-initramfs. All of them use subshells. Hmmm, I have a mothballed eee-PC on the floor with some Ubuntu release or other. I have to look inside. Edit: subshell. Ubuntu 10.04.4 .

Quote:
For example What do you expect when switch_root failed? Do you want system halt, reboot or pause and wait for your command? Or if you want to allow network boot from kernel but fail to establish network due to network problem at the moment? it is a rescue operation? or is it a retry operation?
For the network failure I would say subshell and retry. For switch_root that's easy: press and hold the power button. If switch_root has failed you have to assume that your entire early userspace has been wiped. (From comments at the bottom of the genkernel /init. Also man switch_root and Documentation/filesystems/ramfs-rootfs-initramfs.rst .)

If the shell is to run as pid=1, one way out would be an idempotent /init script, where operations that must run only once are guarded by tests.
Code:
mountpoint -q /proc || mount -t proc     none /proc || rescue_shell "mount /proc failed."
mountpoint -q /sys  || mount -t sysfs    none /sys  || rescue_shell "mount /sys failed."
mountpoint -q /dev  || mount -t devtmpfs none /dev  || rescue_shell "mount /dev failed."
Then you can "exec /init" to rerun the script, or finish the job manually if you so choose. I doubt it's always that easy though.

I also played with passing a small amount of state through "exec sh" and "exec /init" via the environment. The restarted /init looks at the environment to skip work already done. The added boilerplate is small but looks ... weird. Also I can't make it robust if the /init has conditional code, where the condition is altered in the shell. (This proof of concept in toy scripts, not a real /init .)


Last edited by sublogic on Sun Oct 08, 2023 4:31 pm; edited 1 time in total
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 21715

PostPosted: Sun Oct 08, 2023 12:58 am    Post subject: Reply with quote

If exec switch_root fails to start switch_root, then nothing has been changed and the early userspace is intact. If it successfully replaces the current process with switch_root, and later the executed process fails, then this shell is no longer running to even attempt to offer a rescue shell, regardless of how much or how little of the initramfs the switch_root managed to delete.

As a way to compromise on the rescue shell, the init script could implement the rescue as:
Code:
rescue_shell() {
    printf 'Starting rescue subshell: %s\nExit with code 5 to replace /init with a shell running as pid 1\n' "$*"
    /bin/sh
    if [[ $? -eq 5 ]]; then exec /bin/sh; fi
}
This leaves /init paused in the background and gives the user a subshell. If the user repairs the environment enough that resuming /init is the right solution, then the user can exit 0 in the rescue subshell. If the user decides that the remaining /init steps are not appropriate and that the boot must be done manually, the user can exit 5 in the rescue subshell, and /init will replace itself with a rescue non-subshell. From that replacement, the user can exec switch_root or whatever else is needed. The choice of exit 5 is arbitrary. The flag could be any improbable exit code, or could be a specially named file in the initramfs that does not exist, but which the user can create to request that /init should replace itself.
Back to top
View user's profile Send private message
sublogic
Apprentice
Apprentice


Joined: 21 Mar 2022
Posts: 222
Location: Pennsylvania, USA

PostPosted: Sun Oct 08, 2023 1:04 am    Post subject: Reply with quote

Hu wrote:
Code:
rescue_shell() {
    printf 'Starting rescue subshell: %s\nExit with code 5 to replace /init with a shell running as pid 1\n' "$*"
    /bin/sh
    if [[ $? -eq 5 ]]; then exec /bin/sh; fi
}
Now, why didn't I think of that !
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9691
Location: almost Mile High in the USA

PostPosted: Sun Oct 08, 2023 1:05 am    Post subject: Reply with quote

Curious how many people have actually been able to or wish they could resume a initramfs init script safely?

Usually there's some huge reason like a bad kernel .config that would prevent /proc from being mounted and well, resuming this probably means a reboot and you're screwed anyway.

Despite having my own initramfs, I'd rather just do everything manually because I don't have to look carefully at my own script on what else needs to be done to get it to boot, just go do it. Less to think about -- don't need to worry about doing a step that will be done later by mistake, don't need to worry about if the script will die again later because something else went wrong...
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4244
Location: Bavaria

PostPosted: Sun Oct 08, 2023 2:41 am    Post subject: Reply with quote

eccerr0r wrote:
Curious how many people have actually been able to or wish they could resume a initramfs init script safely?

eccerr0r,

I am with you ... for me, a "rescue_shell"-function in a selfmade initramfs has only one simple function:

To be able to read the last messages (+ error message if any) from my init script and see what went wrong ... (so that I can fix my error in the init script or in the kernel config later) ... an init script should be able to catch any error - unless it is unable to mount the root partition and then you have a whole other problem. Before I do anything in a rescue shell I prefer to boot a Linux from the USB stick and try to chroot into my gentoo.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54308
Location: 56N 3W

PostPosted: Sun Oct 08, 2023 9:09 am    Post subject: Reply with quote

The purpose of the rescue_shell() is not to be used at all.
It's there for initrd debugging while the initrd is being proven.

Being able to use it to boot with a broken initrd helps that because chrooting into a system 'partitioned' as
Code:
# lsblk
NAME                     MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda                        8:0    0 931.5G  0 disk
├─sda1                     8:1    0   256M  0 part /boot
└─sda2                     8:2    0 931.3G  0 part
  ├─Pi4_Router-root      254:0    0     2G  0 lvm  /
  ├─Pi4_Router-usr       254:1    0    10G  0 lvm  /usr
  ├─Pi4_Router-var       254:2    0    20G  0 lvm  /var
  ├─Pi4_Router-repos     254:3    0     4G  0 lvm  /var/db/repos
  ├─Pi4_Router-swap      254:4    0     4G  0 lvm 
  ├─Pi4_Router-src       254:5    0    20G  0 lvm  /usr/src
  ├─Pi4_Router-build     254:6    0    40G  0 lvm  /var/tmp/portage
  ├─Pi4_Router-home      254:7    0    40G  0 lvm  /home
  ├─Pi4_Router-opt       254:8    0     3G  0 lvm  /opt
  ├─Pi4_Router-binpkg    254:9    0    40G  0 lvm  /var/cache/binpkgs
  └─Pi4_Router-distfiles 254:10   0    40G  0 lvm  /var/cache/distfiles
is a PITA.
OK, I know to mount Pi4_Router-root, then run humpty_dumpty.sh to put it back together :)
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
pingtoo
l33t
l33t


Joined: 10 Sep 2021
Posts: 932
Location: Richmond Hill, Canada

PostPosted: Sun Oct 08, 2023 11:47 am    Post subject: Reply with quote

sublogic wrote:
Pingtoo, did you find widely used /init scripts that exec their rescue-or-whatever shells ? I only looked at genkernel and dracut, and now better-initramfs and bless-initramfs. All of them use subshells
I think the reason is them have much complex logic because their init does a lot more than simple find rootfs from a disk partition.

If you have encrypted rootfs, use special file system feature and/or special block device management you most likely want to return back to init to let it finish the whole logic.

I dislike current init script style, most of them have code logic grew from many generation with multiple contributor, cause the code hard to understand.

I am trying (not yet start, but still thinking about it all the time) to use finite state machine (FSM), so the script can be reentry with parameters. I want my init can manage network booting and using overlay and hopefully can be kernel version free (I wish my kernel is modulated, as small as possible).
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54308
Location: 56N 3W

PostPosted: Sun Oct 08, 2023 12:06 pm    Post subject: Reply with quote

pingtoo,

initrd/initrams tend to be rather like the rumoured QA on motherboard firmware.

Does it boot Windows?
Ship it.

Once the initrd works, it's never touched.

Its much the same for Gentoo installers, for two reasons,
1. The diversity of installed systems
2. Few users reinstall during the like of the hardware.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
pingtoo
l33t
l33t


Joined: 10 Sep 2021
Posts: 932
Location: Richmond Hill, Canada

PostPosted: Sun Oct 08, 2023 1:43 pm    Post subject: Reply with quote

NeddySeagoon wrote:
pingtoo,

initrd/initrams tend to be rather like the rumoured QA on motherboard firmware.

Does it boot Windows?
Ship it.

Once the initrd works, it's never touched.

Its much the same for Gentoo installers, for two reasons,
1. The diversity of installed systems
2. Few users reinstall during the like of the hardware.
Understood, Part of my idea is just that I want to prove myself I can do that. the other part of it is that I think I will incrementally develop so I want to be able to create a flow than insert functionality one at a time.
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3357
Location: Rasi, Finland

PostPosted: Sun Oct 08, 2023 4:39 pm    Post subject: Reply with quote

sublogic wrote:
Now, why didn't I think of that !
Indeed. I've got to re-implement my emergency shell function now. :D
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
sublogic
Apprentice
Apprentice


Joined: 21 Mar 2022
Posts: 222
Location: Pennsylvania, USA

PostPosted: Sun Oct 08, 2023 4:46 pm    Post subject: Reply with quote

[quote="pingtoo"]
sublogic wrote:
I dislike current init script style, most of them have code logic grew from many generation with multiple contributor, cause the code hard to understand.

Me too. If you boot a single computer the /init can be short and to the point. If you also have a couple of spare, old computers you may want a universal /init script to use on all of them, and therein lies feature creep. If you have to handle any setup, you get a mess.
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9691
Location: almost Mile High in the USA

PostPosted: Mon Oct 09, 2023 1:54 am    Post subject: Reply with quote

I likewise am suffering feature creep because I want to use the same initramfs on my root on RAID machines to my root on cryptoroot to root on cryptoRAIDroot to my single disk machines (so I can use root=LABEL=) as well as my PXE boot systems, and that the PXE machines do not like my initramfs at all...
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2014

PostPosted: Mon Oct 09, 2023 7:53 am    Post subject: Reply with quote

I've vaguely wondered about packaging a generic init as an ebuild with USE flags along the lines of "lukx mdraid fsck ...", with the obvious result that each flag selects the appropriate stanzas in the "case param in" loop processing the command line.
_________________
Greybeard
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3357
Location: Rasi, Finland

PostPosted: Mon Oct 09, 2023 8:28 am    Post subject: Reply with quote

My approach is that /init has several functions and at the end it tries to source /rc.
/rc is custom script on all of my setups while /init stays the same.
If there's no /rc then /init tries to find root by itself.

Btw... Does anyone remember reading that /linuxrc file being the first thing kernel executes instead of /init? Sure there are hits if you search for "/linuxrc"...
I remember trying to rename /init to /linuxrc. Panic was all I got.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54308
Location: 56N 3W

PostPosted: Mon Oct 09, 2023 8:35 am    Post subject: Reply with quote

Zucca.

Its mentioned in /usr/src/linux/Documentation/admin-guide/initrd.rst, along with loadlin and floppy booting.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
sublogic
Apprentice
Apprentice


Joined: 21 Mar 2022
Posts: 222
Location: Pennsylvania, USA

PostPosted: Mon Oct 09, 2023 9:33 pm    Post subject: Reply with quote

NeddySeagoon wrote:
Zucca.
[/linuxrc is] mentioned in /usr/src/linux/Documentation/admin-guide/initrd.rst, along with loadlin and floppy booting.

Huh ! No, it says /sbin/init since commit 9d9a2000e68 ! The /linuxrc is mentioned at the end of the file, in bits that the commit missed !

Code:
commit 9d9a2000e683ecd497b65d5f3e73b048c68976e1
Author: Domenico Andreoli <cavokz@gmail.com>
Date:   Wed May 23 13:58:11 2007 -0700

    documentation: Documentation/initrd.txt
   
    Final clearification of the pivot_root mechanism, which brings this
    document really up-to-date.


Code:
diff --git a/Documentation/initrd.txt b/Documentation/initrd.txt
index 15f1b35deb34..d3dc505104da 100644
--- a/Documentation/initrd.txt
+++ b/Documentation/initrd.txt
@@ -27,16 +27,20 @@ When using initrd, the system typically boots as follows:
   1) the boot loader loads the kernel and the initial RAM disk
   2) the kernel converts initrd into a "normal" RAM disk and
      frees the memory used by initrd
-  3) initrd is mounted read-write as root
-  4) /linuxrc is executed (this can be any valid executable, including
+  3) if the root device is not /dev/ram0, the old (deprecated)
+     change_root procedure is followed. see the "Obsolete root change
+     mechanism" section below.
+  4) root device is mounted. if it is /dev/ram0, the initrd image is
+     then mounted as root
+  5) /sbin/init is executed (this can be any valid executable, including
      shell scripts; it is run with uid 0 and can do basically everything
-     init can do)
-  5) linuxrc mounts the "real" root file system
-  6) linuxrc places the root file system at the root directory using the
+     init can do).
+  6) init mounts the "real" root file system
+  7) init places the root file system at the root directory using the
      pivot_root system call
-  7) the usual boot sequence (e.g. invocation of /sbin/init) is performed
-     on the root file system
-  8) the initrd file system is removed
+  8) init execs the /sbin/init on the new root filesystem, performing
+     the usual boot sequence
+  9) the initrd file system is removed
...
Back to top
View user's profile Send private message
pingtoo
l33t
l33t


Joined: 10 Sep 2021
Posts: 932
Location: Richmond Hill, Canada

PostPosted: Tue Oct 10, 2023 10:55 am    Post subject: Reply with quote

Just to be clear,

/init is for initramfs.
/linuxrc is for initrd.

initramfs is new based on cpio format.
initrd is old based on block device format.

initramfs is mean to replace initrd, however initrd is still supported in mainline linux code.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum