Is reboot the same as init 6?

75,670

There is really never any compelling reason to use init 6 instead of reboot, unless:

  • For some reason you are missing the reboot executable, or
  • You are deliberately trying to avoid notifying users that the system is going down.

reboot (so long as you don't run reboot --force) is actually the "softer" way to shut down.

Consider:

init 6 will run all of the shutdown scripts in /etc/init/rc.* as it reduces system's runlevel

But the reboot command, called without the --force flag, only directly reboots the system (via the reboot system call) when one of these two situations applies:

  • The system is in runlevel 0 (single user mode), so there is no reduction of runlevel that can occur, so no shutdown scripts are automatically run.
  • The system is in runlevel 6. What init 6 does it to put the system in runlevel 6. Again, there's nothing running init 6 will do that running the reboot command won't do.

Otherwise, sudo reboot is equivalent to sudo shutdown -r now. This does all the nice things sudo init 6 does, but also:

  • notifies users that the system is going down.
  • prevents new logins (though they probably wouldn't succeed anyway).
  • is more intuitive and self-documenting than sudo init 6.

If you're on a system with only you logged in, and only local logins, there is nothing wrong with using init 6 to reboot. If that's how you prefer to reboot, then by all means, go ahead--you're not harming anything by doing so. But there's also nothing objectively preferable about doing it this way.

init's own documentation says it's not the normal way to shut down or reboot the system. Consider that when init is run by the user (like when you run sudo init 6), it actually runs telinit (see man init). telinit is what actually changes runlevels. And man telinit tells us:

Normally you would use the shutdown(8) tool to halt or reboot the system, or to bring it down to single-user mode.

Share:
75,670

Related videos on Youtube

cwd
Author by

cwd

Updated on September 18, 2022

Comments

  • cwd
    cwd almost 2 years

    Is reboot the same as init 6 for ubuntu?

    I'm running Ubuntu 12.04 on Amazon EC2. When ssh'ed into the box I can type runlevel and I get:

    N 2
    

    Looking at man reboot I see that:

    When called with --force or when in runlevel 0 or 6, this tool invokes the reboot(2) system call itself and directly reboots the system. Otherwise this simply invokes the shutdown(8) tool with the appropriate arguments.

    If I read man shutdown 8 I see:

    shutdown arranges for the system to be brought down in a safe way. All logged-in users are notified that the system is going down and, within the last five minutes of TIME, new logins are prevented.

    My basic understanding about the difference between reboot and init 6 is:

    • On other distros and perhaps older distros reboot would just unmount the disks and basically flick the power switch without running any shutdown scripts
    • init 6 will run all of the shutdown scripts in /etc/init/rc.* as it reduces system's runlevel
    • On newer versions of Ubuntu the reboot command without --force or -f will run the shutdown command which does would basically do the same thing as init 6
    • It's probably better to get in the habit of using init 6 instead of reboot as it is safer and would work better cross-distro, but the default behavior of reboot has been changed to try and prevent errors / dataloss if someone does use it.

    Is that about right? If not, what am I missing?

  • restacker
    restacker almost 11 years
    I have Alienware X51 dell pc, where i have installed Ubuntu 13.04 and kernel 3.11. When i do $ init 6 , it reboots and sometimes BIOS keep showing forever. IS it because i am using init 6 and not reboot command?
  • Eliah Kagan
    Eliah Kagan almost 11 years
    @YumYumYum I don't see why using init 6 would cause this. When you use reboot instead of init 6, does it always get past the BIOS?
  • restacker
    restacker almost 11 years
    I have updated the BIOS firmware from A00 to A02, since then my reboot or init 6 both works so it seems like BIOS issue was. Thank you.
  • user3549648
    user3549648 almost 9 years
    Running reboot halts sometimes on my Ubuntu Server 14.02 of single user and local login only. Is it safe I always do sync followed by a reboot -f?