Previous Section  < Day Day Up >  Next Section

Recipe 7.10. Shutting Down or Rebooting Linux

7.10.1 Problem

Look at all these shutdown and reboot commands: shutdown, halt, init 0, poweroff, Ctrl-Alt-Delete, etc. What's the right one to use?

7.10.2 Solution

It doesn't matter all that much; use what suits you. Only root can use these commands to shut down:

# shutdown -h now

or:

# poweroff

or:

# halt

To shut down in six minutes:

# shutdown -h +6

shutdown sends a notification to all logged-in users. To make your own message, use:

# shutdown -h +6 "Time to stop working and start partying."

Console users will see:

Broadcast message from root (pts/6) Wed Aug 14 13:51:24 2003

Time to stop working and start partying.

The system is going DOWN for system halt in 6 minutes!

To cancel a shutdown as root, use:

# shutdown -c

To reboot, you can use:

# shutdown -r now

or:

# reboot

or press Ctrl-Alt-Delete. Any user can do this, unless you disable it in /etc/inittab. (See Recipe 7.11 to learn to disable this, or how to grant permission to specific users.)

7.10.3 Discussion

The most important thing to remember is to always have a controlled shutdown. All computers, including Linux machines, have to do a lot of tidying up and putting away before they can be turned off. Services must be turned off, filesystems unmounted, and buffers written to disk.

shutdown, poweroff, and halt all must be executed by the root user. This seems rather silly, as all window managers and desktop environments have their own shutdown menus that any user can use, and anyone physically sitting at the machine can hit the power switch. However, there it is, and we must deal with it. One option is to grant limited privileges for shutdown commands with sudo. Another is to create a "shutdown" group.

7.10.4 See Also

  • shutdown(8), poweroff(8)

  • Recipe 8.20

  • Recipe 8.21

  • Chapter 25 of Unix Power Tools, by Shelley Powers, Jerry Peek, Tim O'Reilly, and Mike Loukides (O'Reilly)

  • Chapter 8 of Running Linux

    Previous Section  < Day Day Up >  Next Section