Translation(s): English - Italiano


Turning your Debian System off and back on

Something as everyday as turning your computer off and on seems like it should be an easy task, but we've advanced beyond flipping the power switch or being present to turn our system on, and sometimes the advanced features can be tricky to set up.

Hardware Power Control

You get your computer in a state where it's ready to lose power. The system would often give a reassuring statement like "Power off" or "Halted" or "It is now safe to turn off your computer." Then you toggled the power switch to off.

Simple. :-)

Software Power Control

Then the computer industry decided to invent some new technology.

Modern on/off options

The old switch on computers was long ago replaced with the push button. When you push the button, the power state changes: from off to on, or from off to suspend, from suspend to on. Hold down the button for a few seconds, and you get a hard off. Power backup devices (UPS) also need to influence the computer's on/off state.

No longer as simple.

APM - Advanced Power Management

APM was the first attempt to help computers manage the more complex world of power management.

APM allows software to interact with the power states of the main board. With it, a program on your computer can 'push the power button.'

For people using the Linux kernel it seemed the focus was on using APM only if you had a laptop on which you wanted to conserve battery power. This was especially true if you wondered if you should run apmd. See the ampd man page or http://www.worldvisions.ca/~apenwarr/apmd/

For the power off from software, the halt program had a -p option to tell the system to poweroff. The poweroff command is usually a symlink to halt that implicity acts like you called halt with the -p option. You do not need apmd to use poweroff. You may need apm support in the kernel (apm=on||apm=off).

ACPI - Advanced Configuration and Power Interface

APM was well and good, but it didn't give us all the options we wanted, like suspend to ram, suspend to disk.

Off

Shutdown in a sentence

You give a command that tells init to switch to run level 0 for halt/poweroff or run level 6 for reboot.

Easy huh?

Shutdown explained

When init enters a run level, it kills some processes and runs some (other?) processes (man init). rc6.d happens to have an alias to /etc/init.d/reboot and rc0.d has an alias to /etc/init.d/halt. The reboot script simply calls /sbin/reboot and the halt script checks to see if halt means halt or if halt means poweroff, then calls /sbin/halt with the appropriate arguments. It also has a hook for apcupsd's ups-monitor script.

While you could use the telinit command to change to these run levels, you should use shutdown instead, since it's designed to "bring the system down gracefully", including telling logged in users that the system is shutting down and blocking new logins.

Many people use poweroff or reboot as aliases to the shutdown command since they can type less. Technically they are aliases to the halt command which sees that you're not at run level 0 or 6 and calls shutdown anyway.

To shut down now and halt but not poweroff:

 shutdown -hH now

To shut down and poweroff now:

 shutdown -hP now

To reboot now:

 shutdown -r now

To go to single user mode now:

 shutdown now

If you don't pass the H or P flag to shutdown -h (like typing poweroff doesn't), Debian looks at the HALT setting of /etc/default/halt to determine if it should power off or not. This allows you more flexibility if your BIOS doesn't give you the right 'do X after power is restored' option.

ACPI configuration in Debian causes many scripts to be run on a suspend or shutdown event. The directory /etc/acpi/events contains scripts that respond to events. The ACPI system works with the kernel to trigger these events. See Suspend for more details.

On

ACPI configuration in Debian causes many scripts to be run on a restore event. See Suspend for more details.

The Final Word

Of course, the question remains, what the heck are you doing turning off a Linux box anyway?!? :-) Sorry. Just a little joke.