# The many ways to power off your computer - difference?

## Zucca

So... I've always wondered what's the difference between all the ways of shutting down the system.

I've never actually paid much anttention to it - there's never been a need. Now there is - I'm trying to make sense to systemd (if it's even possible).

At least systemd knows these ways:poweroffhaltkexec... and there's also shutdown. I think shutdown is a common name (in systemd world) for all those.

I bet these are some remainders from the years when UNIX was more common than Linux in servers.

So. What's the difference between those? And if someone knows how those differ in systemd?

----------

## szatox

Poweroff, halt, shutdown -h, init 0 

All those usually inform your init that the fun is over. 

Init will perform regular shutdown sequence.

It's getting more funny when you go to additional options.

Poweroff is supposed to actually poweroff the hardware after system halt. Halt can stop the system and then leave hardware powered on, just like old good days when windows 95 would print orange "you can safely power off your computer now".

Kexec doesn't really fit your set. AFAIR it's a jump that allows you replace running kernel, so it's closer to reboot. It could even be possible to replace running kernel without going through init at all. No idea if it is actually implemented this way, as replacing executable code and preserving it's internal state is rather tricky.

----------

## eccerr0r

Well, when shutting down the system, there are many things involved.

- terminating processes gracefully to allow...

- unmounting disks 

- then the system may turn power off, spinloop, reboot, or kexec...

Most of the individual commands *should* tell /sbin/init(8) that shutdown-reboot is happening via telling it to change runlevel to the shutdown runlevel.

On an sysvinit/openrc system there are individual commands to do these things like /sbin/halt /sbin/poweroff (usually link to halt).   /sbin/shutdown is a command that does a "delayed" shutdown (who ever uses this on a desktop machine?  This is for shell servers so it can warn users of an impending shutdown...) but also ultimately calls init to do the actual shutdown cleanup by changing runlevels.  Init will run the halt command to halt the system after it deems cleanup is done.  Halt will do the ioctl with a specific bit sequence to tell the kernel to die. 

Systemd must basically work the same exact way to keep things clean - except systemd ate all the commands and wants a dbus command to initiate these things... You can still use /sbin/halt to do an unclean shutdown (unless it got hacked to call systemd)...

----------

## Zucca

 *szatox wrote:*   

> Poweroff is supposed to actually poweroff the hardware after system halt. Halt can stop the system and then leave hardware powered on, just like old good days when windows 95 would print orange "you can safely power off your computer now".

 That seems logical. I wonder if some hardware then would allow remote power on the system only if halted... There must be some use for letting the hardware being powered on while the system has been shut down.

Of course nowdays most of the systems are in standby and the motherboard just waits for a signal to power on the rest of the components...

EDIT:

 *eccerr0r wrote:*   

> On an sysvinit/openrc system there are individual commands to do these things like /sbin/halt /sbin/poweroff (usually link to halt).   /sbin/shutdown is a command that does a "delayed" shutdown (who ever uses this on a desktop machine?  This is for shell servers so it can warn users of an impending shutdown...) but also ultimately calls init to do the actual shutdown cleanup by changing runlevels.  Init will run the halt command to halt the system after it deems cleanup is done.  Halt will do the ioctl with a specific bit sequence to tell the kernel to die. 
> 
> Systemd must basically work the same exact way to keep things clean - except systemd ate all the commands and wants a dbus command to initiate these things... You can still use /sbin/halt to do an unclean shutdown (unless it got hacked to call systemd)...

 

Ah. I remember wondering why I had to command such a complex command as shutdown -h now just to power off my first ever linux laptop. :P Later I created an alias for it.

All in all... I don't think I'll ever use kexec.

poweroff is the way to go. And that's what I've been using for year now.

This all just came into my mind when I wanted to create a systemd service file.

----------

## szatox

No idea would be the use of it. I've been thinking about it as a relic of the past that somehow survived  the birth of ACPI.

I would not expect the hardware to boot up again from halt. System is not running anymore at that point so it will not serve the interrupts, but the hardware does not necessarily know it.

You can see the difference between halt and poweroff when you call them with force, so they bypass init. Handy thing when you go all minimal with a shell script instead of fully blown init executable.

----------

## eccerr0r

For systemd, "systemctl poweroff" or whatever alias or script that runs this is what you want to gracefully shutdown right away.

For init/openrc, "poweroff" in recent versions of sysvinit will actually eventually change the runlevel of init, but old versions may shutdown the system uncleanly as it meant to power down the machine right away.  You can emulate the old behavior by giving it the -f flag (but this is very dangerous!).

---

Oh and halting without poweroff - this is a relic of old workstations that were the pioneers of Un*x which had command line ROM monitors.  Halt would jump back to the ROM monitor.  PC's don't have this and thus is very useless.

----------

## Zucca

Thanks of all the replies. This was a nice time travel back in *NIX history. :)

----------

