What would happen if init was deleted?

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.


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

Tags:

Kernel

Init