Linux halt vs shutdown

shutdown: What is difference between «Power Off» and «Halt»?

With your typical Linux shutdown command, what is the difference between halting the system and powering off the system?

6 Answers 6

Halting involves stopping all CPUs on the system. Powering off involves sending an ACPI command to signal the PSU to disconnect main power.

@TorKlingberg that’s because halt without parameters actually calls shutdown (see linux.die.net/man/8/halt) und showdown -h leaves the decision of if to power off or only to halt to the computer’s settings.

I’m quite sure that invoking halt from crontab doesn’t actually power off the system, but it only stops the cpu, without cutting power to the pc. In ubuntu the shutdown image remains visible on the screen. Instead, invoking halt from command line powers off it. Am I right?

will halt the system — meaning the system will shutdown and at the end stop at a screen with the last message beeing something like «System halted».

will power off the system — meaning the system will shutdown and at the end power off (only possible if the system actually supports it but most systems I know have for quite a while now)

will only halt or power off the system depending on what’s the default on that system (can sometimes be changed in BIOS)

If the machine in question does not have power management capabilities, there isn’t a difference. If it does, the difference is power off will send the signal to power the machine off, Halt will shut everything down and it will wait at a «Power Off» prompt, meaning it is safe to hit the power switch.

I’m fairly certain that a halt will just bring the OS down wheras a Power Off will bring the OS down and then send an ACPI power off command to the power supply.

Well, technically speaking, you can halt the system without powering it off. So you issue a halt, wait for it to say «You can turn the computer off now» and then you can hit the power button without worrying that something is going to unmount weirdly.

But in most modern unix’s halt, shutdown, init 0, poweroff, etc, etc all do about the same thing. Halt, for example, is mapped to «shutdown -h» when the system isn’t in runlevel 0 or 6.

The redundant commands are all nods to backward compatibility with older, proprietary *nix’s.

I remember when Windows used to work that way! How many times did I come to work to see my computer still saying «You can now safely turn off your computer» from the night before.

In the very old days, «shutdown» was a request to run through the init scripts and try to gracefully stop everything running by notifying it that the system was about to stop and it should clean up or exit nicely.

Читайте также:  Anaconda для linux mint

«Halt» was the brick wall. The system just stopped immediately without doing any orderly shutdown. It was nicer to the system than just pulling the input power. but not much.

You must log in to answer this question.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.17.43536

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Ways to Stop and Restart a Linux system or the Difference Between halt, poweroff, shutdown -H, and shutdown -P

announcement - icon

The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.

To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.

Connect your cluster and start monitoring your K8s costs right away:

1. Introduction

Through the years, machines have refined to the point of performing and synchronizing billions of sensitive but complex actions per second. Because of this, how we switch off any operating system (OS) without losing or corrupting data can be a critical consideration.

In this tutorial, we learn about ways to bring a Linux system down. First, we talk about the usual Linux shutdown process. Next, we go through the standard stop and restart commands, some of their historical background, and contemporary functions. Finally, we explore how the methods we discuss got centralized into a single binary.

We tested the code in this tutorial on Debian 11 (Bullseye) with GNU Bash 5.1.4. It should work in most POSIX-compliant environments.

2. Linux Shutdown Process

Of course, what goes up, must come down. If there is a Linux boot process, we also need steps to stop.

Basically, a shutdown means that the OS gives up control of the hardware. However, before doing that, an OS usually performs maintenance, which ensures several things:

  • ties to devices such as file handles and block special files are gracefully severed
  • all software is in a proper state
  • each hardware component is in the proper state
  • next boots are stable

In fact, abrupt stops may damage the filesystem or even the circuitry and hardware, depending on its exact nature.

For this reason, Linux usually goes through at least a minimal set of operations before giving up control of the hardware:

  1. Warn users
  2. Perform scheduled tasks
  3. Sync and unmount storage filesystems
  4. Stop system services
  5. Detach and power off devices
  6. Unload kernel modules
  7. Move through and stop targets (run levels)
  8. Stop and prevent user sessions
  9. Disable terminal services
  10. Disable security mechanisms
  11. Disable logging

While the order is more or less as listed, not all distributions and installations follow the exact same process, so a step can get delayed, omitted, or intertwined.

Читайте также:  Восстановить загрузчик линукс роса

Perhaps the most critical steps relate to the sensitive structure of storage components. Leaving at least the OS configuration in a coherent state while unmounting filesystems is paramount.

So, with our basic understanding of the shutdown process Linux follows, let’s explore some commands to initiate it.

3. halt

The halt command simply stops the OS without consideration for the hardware state after that.

To understand the idea behind halt, we turn to the Advanced Configuration and Power Interface (ACPI), which provides the OS with the means to power off attached devices:

On older or specialty machines without a convenient ACPI-controlled power button, halt usually performs the necessary stop procedures for everything the OS has control over but doesn’t power off anything. Essentially, this leaves the machine running but without third-party OS control. At that point, an operator can physically switch the power off.

Critically, there are very old versions of halt that don’t go through a graceful stop process, instead directly literally halting the OS.

Due to the advent and widespread use of ACPI, halt now usually incorporates the protocol, becoming very similar, if not equivalent to the next Linux command.

4. poweroff

Indeed, the poweroff command was initially just an ACPI call to directly power off the machine without any shutdown procedure. In other words, it was the equivalent of holding down the power button or pulling the plug.

However, due to the aforementioned repercussions of simply switching off a complex system of hardware and software, this theoretical complement to halt came to include it. Similarly, contemporary versions of halt include the poweroff ACPI call, if supported.

Consequently, the two commands are usually pretty much equivalent.

5. reboot

The function of reboot is to bring the system down and then bring it back up.

How it does that usually depends on the options. Before ACPI, reboot just did a halt and restart without power operations. Contemporary versions usually go through the whole process:

Because of the merge between halt and poweroff, as well as the fact that reboot combines them, all three commands are commonly symbolic links to the same binary.

6. shutdown

Since, in the past, halt, poweroff, and reboot were distinct options for stopping, shutdown was meant to further combine maintenance, termination, and restarts into one:

  • perform the proper tasks to gracefully stop the OS
  • power off the system
  • optionally power the system back on

Whether this is done by calling them in order or via a custom binary depends on the version and implementation.

Since shutdown includes all previous commands, we can often use it to call them via flags:

After exploring the historic commands for stopping and restarting a system, let’s bring them all together.

7. OS Stop Control

At this point, the names of stop commands can just be semantically different, while the underlying code paths remain basically the same. Consequently, we can have unexpected combinations:

$ halt --poweroff $ poweroff --reboot $ reboot --halt

Critically, the specific actions of each command depend on many factors:

Some environments merge halt and reboot in the same binary, while shutdown and poweroff are a different binary. Others combine everything into one.

In fact, in many recent versions of Linux, halt, poweroff, reboot, and shutdown are all the systemctl command with their own set of subcommands for each function.

Читайте также:  Angry ip scanner kali linux

In addition, there is usually a -f, -ff, or –force switch, which, like the original halt, doesn’t contact the system manager further before performing any stop operations. This means we jump over the shutdown functionality and any graceful stops, risking system damage but ensuring the action completes as quickly as possible.

Due to all of the above, referring to the documentation of a UNIX or Linux distribution can be vital to how the options we have for system state control are implemented.

8. Summary

In this article, we looked at the usual commands for stopping and restarting a Linux system, some of their history, and their current status quo.

In conclusion, while there were historical differences between halt, poweroff, and shutdown based on technicalities, their contemporary codebase is much more unified, if not equivalent, depending on the system.

Источник

Understanding Shutdown, Poweroff, Halt and Reboot Commands in Linux

In this article, we will explain to you the difference between shutdown, poweroff, halt and reboot Linux commands. We will make clear what they actually do when you execute them with available options.

If you are hoping to dive into Linux server administration, then these are some of the important Linux commands you need to fully understand for effective and reliable server administration.

Normally, when you want to turn off or reboot your machine, you’ll run one of the commands below:

Shutdown Command

shutdown schedules a time for the system to be powered down. It may be used to halt, power-off or reboot the machine.

You may specify a time string (which is usually “now” or “hh:mm” for hour/minutes) as the first argument. Additionally, you may set a wall message to be sent to all logged-in users before the system goes down.

Important: If the time argument is used, 5 minutes before the system goes down the /run/nologin file is created to ensure that further logins will not be allowed.

Examples of shutdown commands:

# shutdown # shutdown now # shutdown 13:20 # shutdown -p now #poweroff the machine # shutdown -H now #halt the machine # shutdown -r09:35 #reboot the machine at 09:35am

To cancel a pending shutdown, simply type the command below:

Halt Command

halt instructs the hardware to stop all CPU functions, but leaves it powered on. You can use it to get the system to a state where you can perform low level maintenance.

Note that in some cases it completely shuts down the system. Below are examples of halt commands:

# halt #halt the machine # halt -p #poweroff the machine # halt --reboot #reboot the machine

Power off Command

poweroff sends an ACPI signal which instructs the system to power down.

The following are examples of poweroff commands:

# poweroff #poweroff the machine # poweroff --halt #halt the machine # poweroff --reboot #reboot the machine

Reboot Command

reboot instructs the system to restart.

# reboot #reboot the machine # reboot --halt #halt the machine # reboot -p #poweroff the machine

That’s all! As mentioned earlier on, understanding these commands will enable to effectively and reliably manage Linux server in a multi-user environment. Do you have any additional ideas? Share them with us via the comments section below.

Источник

Оцените статью
Adblock
detector