Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
The many ways to power off your computer - difference?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
Zucca
Veteran
Veteran


Joined: 14 Jun 2007
Posts: 1520
Location: KUUSANKOSKI, Finland

PostPosted: Thu May 04, 2017 6:15 pm    Post subject: The many ways to power off your computer - difference? Reply with quote

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:
  • poweroff
  • halt
  • kexec
... 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?
Back to top
View user's profile Send private message
szatox
Veteran
Veteran


Joined: 27 Aug 2013
Posts: 1747

PostPosted: Thu May 04, 2017 6:59 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 7134
Location: almost Mile High in the USA

PostPosted: Thu May 04, 2017 7:08 pm    Post subject: Reply with quote

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)...
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
Zucca
Veteran
Veteran


Joined: 14 Jun 2007
Posts: 1520
Location: KUUSANKOSKI, Finland

PostPosted: Thu May 04, 2017 7:09 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
szatox
Veteran
Veteran


Joined: 27 Aug 2013
Posts: 1747

PostPosted: Thu May 04, 2017 7:25 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 7134
Location: almost Mile High in the USA

PostPosted: Thu May 04, 2017 7:28 pm    Post subject: Reply with quote

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.
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
Zucca
Veteran
Veteran


Joined: 14 Jun 2007
Posts: 1520
Location: KUUSANKOSKI, Finland

PostPosted: Sat May 06, 2017 12:24 pm    Post subject: Reply with quote

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

Code:
ERROR: '--failure' is not an option. Aborting...
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum