5

This is probably a dumb question with an easy answer, but I can't seem to shed any light on it after hours of Google-ing. From what I have learned the halt command on UNIX (e.g BSD) & Unix-like Systems (e.g Linux) will halt the CPU after calling sync. I know that on most modern Linux Distros halt is just another way to call shutdown, but I have installed FreeBSD and Arch Linux on my Laptop, and both of those systems seem to do what halt is supposed to do (halt the CPU, but don't ACPI shutdown). My question is that after calling

# sync;sync;sync
# halt

is it safe to "pull the plug" or cut the power (from the power socket at the wall)? After calling halt is the system truly in an "off" state?

Bonus: After calling halt on eiter Arch Linux or FreeBSD, my computer seems "halted", like it is unresponsive, and nothing works but I can still hear the fan running. The fan stops after I take the power out. So it's not a problem, I'm just wondering if maybe halt doesn't stop all the hardware, and only stops the CPU?

  • Once the system is halted, there is no further danger to system corruption by removing power. – Nevin Williams Oct 25 '15 at 9:54
  • @NevinWilliams Does this mean that <code>halt</code> will unmount all mounted FileSystems? – Ankush Oct 25 '15 at 23:15
  • No. What does 'man halt' say on the subject? – Nevin Williams Oct 26 '15 at 0:24
  • Halt can only halt hardware that has a halt function. Fans do not have a halt function. – qasdfdsaq Oct 26 '15 at 16:17
5

As long as sync has completed, it's probably always OK to unplug!

In the bad old days you could damage your disk platter if you pulled the plug when the head wasn't parked, but these days there's not really any hardware damage you can do (probably, maybe ... let's be safe and not do it).

That only leaves software damage. Clearly pulling the plug in the middle of a big disk job is a bad plan, but if the machine is idle, you've saved your open documents, and you've done a sync to flush the write buffers, then a sudden power-off event isn't likely to hurt much. In any case, after halt the software isn't going to do anything more, so any damage that was going to get done has already been done.

Of course, it's all a moot point, because halt is just a synonym for shutdown -H now, which will do a proper, graceful shutdown of all running processes and services, sync all data, and unmount all file-systems.

As for the other hardware devices, they're still on, idling away. The screen will continue to show whatever was on screen before the CPU halted. The fans will continue to do whatever they do without software control. The disk will do whatever its configurable power profile says to do.

In fact, depending on your machine, the CPU may not even be off -- it might just be busy spinning round an infinite loop, waiting for someone to hit reset.

  • Upvote. This is certainly technically true. imho, the only time I would "just pull the plug" would be if it were non-responsive - and in that circumstance am left to simply pray that sync was finished "enough" - fortunately, these days, the odds are highly in favor of Linux keeping the file system intact. And of course this is why we also keep backups. – SDsolar Jun 19 '18 at 19:15
4

I'd recommend against it. While some/most modern OSes alias halt to shutdown -h now, It is poor practice to rely on that.

In its true form, halt is a very abrupt cessation of all CPU activity, and is really only designed to be called by rc.d in the init 0 runlevel after the system has run a proper shutdown sequence... While you have sync'ed the disks, which takes care of most of the data corruption risk, there is still a lot more cleanup (FS unmounts, lockfiles, etc) involved in a proper shutdown.

You also run the risk that some process starts doing something critical right between the sync and halt calls -- no matter how quickly you chain them (unless you can somehow guarantee the behavior of the CPU scheduler... which you can't).

Best practice is to call shutdown -h now, which will gracefully stop all processes and daemons, dismount filesystems, and eventually bring the system to the same halted state. Then you can safely remove power. This method also has the benefit of invoking an ACPI power off command (on modern ACPI supporting systems) which causes the PSU to cut power (thereby stopping the fans and everything else) unlike (true) halt, which does not issue any ACPI commands and will idle the CPU with everything still powered on.

0

Yes, that is the purpose of the halt command. It causes all activity to cease.

These commands shut down the system immmediately in preparation for power-off:

  • sudo shutdown -h now
  • sudo poweroff
  • sudo halt
  • sudo init 0

NOTICE THE HARD DRIVE INDICATOR LIGHT

If there is activity then the system is still running. It will stop soon after these commands.

Once it stops flickering then you know it is finished shutting down.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.