Turning your Debian System off and back on

Something as every day 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 loose power, and you hit the power button. The system would often give a reassuring statemen like "Power off" or "Halted" or "It is now safe to turn of your computer." If the power went out and then came back later, the computer would boot back up because the switch was still on. If you didn't want that to happen, you toggled the switch to off even though the power was out and the computer was already off.

Simple.

Software Power Control

Then the computer industry decides to invent some new technology and spit out a couple new buzz words, ATX and APM.

ATX form factor

Now our computers (well, the BIOS and main board bits) start trying to decide how to manage the power states of our systems including powering off. The two state power switch is replaced overnight with a contact button that tells the bios "I was just pressed" and it's up to the bios to decide what that means. Generally it means "turn on" if it was off and "turn off" if it was on, but what if you accidently bumped it, and how do you say "go to sleep" (new option with APM.) Also, what should it do if the power goes out and comes back on later? The switch we flipped can no longer be 'flipped' with no power.

No longer as simple.

APM - Advanced Power Management

So the BIOS configuration allows you to specify what parts of APM you want it to support and what to do in case there is a power outage. Some of the options include:

Another perk of the APM is that it allows other 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 that you wanted to conserve battery power on. 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 good and well, but it didn't give us all the options we wanted, like suspend to ram, suspend to disk and that BIOS was in charge, not our software. ACPI turned this around putting the BIOS back in it's place (low level communications, not giving orders.) Unfortunatly now you have three ways for turning off your computer and your main board (and chipset), cpu, bios and software all need to be on the same sheet of music to work it out right.

Since ACPI is suppose to replace APM, it seems that it should be out with the old and in with the new. Especially on SMP systems where APM may have caused race conditions. The answer seems to be 'maybe' or 'try this, or this or this or this and tell me what works'. Hopefully we can put together a good step by step APM or APIC OffAndOnAgain checklist so that you can get your computer to turn off like you'd like it to.

Off

Shutdown in a sentance

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 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 and 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 is designed to bring "the system down in a secure way" 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 (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.

On

Pushing the power button to turn the computer back on is simple enough, even with APM or ACPI. For more advanced options if your BIOS and hardware support it you could try WakeOnLan or other hardware wake events like your keyboard or mouse.

If you don't poweroff, but just halt your system (or if your system won't poweroff due to APM or ACPI problems) is there a way to remotely restart the system?