Just a theoretical question...

But what would happen if init (in /sbin/init) would be removed?

  • Don't try ln -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 as dpkg, as it won't know it's gone by default. "Package upstart is already at the current version." You could dpkg --force-depends --force-remove-essential -r upstart first. – Joshua Jun 3 '14 at 1:30
  • 1
    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. – Ruslan Jun 3 '14 at 10:10
  • @muru OK. I'll add a tag synonym then. – Kaz Wolfe Sep 9 '14 at 19:34

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.

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") ||
        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.

  • Great answer. Didn't know that kernel searches for something more than /sbin/init. – Ruslan Jun 2 '14 at 12:16
  • And if there is no /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? – trysis Jun 2 '14 at 23:48
  • Well, then you would see the kernel panic, the part of the answer above the Correction line. But don't do that on a system you need. Seriously, don't. If you want to experiment (and it is a good exercise) create a Virtualbox VM, break it and try to fix it. BTW the answer by 200_success is not bad either. – sмurf Jun 3 '14 at 1:26

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.