Are all kernel argument really used by the kernel?Why does Linux allow ‘init=/bin/bash’?Splash in PID...
Does ultrasonic bath cleaning damage laboratory volumetric glassware calibration?
How can Charles Proxy change settings without admin rights after first time?
Why isn’t the tax system continuous rather than bracketed?
Is my Rep in Stack-Exchange Form?
Declining an offer to present a poster instead of a paper
How many codes are possible?
Mount a folder with a space on Linux
Why does the numerical solution of an ODE move away from an unstable equilibrium?
Ending: accusative or not?
Analog is Obtuse!
Symbolic equivalent of chmod 400
STM Microcontroller burns every time
Why does adding parentheses prevent an error?
What would Earth look like at night in medieval times?
Why cruise at 7000' in an A319?
How often can a PC check with passive perception during a combat turn?
How can I convince my reader that I will not use a certain trope?
Simple object validator with a new API
Should I tell my insurance company I'm making payments on my new car?
What is this particular type of chord progression, common in classical music, called?
How to perform Login Authentication at the client-side?
What is this opening trap called, and how should I play afterwards? How can I refute the gambit, and play if I accept it?
How could mana leakage be dangerous to a elf?
Why do some games show lights shine through walls?
Are all kernel argument really used by the kernel?
Why does Linux allow ‘init=/bin/bash’?Splash in PID =1Take initrd out of the Linux boot processHow is the kernel loaded?Are Linux drivers part of the kernel or the rootfsWhat entropy sources are used by the Linux kernel?Patching the kernel to allow booting without initrduCLinux (linux 4.9 nommu) VFS: Cannot open root device “(null)”Running a current Linux OS on older kernel (what are the / are there disadvantages?)How to pass arguments to a Linux kernel `init=` bootparam?Did the pivot_root() documentation anticipate the feature of mount namespaces?How does linux know where the rootfs is?kernel sysfs doesn't recognize storage kobjects
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
Why does Linux allow ‘init=/bin/bash’?
I read this, answers are saying it's KERNEL running this init program.
Then I started to wonder, Linux usually comes with a initramfs, which will eventually mount and pivot_root to real root filesystem. So what does this init
argument mean? The path in the initramfs? Or like I guessed, it's not read by the kernel but by init of initramfs to exec the real init.
Also, the root=UUID=xxxx
argument, is that really read by kernel or just by init of initramfs to find the real root filesystem?
It seems like I can pass any argument I want as kernel arguments, so are they all read by the kernel or at least some of them are only meaningful to userspace programs?
linux-kernel
add a comment |
Why does Linux allow ‘init=/bin/bash’?
I read this, answers are saying it's KERNEL running this init program.
Then I started to wonder, Linux usually comes with a initramfs, which will eventually mount and pivot_root to real root filesystem. So what does this init
argument mean? The path in the initramfs? Or like I guessed, it's not read by the kernel but by init of initramfs to exec the real init.
Also, the root=UUID=xxxx
argument, is that really read by kernel or just by init of initramfs to find the real root filesystem?
It seems like I can pass any argument I want as kernel arguments, so are they all read by the kernel or at least some of them are only meaningful to userspace programs?
linux-kernel
add a comment |
Why does Linux allow ‘init=/bin/bash’?
I read this, answers are saying it's KERNEL running this init program.
Then I started to wonder, Linux usually comes with a initramfs, which will eventually mount and pivot_root to real root filesystem. So what does this init
argument mean? The path in the initramfs? Or like I guessed, it's not read by the kernel but by init of initramfs to exec the real init.
Also, the root=UUID=xxxx
argument, is that really read by kernel or just by init of initramfs to find the real root filesystem?
It seems like I can pass any argument I want as kernel arguments, so are they all read by the kernel or at least some of them are only meaningful to userspace programs?
linux-kernel
Why does Linux allow ‘init=/bin/bash’?
I read this, answers are saying it's KERNEL running this init program.
Then I started to wonder, Linux usually comes with a initramfs, which will eventually mount and pivot_root to real root filesystem. So what does this init
argument mean? The path in the initramfs? Or like I guessed, it's not read by the kernel but by init of initramfs to exec the real init.
Also, the root=UUID=xxxx
argument, is that really read by kernel or just by init of initramfs to find the real root filesystem?
It seems like I can pass any argument I want as kernel arguments, so are they all read by the kernel or at least some of them are only meaningful to userspace programs?
linux-kernel
linux-kernel
asked Oct 4 '18 at 14:20
炸鱼薯条德里克炸鱼薯条德里克
6461 gold badge4 silver badges17 bronze badges
6461 gold badge4 silver badges17 bronze badges
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Parameters passed on the kernel command line don’t have to be meaningful for the kernel: the kernel parameters documentation says
The kernel parses parameters from the kernel command line up to “–”; if it doesn’t recognize a parameter and it doesn’t contain a ‘.’, the parameter gets passed to init: parameters with ‘=’ go into init’s environment, others are passed as command line arguments to init. Everything after “–” is passed as an argument to init.
This doesn’t apply to init
and root
which really are kernel parameters, and are handled by the kernel. They can also be acted upon by user-space, since they appear in /proc/cmdline
. (Thus for example systemd takes the quiet
kernel parameter into account to reduce its output.)
When the kernel is booted with an initramfs, the init
and root
parameters aren’t used by the kernel directly; as far as the kernel is concerned, they are fall-backs in case the initramfs doesn’t work (but they are still kernel parameters). The initramfs itself is the root file system (at least for booting), and the kernel looks for an init
executable in the root directory of the initramfs and runs that. If anything fails (the initramfs isn’t usable, or doesn’t contain /init
, or the latter isn’t executable), the kernel will try to mount the device specified by its root
parameter, and run /sbin/init
or the executable specified by the init
parameter.
Also a little curious, what if init-in-the-initramfs is a set-uid-non-root file? A file without executable bit? Will it be run as root anyway? What if it's broken ELF or can't findld-linux.so
ELF or recursion-too-deep script or anything just can't be execve?
– 炸鱼薯条德里克
Oct 4 '18 at 14:58
3
I'm pretty sure the kernel doesn't load the program specified in "init=" from the initramfs. It an initramfs is in use then it seems to run as normal before the user-specified init program is run (not sure if it's the kernel that does this or code in the initramfs).
– plugwash
Oct 4 '18 at 15:31
2
@plugwash you’re right, the kernel runs/init
from the initramfs, and if that doesn’t exist, tries to run the program specified ininit=
, or/sbin/init
, from the root file system.
– Stephen Kitt
Oct 4 '18 at 15:40
add a comment |
Passing custom kernel arguments is one way to customize a system during a KickStart install, for example a PXE server could set:
linuxefi /c7/vmlinuz ks=http://.../ks/c7 lab ksdevice=eth0 net.ifnames=0 biosdevname=0
where lab
is then used in the KickStart configuration to do different things than for other system builds:
%pre
...
case " $(cat /proc/cmdline)" in
...
* lab*)
filesystems_lab
;;
*)
filesystems_common
;;
...
Here to setup a different filesystem layout than used on other system types. Hopefully different labels are used for local customizations than are used by the kernel, given the single namespace involved.
add a comment |
This famous bit of kernel code below is easy to understand --- it's just comments, panics and filenames!
execute_command contains the init= option: if you give a name there, but running it fails, you get a "Requested init xyz failed" error/panic.
Without a init= option, the kernel tries these four commands, from /sbin/init to /bin/sh. If these standard files are all missing, you get a "No working init found" panic.
And notice:
Try passing init= option to kernel
This is from Mr. Linux himself, unchanged for about 30 years. Initrd came later, in two steps...
So then, why does Linux "allow" init=/bin/bash? As you can see below, the kernel is one line away from panicking. It might be hard to see why, but rather than take care of zero processes and show a blinking cursor, the kernel decides to panic.
/*
* We try each of these until one succeeds.
*
* The Bourne shell can be used instead of init if we are
* trying to recover a really broken machine.
*/
if (execute_command) {
ret = run_init_process(execute_command);
if (!ret)
return 0;
panic("Requested init %s failed (error %d).",
execute_command, ret);
}
if (!try_to_run_init_process("/sbin/init") ||
!try_to_run_init_process("/etc/init") ||
!try_to_run_init_process("/bin/init") ||
!try_to_run_init_process("/bin/sh"))
return 0;
panic("No working init found. Try passing init= option to kernel. "
"See Linux Documentation/admin-guide/init.rst for guidance.");
}
In a initrd you need this switch_root/pivot_root/chroot trick to change root and pass PID1 to the real init: default sbin/init, something else or whatever init= wishes.
switch_root [newrootdir] [init] [args to init]
In any case, initrd makes a complex procedure even more complex...
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473260%2fare-all-kernel-argument-really-used-by-the-kernel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Parameters passed on the kernel command line don’t have to be meaningful for the kernel: the kernel parameters documentation says
The kernel parses parameters from the kernel command line up to “–”; if it doesn’t recognize a parameter and it doesn’t contain a ‘.’, the parameter gets passed to init: parameters with ‘=’ go into init’s environment, others are passed as command line arguments to init. Everything after “–” is passed as an argument to init.
This doesn’t apply to init
and root
which really are kernel parameters, and are handled by the kernel. They can also be acted upon by user-space, since they appear in /proc/cmdline
. (Thus for example systemd takes the quiet
kernel parameter into account to reduce its output.)
When the kernel is booted with an initramfs, the init
and root
parameters aren’t used by the kernel directly; as far as the kernel is concerned, they are fall-backs in case the initramfs doesn’t work (but they are still kernel parameters). The initramfs itself is the root file system (at least for booting), and the kernel looks for an init
executable in the root directory of the initramfs and runs that. If anything fails (the initramfs isn’t usable, or doesn’t contain /init
, or the latter isn’t executable), the kernel will try to mount the device specified by its root
parameter, and run /sbin/init
or the executable specified by the init
parameter.
Also a little curious, what if init-in-the-initramfs is a set-uid-non-root file? A file without executable bit? Will it be run as root anyway? What if it's broken ELF or can't findld-linux.so
ELF or recursion-too-deep script or anything just can't be execve?
– 炸鱼薯条德里克
Oct 4 '18 at 14:58
3
I'm pretty sure the kernel doesn't load the program specified in "init=" from the initramfs. It an initramfs is in use then it seems to run as normal before the user-specified init program is run (not sure if it's the kernel that does this or code in the initramfs).
– plugwash
Oct 4 '18 at 15:31
2
@plugwash you’re right, the kernel runs/init
from the initramfs, and if that doesn’t exist, tries to run the program specified ininit=
, or/sbin/init
, from the root file system.
– Stephen Kitt
Oct 4 '18 at 15:40
add a comment |
Parameters passed on the kernel command line don’t have to be meaningful for the kernel: the kernel parameters documentation says
The kernel parses parameters from the kernel command line up to “–”; if it doesn’t recognize a parameter and it doesn’t contain a ‘.’, the parameter gets passed to init: parameters with ‘=’ go into init’s environment, others are passed as command line arguments to init. Everything after “–” is passed as an argument to init.
This doesn’t apply to init
and root
which really are kernel parameters, and are handled by the kernel. They can also be acted upon by user-space, since they appear in /proc/cmdline
. (Thus for example systemd takes the quiet
kernel parameter into account to reduce its output.)
When the kernel is booted with an initramfs, the init
and root
parameters aren’t used by the kernel directly; as far as the kernel is concerned, they are fall-backs in case the initramfs doesn’t work (but they are still kernel parameters). The initramfs itself is the root file system (at least for booting), and the kernel looks for an init
executable in the root directory of the initramfs and runs that. If anything fails (the initramfs isn’t usable, or doesn’t contain /init
, or the latter isn’t executable), the kernel will try to mount the device specified by its root
parameter, and run /sbin/init
or the executable specified by the init
parameter.
Also a little curious, what if init-in-the-initramfs is a set-uid-non-root file? A file without executable bit? Will it be run as root anyway? What if it's broken ELF or can't findld-linux.so
ELF or recursion-too-deep script or anything just can't be execve?
– 炸鱼薯条德里克
Oct 4 '18 at 14:58
3
I'm pretty sure the kernel doesn't load the program specified in "init=" from the initramfs. It an initramfs is in use then it seems to run as normal before the user-specified init program is run (not sure if it's the kernel that does this or code in the initramfs).
– plugwash
Oct 4 '18 at 15:31
2
@plugwash you’re right, the kernel runs/init
from the initramfs, and if that doesn’t exist, tries to run the program specified ininit=
, or/sbin/init
, from the root file system.
– Stephen Kitt
Oct 4 '18 at 15:40
add a comment |
Parameters passed on the kernel command line don’t have to be meaningful for the kernel: the kernel parameters documentation says
The kernel parses parameters from the kernel command line up to “–”; if it doesn’t recognize a parameter and it doesn’t contain a ‘.’, the parameter gets passed to init: parameters with ‘=’ go into init’s environment, others are passed as command line arguments to init. Everything after “–” is passed as an argument to init.
This doesn’t apply to init
and root
which really are kernel parameters, and are handled by the kernel. They can also be acted upon by user-space, since they appear in /proc/cmdline
. (Thus for example systemd takes the quiet
kernel parameter into account to reduce its output.)
When the kernel is booted with an initramfs, the init
and root
parameters aren’t used by the kernel directly; as far as the kernel is concerned, they are fall-backs in case the initramfs doesn’t work (but they are still kernel parameters). The initramfs itself is the root file system (at least for booting), and the kernel looks for an init
executable in the root directory of the initramfs and runs that. If anything fails (the initramfs isn’t usable, or doesn’t contain /init
, or the latter isn’t executable), the kernel will try to mount the device specified by its root
parameter, and run /sbin/init
or the executable specified by the init
parameter.
Parameters passed on the kernel command line don’t have to be meaningful for the kernel: the kernel parameters documentation says
The kernel parses parameters from the kernel command line up to “–”; if it doesn’t recognize a parameter and it doesn’t contain a ‘.’, the parameter gets passed to init: parameters with ‘=’ go into init’s environment, others are passed as command line arguments to init. Everything after “–” is passed as an argument to init.
This doesn’t apply to init
and root
which really are kernel parameters, and are handled by the kernel. They can also be acted upon by user-space, since they appear in /proc/cmdline
. (Thus for example systemd takes the quiet
kernel parameter into account to reduce its output.)
When the kernel is booted with an initramfs, the init
and root
parameters aren’t used by the kernel directly; as far as the kernel is concerned, they are fall-backs in case the initramfs doesn’t work (but they are still kernel parameters). The initramfs itself is the root file system (at least for booting), and the kernel looks for an init
executable in the root directory of the initramfs and runs that. If anything fails (the initramfs isn’t usable, or doesn’t contain /init
, or the latter isn’t executable), the kernel will try to mount the device specified by its root
parameter, and run /sbin/init
or the executable specified by the init
parameter.
edited Oct 5 '18 at 8:11
answered Oct 4 '18 at 14:40
Stephen KittStephen Kitt
192k26 gold badges459 silver badges528 bronze badges
192k26 gold badges459 silver badges528 bronze badges
Also a little curious, what if init-in-the-initramfs is a set-uid-non-root file? A file without executable bit? Will it be run as root anyway? What if it's broken ELF or can't findld-linux.so
ELF or recursion-too-deep script or anything just can't be execve?
– 炸鱼薯条德里克
Oct 4 '18 at 14:58
3
I'm pretty sure the kernel doesn't load the program specified in "init=" from the initramfs. It an initramfs is in use then it seems to run as normal before the user-specified init program is run (not sure if it's the kernel that does this or code in the initramfs).
– plugwash
Oct 4 '18 at 15:31
2
@plugwash you’re right, the kernel runs/init
from the initramfs, and if that doesn’t exist, tries to run the program specified ininit=
, or/sbin/init
, from the root file system.
– Stephen Kitt
Oct 4 '18 at 15:40
add a comment |
Also a little curious, what if init-in-the-initramfs is a set-uid-non-root file? A file without executable bit? Will it be run as root anyway? What if it's broken ELF or can't findld-linux.so
ELF or recursion-too-deep script or anything just can't be execve?
– 炸鱼薯条德里克
Oct 4 '18 at 14:58
3
I'm pretty sure the kernel doesn't load the program specified in "init=" from the initramfs. It an initramfs is in use then it seems to run as normal before the user-specified init program is run (not sure if it's the kernel that does this or code in the initramfs).
– plugwash
Oct 4 '18 at 15:31
2
@plugwash you’re right, the kernel runs/init
from the initramfs, and if that doesn’t exist, tries to run the program specified ininit=
, or/sbin/init
, from the root file system.
– Stephen Kitt
Oct 4 '18 at 15:40
Also a little curious, what if init-in-the-initramfs is a set-uid-non-root file? A file without executable bit? Will it be run as root anyway? What if it's broken ELF or can't find
ld-linux.so
ELF or recursion-too-deep script or anything just can't be execve?– 炸鱼薯条德里克
Oct 4 '18 at 14:58
Also a little curious, what if init-in-the-initramfs is a set-uid-non-root file? A file without executable bit? Will it be run as root anyway? What if it's broken ELF or can't find
ld-linux.so
ELF or recursion-too-deep script or anything just can't be execve?– 炸鱼薯条德里克
Oct 4 '18 at 14:58
3
3
I'm pretty sure the kernel doesn't load the program specified in "init=" from the initramfs. It an initramfs is in use then it seems to run as normal before the user-specified init program is run (not sure if it's the kernel that does this or code in the initramfs).
– plugwash
Oct 4 '18 at 15:31
I'm pretty sure the kernel doesn't load the program specified in "init=" from the initramfs. It an initramfs is in use then it seems to run as normal before the user-specified init program is run (not sure if it's the kernel that does this or code in the initramfs).
– plugwash
Oct 4 '18 at 15:31
2
2
@plugwash you’re right, the kernel runs
/init
from the initramfs, and if that doesn’t exist, tries to run the program specified in init=
, or /sbin/init
, from the root file system.– Stephen Kitt
Oct 4 '18 at 15:40
@plugwash you’re right, the kernel runs
/init
from the initramfs, and if that doesn’t exist, tries to run the program specified in init=
, or /sbin/init
, from the root file system.– Stephen Kitt
Oct 4 '18 at 15:40
add a comment |
Passing custom kernel arguments is one way to customize a system during a KickStart install, for example a PXE server could set:
linuxefi /c7/vmlinuz ks=http://.../ks/c7 lab ksdevice=eth0 net.ifnames=0 biosdevname=0
where lab
is then used in the KickStart configuration to do different things than for other system builds:
%pre
...
case " $(cat /proc/cmdline)" in
...
* lab*)
filesystems_lab
;;
*)
filesystems_common
;;
...
Here to setup a different filesystem layout than used on other system types. Hopefully different labels are used for local customizations than are used by the kernel, given the single namespace involved.
add a comment |
Passing custom kernel arguments is one way to customize a system during a KickStart install, for example a PXE server could set:
linuxefi /c7/vmlinuz ks=http://.../ks/c7 lab ksdevice=eth0 net.ifnames=0 biosdevname=0
where lab
is then used in the KickStart configuration to do different things than for other system builds:
%pre
...
case " $(cat /proc/cmdline)" in
...
* lab*)
filesystems_lab
;;
*)
filesystems_common
;;
...
Here to setup a different filesystem layout than used on other system types. Hopefully different labels are used for local customizations than are used by the kernel, given the single namespace involved.
add a comment |
Passing custom kernel arguments is one way to customize a system during a KickStart install, for example a PXE server could set:
linuxefi /c7/vmlinuz ks=http://.../ks/c7 lab ksdevice=eth0 net.ifnames=0 biosdevname=0
where lab
is then used in the KickStart configuration to do different things than for other system builds:
%pre
...
case " $(cat /proc/cmdline)" in
...
* lab*)
filesystems_lab
;;
*)
filesystems_common
;;
...
Here to setup a different filesystem layout than used on other system types. Hopefully different labels are used for local customizations than are used by the kernel, given the single namespace involved.
Passing custom kernel arguments is one way to customize a system during a KickStart install, for example a PXE server could set:
linuxefi /c7/vmlinuz ks=http://.../ks/c7 lab ksdevice=eth0 net.ifnames=0 biosdevname=0
where lab
is then used in the KickStart configuration to do different things than for other system builds:
%pre
...
case " $(cat /proc/cmdline)" in
...
* lab*)
filesystems_lab
;;
*)
filesystems_common
;;
...
Here to setup a different filesystem layout than used on other system types. Hopefully different labels are used for local customizations than are used by the kernel, given the single namespace involved.
answered Oct 4 '18 at 15:01
thrigthrig
25.5k2 gold badges37 silver badges60 bronze badges
25.5k2 gold badges37 silver badges60 bronze badges
add a comment |
add a comment |
This famous bit of kernel code below is easy to understand --- it's just comments, panics and filenames!
execute_command contains the init= option: if you give a name there, but running it fails, you get a "Requested init xyz failed" error/panic.
Without a init= option, the kernel tries these four commands, from /sbin/init to /bin/sh. If these standard files are all missing, you get a "No working init found" panic.
And notice:
Try passing init= option to kernel
This is from Mr. Linux himself, unchanged for about 30 years. Initrd came later, in two steps...
So then, why does Linux "allow" init=/bin/bash? As you can see below, the kernel is one line away from panicking. It might be hard to see why, but rather than take care of zero processes and show a blinking cursor, the kernel decides to panic.
/*
* We try each of these until one succeeds.
*
* The Bourne shell can be used instead of init if we are
* trying to recover a really broken machine.
*/
if (execute_command) {
ret = run_init_process(execute_command);
if (!ret)
return 0;
panic("Requested init %s failed (error %d).",
execute_command, ret);
}
if (!try_to_run_init_process("/sbin/init") ||
!try_to_run_init_process("/etc/init") ||
!try_to_run_init_process("/bin/init") ||
!try_to_run_init_process("/bin/sh"))
return 0;
panic("No working init found. Try passing init= option to kernel. "
"See Linux Documentation/admin-guide/init.rst for guidance.");
}
In a initrd you need this switch_root/pivot_root/chroot trick to change root and pass PID1 to the real init: default sbin/init, something else or whatever init= wishes.
switch_root [newrootdir] [init] [args to init]
In any case, initrd makes a complex procedure even more complex...
New contributor
add a comment |
This famous bit of kernel code below is easy to understand --- it's just comments, panics and filenames!
execute_command contains the init= option: if you give a name there, but running it fails, you get a "Requested init xyz failed" error/panic.
Without a init= option, the kernel tries these four commands, from /sbin/init to /bin/sh. If these standard files are all missing, you get a "No working init found" panic.
And notice:
Try passing init= option to kernel
This is from Mr. Linux himself, unchanged for about 30 years. Initrd came later, in two steps...
So then, why does Linux "allow" init=/bin/bash? As you can see below, the kernel is one line away from panicking. It might be hard to see why, but rather than take care of zero processes and show a blinking cursor, the kernel decides to panic.
/*
* We try each of these until one succeeds.
*
* The Bourne shell can be used instead of init if we are
* trying to recover a really broken machine.
*/
if (execute_command) {
ret = run_init_process(execute_command);
if (!ret)
return 0;
panic("Requested init %s failed (error %d).",
execute_command, ret);
}
if (!try_to_run_init_process("/sbin/init") ||
!try_to_run_init_process("/etc/init") ||
!try_to_run_init_process("/bin/init") ||
!try_to_run_init_process("/bin/sh"))
return 0;
panic("No working init found. Try passing init= option to kernel. "
"See Linux Documentation/admin-guide/init.rst for guidance.");
}
In a initrd you need this switch_root/pivot_root/chroot trick to change root and pass PID1 to the real init: default sbin/init, something else or whatever init= wishes.
switch_root [newrootdir] [init] [args to init]
In any case, initrd makes a complex procedure even more complex...
New contributor
add a comment |
This famous bit of kernel code below is easy to understand --- it's just comments, panics and filenames!
execute_command contains the init= option: if you give a name there, but running it fails, you get a "Requested init xyz failed" error/panic.
Without a init= option, the kernel tries these four commands, from /sbin/init to /bin/sh. If these standard files are all missing, you get a "No working init found" panic.
And notice:
Try passing init= option to kernel
This is from Mr. Linux himself, unchanged for about 30 years. Initrd came later, in two steps...
So then, why does Linux "allow" init=/bin/bash? As you can see below, the kernel is one line away from panicking. It might be hard to see why, but rather than take care of zero processes and show a blinking cursor, the kernel decides to panic.
/*
* We try each of these until one succeeds.
*
* The Bourne shell can be used instead of init if we are
* trying to recover a really broken machine.
*/
if (execute_command) {
ret = run_init_process(execute_command);
if (!ret)
return 0;
panic("Requested init %s failed (error %d).",
execute_command, ret);
}
if (!try_to_run_init_process("/sbin/init") ||
!try_to_run_init_process("/etc/init") ||
!try_to_run_init_process("/bin/init") ||
!try_to_run_init_process("/bin/sh"))
return 0;
panic("No working init found. Try passing init= option to kernel. "
"See Linux Documentation/admin-guide/init.rst for guidance.");
}
In a initrd you need this switch_root/pivot_root/chroot trick to change root and pass PID1 to the real init: default sbin/init, something else or whatever init= wishes.
switch_root [newrootdir] [init] [args to init]
In any case, initrd makes a complex procedure even more complex...
New contributor
This famous bit of kernel code below is easy to understand --- it's just comments, panics and filenames!
execute_command contains the init= option: if you give a name there, but running it fails, you get a "Requested init xyz failed" error/panic.
Without a init= option, the kernel tries these four commands, from /sbin/init to /bin/sh. If these standard files are all missing, you get a "No working init found" panic.
And notice:
Try passing init= option to kernel
This is from Mr. Linux himself, unchanged for about 30 years. Initrd came later, in two steps...
So then, why does Linux "allow" init=/bin/bash? As you can see below, the kernel is one line away from panicking. It might be hard to see why, but rather than take care of zero processes and show a blinking cursor, the kernel decides to panic.
/*
* We try each of these until one succeeds.
*
* The Bourne shell can be used instead of init if we are
* trying to recover a really broken machine.
*/
if (execute_command) {
ret = run_init_process(execute_command);
if (!ret)
return 0;
panic("Requested init %s failed (error %d).",
execute_command, ret);
}
if (!try_to_run_init_process("/sbin/init") ||
!try_to_run_init_process("/etc/init") ||
!try_to_run_init_process("/bin/init") ||
!try_to_run_init_process("/bin/sh"))
return 0;
panic("No working init found. Try passing init= option to kernel. "
"See Linux Documentation/admin-guide/init.rst for guidance.");
}
In a initrd you need this switch_root/pivot_root/chroot trick to change root and pass PID1 to the real init: default sbin/init, something else or whatever init= wishes.
switch_root [newrootdir] [init] [args to init]
In any case, initrd makes a complex procedure even more complex...
New contributor
edited 30 mins ago
New contributor
answered 56 mins ago
sam68sam68
113 bronze badges
113 bronze badges
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473260%2fare-all-kernel-argument-really-used-by-the-kernel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown