Just a theoretical question...
But what would happen if init
(in /sbin/init
) would be removed?
The boot loader will load the kernel, the kernel would attempt to run init, not find it and panic.
The way out of it is to reboot, edit the boot parameters, add init=/bin/bash
and boot that way. The kernel will use bash as init. This will give you a chance to run commands and fix the system.
Correction
Apparently the kernel (file init/main.c) does:
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/init.txt for guidance.");
So it would find /bin/sh (which is a link to dash) and that will give you a shell and a chance to fix it without using the init=/bin/bash
boot parameter.
/sbin/init
.
/bin/sh
file? Or /bin/bash
or /bin/dash
etc? Not sure how you could delete all of these at the same time, but what would happen, theoretically?
Nothing happens, until you try to reboot. As long as the system is running, and you don't try to switch runlevels by running /sbin/init
n, you wouldn't even realize it was gone.
Actually, deletion of /sbin/init
is undoable if you realize the mistake early and stay calm. System administrators have recovered from much nastier "lobotomies" while keeping the operating system running.
One way to recover from the deletion of /sbin/init
is to reinstall the upstart
package using APT.
The macho way to recover is to use only the resources on the machine itself. One factor in your favour is that /sbin/init
is always running. Therefore, when you run rm /sbin/init
, the file is merely unlinked from the filesystem. The inode and file contents remain on disk and in memory until PID 1 exits. You merely need to re-create /sbin/init
from the appropriate inode.
The easiest way to accomplish that is:
# cp /proc/1/exe /sbin/init
# chmod 755 /sbin/init
-L
-- it won't work.cp /proc/fd/1/exe /sbin/init && chmod 755 /sbin/init
works though. Using APT to re-install upstart is not as obvious asdpkg
, as it won't know it's gone by default. "Package upstart is already at the current version." You coulddpkg --force-depends --force-remove-essential -r upstart
first.apt-get install --reinstall upstart
. Also, I don't have/proc/fd
directory. And I just checked,ln -L /proc/1/exe /tmp/init
works with/sbin/init
renamed to/sbin/init.bak
, i.e. I can read without a problem/tmp/init
after this.