62

I've a home server I'm playing around with :) I want to learn server administration...

I have a hard time understanding the difference between shutdown -h now and poweroff -h now My logic tells me it's the same thing...

But with the shutdown, Linux halts, and power stays on - I can see all lights up and cooler rotating. Strange, the only way to turn off my box completely is to use poweroff -h

Any clarification will be appreciated!

Milan
  • 196

2 Answers2

54

The answer is in the poweroff(8) man page:

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.

A bit of explanation:

  • The reboot() system call is the kernel function used to reboot, halt or poweroff the machine. It is called reboot for historical reasons, but performs all three functions, depending on parameters that are passed to it.

  • The difference between halt and poweroff is that in halt mode the control is returned to a "ROM monitor" (think BIOS), whereas poweroff simply powers the system board off. (I have never seen this distinction in effect on PC architectures; on Sun machines it's different, though.)

  • So, when the poweroff program is invoked when the Linux system is in runlevel 0 or 6, it will immediately power off the system via the reboot(RB_POWEROFF) system call.

  • In any other case, poweroff will just behave as an alias for shutdown now.

muru
  • 207,228
0

To the original question "shutdown" vs. "poweroff": As the names imply, "shutdown" ends in something like "cli(); while(1);" while "poweroff" communicates somehow with the power supply before ending execution in a similar or same loop like "shutdown". (Only for the case that there is a problem with the power supply.)

In case of Raspberry Pi, by default, it is the same. However, there is a standard kernel overlay available, which can be loaded by modifying /boot/config.txt:

dtoverlay = gpio-poweroff

which changes (by default) GPIO26 (Pin 37) to an Output driving High. As this pin is not used by default, and unused pins are inputs without pullup/pulldown, a simple circuitry can cut power supply at High level. Note (for the designer of circuitry): This pin will revert to Low after power cut, of course! So use a flipflop.

As the overlay name "gpio-poweroff" should imply, it is called (somehow by systemd) on "poweroff", not on "shutdown" or "halt".