How to stop a reboot after init 6 is given by mistake?

Hi, I recently had an issue and by mistake a script of mine has initiated init 6 command,

Is there a way to stop the reboot manually after init 6 is given,

Your response is highly appreciated.
Thanks in advance !!

I am not aware of any means to stop a reboot. Also, you would only have a few seconds or even less before your shell is killed by the shutdown process.

I wonder if you could do "pf -ef | grep 'init 6'" then get the pid and do "kill -9 <pid>". The real question is can you do the above before you session is killed. When typing something that could cause harm, you can always pause for a moment before hitting enter and make sure that what you are doing is really what you wanted to do.

This would not work, because 'init 6' does nothing but send a signal of some sort to the real init process, the one which started when the computer booted. You'd have a fraction of a millisecond to catch 'init 6' before it sends that signal and quits.

Killing the real init process would make things worse.

That is good to know in case I do type init 6 as root on a unix system. The other problem with someone accidentally doing init 6, is that even if you can stop the shutdown from happening, the OS will start killing processes. Processes that would need to be restarted. Either way doing init 6 or shutdown on a running production server by accident is going to cause issues.

Fortunately, modern unix versions protect the init process.

Solaris 10:

# kill -9 1
kill: 1: permission denied

RHEL 6 does not even print an error message, it just discards the nonsense.

Long time ago, it was possible to kill init, which usually caused a

kernel panic: init died.
1 Like

If you really want to kill init, I'd bet this would work on Solaris:

dd if=/dev/zero of=/proc/1/as

Anyone care to try? :smiley:

Not sure offhand what the equivalent Linux /proc/1 entry would be.

You lost your bet, achenle :smiley:

# dd if=/dev/zero of=/proc/1/as
dd: /proc/1/as: open: Permission denied
# uname -a
SunOS sol10 5.10 Generic_141445-09 i86pc i386 i86pc

I agree completely with Corona688 (post#4). You can't mess with the init process!!!!

The init process is part of the kernel (PID=1) and all you are doing with 'init 6' is sending a signal to that process to change run level.

Direct use of the init command gets a faster response than the shutdown command and is often used by sysadmins. However, you need root privs to get the command acted on by the system and, if you are logged in as root (or su'd to root), you need to be thinking about what you're doing VERY CAREFULLY. Root bypasses all normal security on most Unix flavors, you are god and anything you say goes, no questions asked. There are all sorts of commands that root can accidentally type that will completely destroy the system outright.

If I login on my own account then I know that if I try something stupid that the system will tell me. If I login as root then I really pay attention to what I'm doing (and logout from root as soon as possible).

1 Like

Taking the question literally, this is actually very easy to do. Wait until the system has shut down and then power it off. That will stop the reboot. :smiley:

I'm not just being a wiseguy. I have done exactly this several times in the past several years. I meant to type "init 5" and accidentally typed "init 6". These were servers on my desk and I was re-installing (an upgraded version of) the OS. So I had easy access to the power button.