- Linux halt, poweroff and reboot commands
- Description
- Syntax
- Technical description
- Options
- Environment
- Files
- Examples
- Related commands
- 5 Linux Commands to Shutdown and Reboot the System
- Linux shutdown / reboot command
- 1. «shutdown» command
- 2. «reboot» command
- 3. «halt» command
- 4. «poweroff» command
- 5. REISUB — R E I S U B key strokes
- 10 thoughts on “ 5 Linux Commands to Shutdown and Reboot the System ”
- Перезагрузка вместо выключения
- How to Reboot and Shutdown Linux Servers?
- GUI Method
- systemctl Command
- shutdown Command
- Reboot Command
- Halt Command
- Poweroff Command
- init Command
- Power Button
- Alt + SysRq Combination
- Summary
Linux halt, poweroff and reboot commands
On Unix-like operating systems, the halt, poweroff, and reboot commands stop, power down, or reboot the system, respectively.
This page covers the GNU/Linux versions of halt, poweroff, and reboot.
Description
halt, poweroff, and reboot are commands you can run as root to stop the system hardware.
- halt instructs the hardware to stop all CPU functions.
- poweroff sends an ACPI signal which instructs the system to power down.
- reboot instructs the system to reboot.
These commands require superuser privileges. If you are not logged in as root, you need to prefix the command with sudo or the signal isn’t sent.
Syntax
Technical description
These programs allow a system administrator to reboot, halt or poweroff the system.
When called with —force or when in runlevel 0 or 6, this tool invokes the reboot system call itself (with REBOOTCOMMAND argument passed) and directly reboots the system. Otherwise, this invokes the shutdown tool with the appropriate arguments without passing REBOOTCOMMAND argument.
Before invoking reboot, a shutdown time record is first written to /var/log/wtmp
Options
-f, —force | Does not invoke shutdown and instead performs the actual action you would expect from the name. |
-p, —poweroff | Instructs the halt command to instead behave as poweroff. |
-w, —wtmp-only | Does not call shutdown or the reboot system call and instead only writes the shutdown record to /var/log/wtmp. |
—verbose | Outputs slightly more verbose messages when rebooting, which can be useful for debugging problems with shutdown. |
Environment
RUNLEVEL | reboot will read the current runlevel from this environment variable if set in preference to reading from /var/run/utmp. |
Files
/var/run/utmp | File where the current runlevel will be read from; this file also be updated with the runlevel record being replaced by a shutdown time record. |
/var/log/wtmp | A new runlevel record for the shutdown time will be appended to this file. |
Examples
If you are logged in as root, issuing the halt command will cease all CPU function on the system. On most systems, this will drop you into single-user mode and then power off the machine.
If you’re not logged in as root, prefix the halt command with sudo to run the command as the superuser.
If you are logged in as root, issuing the poweroff command sends an ACPI hardware signal which will instruct the system to commence with a complete and immediate shutdown. This is roughly equivalent to pressing the power button on a typical desktop computer.
Execute the poweroff command as root.
If you are logged in as root, issuing the reboot command will immediately initiate a reboot sequence. The system shuts down and then commence a warm boot.
Execute the reboot command as root.
Related commands
shutdown — Schedule a time for the system to be powered down.
Источник
5 Linux Commands to Shutdown and Reboot the System
Linux shutdown / reboot command
On Linux, like all tasks, the shutdown and restart operations can also be done from the command line.
The commands are shutdown, halt, poweroff, reboot and REISUB keystrokes.
In this post I am going to show you how to shutdown or restart a linux system using these commands.
The commands are useful specially when you have to reboot a remote linux server, where only shell access is available and no gui.
Servers often need a restart when upgrades are installed or need to shutdown for other maintainance tasks.
The commands are available on any linux system like centos, ubuntu, debian, fedora or suse and do not require the installation of any extra packages.
1. «shutdown» command
The first command is the shutdown command and it can be used to shutdown a system or restart it. It is commonly used to shutdown or reboot both local and remote machines.
To shutdown a machine call the shutdown command like this
The h option is for halt which means to stop. The second parameter is the time parameter. «now» means that shutdown the system right away.
The time parameter can be specified in minutes or hours also. For example
The above command shall flash the message to all other logged in users and give them 5 minutes before the system goes for shutdown.
The shutdown command can be used to restart a system with the r option instead of the h option. Usage is same as before. Just replace the h option with r option.
All other logged in users will see a broadcast message in their terminal like this
At this point a shutdown can be cancelled by calling shutdown with «c» option.
2. «reboot» command
Next command is the reboot command. It can be used to shutdown or reboot linux.
The following command will shutdown linux.
The «p» options stands for poweroff.
To reboot linux just call the reboot command directly without any options.
This will perform a graceful shutdown and restart of the machine. This is what happens when you click restart from your menu.
Reboot linux forcibly
The following command will forcefully reboot the machine. This is similar to pressing the power button of the CPU. No shutdown takes place. The system will reset instantly.
The man page explains it as follows
3. «halt» command
The next command is the halt command. This can shutdown a system
The halt command also has a force option, but you do not want to use it. It is supposed to shutdown the system instantly. But its behaviour may not be consistent. Desktops might hang on running this command.
4. «poweroff» command
There is another command exactly same as the halt command. It does the same things and takes the same options.
5. REISUB — R E I S U B key strokes
The above shown commands can be used when you are in control of your system. What if the system has hanged and is not responding at all. And you do not want to press the power button on the CPU which might lead to data corruption. To save from such a situation, comes the magic sysRQ keys.
A special combination of key presses that will allow you to reboot your linux system, no matter how much it is hanged. Check the wikipedia article. for more information.
Warning : Pressing the following keys would instantly reboot your system. Its similar to pressing the power button of your CPU or executing the reboot -f command.
Now in place of the B key we have to use R E I S U letters first. Each key does a task as mentioned below
1. Hold down the Alt and SysRq (Print Screen) keys.
2. While holding those down, type the following keys in order, several seconds apart: R E I S U B
3. Computer should reboot.
Make sure to have some time gap between each of keys R E I S U B.
The sysrq feature can be controlled by changing the value of /proc/sys/kernel/sysrq. To check if sysrq is enabled on the system or not, echo the value. It should be non zero.
A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected] .
10 thoughts on “ 5 Linux Commands to Shutdown and Reboot the System ”
It worked on SUSE SLES 11
Now systemctl utility replaces a number of power management commands and even the shutdown command will call systemctl utility to perform the shutdown tasks.
The command reboot does work and immediately rebooted my Bluestar Linux system 4.20.7 (based on Arch Linux).
I am so glad that you could reboot your linux system!
If I’m not mistaken, reboot by itself actually does a shutdown: https://linux.die.net/man/8/reboot . You have to do reboot -f to actually get it to reboot.
Arrrgh so sick of finding the incorrect example of shutdown everywhere. The reboot syntax shown, on Ubuntu and probably in every flavor today, will Immediately reboot your server with no delay or warning. the +5 option is either wrong or in the wrong spot.
Important note – this only applies (AFAIKT) to x86 systems. On arm – no-worky.
what? 20 – 30 mins? O.o Shouldn’t it be 20 – 30 seconds?
I rebooted my linux machine using command reboot -f, it went down. How long does it takes normally to start again?
Its depends upon hardware and file system mounted on Linux box , If it is high end hardware and have been mounted more file system then it will 20-30 mins to come online
Источник
Перезагрузка вместо выключения
Столкнулся с неприятной ситуацией: компьютер под Linux Mint 20 вместо выключения перезагружается. То есть он как бы выключается, но, спустя мгновение, вновь включается. Выключить можно либо зажав кнопку на системном блоке, либо нажав её один раз, находясь в Bios. Причём началось это внезапно, и я не могу установить какую-то закономерность. Комп — новый, месяца 2-3 ему, проблема появилась месяц назад примерно.
Казалось бы, при чём тут Linux? Однако у меня есть старый жесткий диск с Виндой — и при выключении в Винде такой проблемы нет. Что я предпринимал (безуспешно), чтобы решить проблему?
- Выключил Wake-on-LAN в Bios (на самом деле, он и был выключен)
- Сбрасывал Bios
- Вытаскивал LAN-кабель
- Перепробовал различные варианты выключения через терминал ( shutdown -h now в том числе)
- Обновил Bios
- На пустой новый SSD установил Linux Mint (подумал, может кривой апдейт прилетел) — аналогичная ситуация наблюдается и на чистой системе
- Отключал все жёсткие диски и ssd, оставлял только m2 с системой
- Отключал все подключённые к USB устройства, кроме мыши, ставил в другие разъёмы и т.п. — бесполезно.
- В /etc/default/grub прописал GRUB_CMDLINE_LINUX_DEFAULT=»quiet acpi=force reboot=acpi splash»
Ничего не помогает. Подскажите, пожалуйста, что ещё можно проверить? Закралась мысль, что что-то с блоком питания, но тогда странно, что Винда нормально выключается. Да и блок питания новый.
OS: Linux Mint 20
Комп: AMD Ryzen 9 3900X/GIGABYTE X570 AORUS MASTER/2*16ГБ/RTX2060S-8ГБ/512ГБ/4ТБ
Источник
How to Reboot and Shutdown Linux Servers?
Geekflare is supported by our audience. We may earn affiliate commissions from buying links on this site.
As a Sysadmin, one of the frequent activities is to reboot or power off servers.
This could be due to regular maintenance activity like OS patching or due to some hardware failure that requires a system to be powered down for maintenance.
A Linux system offers several different ways to reboot or shut down the server. A normal system should respond to any command while a degraded server may need to be rebooted forcefully. Do note that most of these commands will require a certain level of privilege either as superuser or with sudo to be executed successfully since rebooting a system is an administrative task and for a multi-user system or server running critical processes, reboot or shutdown is a disruptive activity.
This article covers few such methods which can help you out with Linux reboot/shutdown activity.
GUI Method
If you’re using a GUI Desktop Environment for Linux like Gnome, KDE, Mate, XFCE, etc., you’ll find a power button in the system/application menu which offers actions such as logout, reboot, hibernate or power off. Available options may differ slightly depending upon which distribution, desktop environment, and version of OS is in use. But you’ll definitely find power-related settings in available menus to change the power state of your system.
For example, on my Ubuntu Mate desktop, I can find the Shut Down option in the power menu at the top right of my screen.
Once you select “Shut Down…” option, you’ll be presented with a dialog with multiple options like Suspend, Restart, Cancel and Shut Down. You can either proceed with Restart or Shut Down by clicking on the right button or cancel and get back to your desktop environment.
Offered GUI and options may differ slightly on the distribution and Desktop Environment you’re using but rest assured there is an option to change the power state of the system. And with GUI, it’s no more than few clicks in the power menu.
systemctl Command
On a Linux box running systemd as the init system, you can use systemctl command to reboot your machine.
Or you can simply use systemctl with required option, like for reboot as:
For initiating a shutdown, systemctl command goes like:
To halt the system, use:
shutdown Command
shutdown command can be used to power down as well as reboot a Linux system. To reboot a system immediately use:
Or to power down a system without wait, use -h or -P flag:
We can add a delay to shutdown command to reboot/power off the system after a specified interval. This can be achieved as:
To halt a system without asking hardware to power off, you can use -H flag:
If you simply specify shutdown command, the shutdown will get scheduled after a minute. To shut down at specific time use:
In many cases, while a system is going down it’ll broadcast a message to the console of logged-in users. If you want to add your custom message in this broadcast, you can specify a message along with shutdown command as:
To cancel a scheduled shutdown, you can use -c flag:
On some systems, shutdown command call systemctl in the backend to achieve desired reboot/shutdown operation.
Reboot Command
To gracefully reboot a system, you can also use reboot command (may need to use with sudo).
To power off the system with the reboot command, use -p flag:
To force a reboot (for systems not responding to normal reboot command), you can try -f flag as:
Halt Command
To halt a system, you can simply use halt command:
Poweroff Command
To power off a system, you have the option to use poweroff command:
init Command
For systems not running on systemd, init ( telinit will also work) command offers options to change the system’s run-level. To reboot a system using init , you can use:
Similarly to halt a system, the init command to use is:
Calling a specific run-level using init causes the system’s init process to execute a series of init scripts in a particular order to ensure the system reaches the desired run-level. Run-level 6 is defined for reboot while run-level 0 if for halting the system.
Power Button
For Linux running on a desktop or laptop, pressing the power button by default have the action of either putting the system to sleep or powering it down by sending the shutdown signal. This option can be tweaked from the system’s power settings. Although it should ideally be used as the last option if normal commands don’t work.
For a remote server running Linux, the power button usually powers off the system. But those located in remote data centers have the additional option to be rebooted or powered off from their remote lights-out management CLI/GUI tools offered by the respective server vendors.
Alt + SysRq Combination
For a non-responding, frozen system, it’s hard to bring it to a reboot or power off state. When you’ve no other option and as a last resort, you can try pressing Alt + PrintScreen + a sequence of keys in order to instantly reboot the system. It may not be a preferred or recommended option but nevertheless can be used as a last resort.
Always remember that there is possibility of data loss and corruption using this method as with any other non-graceful, forced reboot or shutdown option will have. Ensure system best practices for backups and redundancy and be careful when using this option.
For this option to work, it should have been enabled in the Linux kernel. You can check this by using below command:
An output of 1 indicates its enabled completely, while a number greater than indicates its partially enabled with some features. To enable it explicitly, you can use:
To reboot a system using this method, keep holding Alt + SysRq (PrintScreen) and then press in sequence following keys after interval of few seconds between each key:
or to shutdown press O instead of B at the end:
Here what the keys mean:
- R: Switch keyboard from raw to XLATE mode
- E: Send SIGTERM signal to all processes except init
- I: Send SIGKILL signal to all processes except init
- S: Sync all mounted filesystems
- U: Remount all mounted filesystems as read-only
Lastly, we’ve either B or O which stands for:
- B: Immediately reboot the system, without unmounting partitions or syncing
- O: Immediately shut down the system, without unmounting partitions or syncing
Summary
So here go different ways that allow you to reboot or shut down a Linux system. It offers you options ranging from simple GUI interfaces to relatively complex terminal commands that can make your life easy or even allows you to automate stuff. For systems that froze for one reason or another, we discussed forced ways to achieve a reboot or shutdown state which may not be the ideal way but have to be used on rare occasions.
Take precautions while using the commands discussed in this article as they affect the system state and could possibly affect multiple users and services in the case of an enterprise server. Check out the man pages of commands suggested in this article to learn more about them and what all options they offer.
Источник