# Every single way you can reboot Linux
by Seth Kenlon

Linux is fully capable of running not weeks but years without a reboot, and in some industries that's exactly what Linux does, thanks to advances like ``kpatch`` and ``kgraph`.
For laptop and desktop users, though, that metric is a little extreme, and while it may not be a day-to-day reality, it's at least a weekly reality that sometimes you have a good reason to reboot your machine.
And for a system that doesn't need rebooting often, Linux offers plenty of choices for you when it's time to start over.


## Click the button

The first way to reboot or shutdown Linux is the most common way, and the most intuitive for most desktop users regardless of their OS: it's the **Power** button in the GUI.
Because powering-down and rebooting are common tasks on a workstation, you can usually find the power button in a few different places.

On the GNOME desktop it's in the System Tray:

![](gnome-menu-power.jpg)

It's also in the Activities Menu:

![](gnome-screen-reboot.jpg)

On the KDE desktop, it can be found in the Applications Menu:

![](kde-menu-power.jpg)

And it can be brought by right-clicking on the desktop and selecting the **Leave** option:

![](kde-screen-power.jpg)

Other desktops provide variations on these themes, but the general idea is the same: you use your mouse to locate the power button and then you click it.
You may have to select between rebooting and powering-down, but in the end the result is nearly the same: processes are stopped, nicely, to allow data to be saved and temporary files to be removed, data is synchronized to drives, and then the system is powered down.

## Push the button

Most computers have a physical power button.
If you press the button, your Linux desktop may display a power menu with options to shutdown or reboot.
This is provided by the Advanced Configuration and Power Interface (ACPI) subsystem, which communicates with the firmware of your motherboard to control the state of your computer.

ACPI is important but it's limited in scope, so there's not much to configuring it, from the user's perspective.
Usually ACPI options are generically called **Power**, and they're usually set to a sane default, but if you want to change it, you can do so from your System Settings application.

On GNOME, open **Settings** from the Activities menu or from the System Tray menu, and select the Power category in the left column.
In the **Suspend & Power Button** section, select what you want the physical power button to do.
Common options are Suspend, Power Off, Hibernate, or Nothing.

![](gnome-settings-power.jpg)

After it's set, pressing the physical button of your computer provides the option you chose.
Depending on your computer vendor (or parts vendors, if you build your own), a "press" might be a light tap or it may require a slightly long press, so you might have to do some tests before you get the hang of it.
Beware of an over-long press, which may shut your computer down without warning.


## Systemctl

If you operate more in a terminal than in a GUI desktop, you might prefer to reboot with a command.
Broadly speaking, rebooting and powering-down are processes of the init system, the sequence of programs that bring a computer up or down after a power signal (either on or off, respectively) has been received.
On most modern Linux distributions, systemd is the init system, so both rebooting and powering-down can be performed through the systemd user interface, ``systemctl``.

The ``systemctl`` command accepts, among many other options, ``halt``, ``reboot``, and ``poweroff``.
These are mostly equivalent to starting the target file of the same name.
For instance, to trigger a reboot:

```
$ sudo systemctl start reboot.target
```

## Shutdown

Traditional UNIX, before the days of systemd (and for some Linux distributions, like [Slackware](http://slackware.com), that's now), there were commands specific to stopping a system.
The ``shutdown`` command, for instance, can power down your machine, but it has several options to control exactly what that means.
It requires a time argument, in minutes, so that ``shutdown`` knows when to execute.

To reboot, append the ``-r`` flag:

```
$ sudo shutdown -r now
```

To power-down:

```
$ shutdown -P now
```

To reboot after 10 minutes:

```
$ shutdown -r 10
```

Shutdown is a safe way to poweroff or reboot your computer, allowing disks to sync and processes to end.
It prevents new logins within the final 5 minutes leading up to the shutdown call, which is particularly useful on multi-user systems.

On many systems, the ``shutdown`` command is actually just a symlink to ``systemctl`` with the appropriate reboot or poweroff option.


## Reboot

The ``reboot`` command, on its own, is basically a shortcut to ``shutdown -r now``.
If you use the ``--force`` flag, however, the shutdown step is skipped, which can be abrupt for running processes, so it should only be used when you have reason to believe that the ``shutdown`` command is blocking you from powering-down.

From a terminal, this is the easiest and quickest reboot command:

```
$ sudo reboot
```

On many systems, ``reboot`` is actually a symlink to ``systemctl`` with the appropriate reboot or poweroff option.

## Brute force

That's a list of all the "right" ways to reboot or shutdown your Linux computer.
To be thorough, I am going to list additional methods of bringing down a Linux computer, but by no means are these methods recommended.
They aren't designed as a daily reboot or shutdown command (``reboot`` and ``shutdown`` exist for that), but they're valid means to accomplish the task.
If you try these methods, try them in a virtual machine.
Otherwise, use them in emergencies.


### Init

On Linux distributions without systemd, there are up to 7 runlevels your computer understands.
Different distributions can assign each mode uniquely, but generally 0 initiates a halt state, and 6 initiates a reboot (everything in between denotes single-user mode, multi-user mode, a GUI prompt, and a text prompt).
These modes are defined in ``/etc/inittab`` on systems without systemd.
On distributions using systemd as the init system, the ``/etc/inittab`` file is either missing or it's just a placeholder.

The ``telinit`` command is the front-end to your init system.
If you're using systemd, then it's a symlink to ``systemctl`` with the appropriate options.

To poweroff your computer by sending it into runlevel 0:

```
$ sudo telinit 0
```

To reboot using the same method:


```
$ sudo telinit 6
```

How unsafe this is for your data depends entirely on your init configuration.
Most distributions try to protect you from "pulling the plug" (or the digital analogue of that) by mapping runlevels to friendly commands.
You can see for yourself what happens at each runlevel by reading the init scripts found in ``/etc/rc.d`` or ``/etc/init.d``, or by reading systemd targets in ``/lib/systemd/system/``.


### proc

A step lower than the init system is the ``/proc`` filesystem, a virtual representation of nearly everything happening on your computer.
For instance, you can view your CPUs as if though they were text files with ``cat /proc/cpuinfo``, view how much power is left in your laptop's battery, or, after a fashion, reboot your system.

There's a provision in the Linux kernel for System Requests (``Sysrq`` on most keyboards).
You can communicate directly with this subsystem using key combinations, ideally regardless of what state your computer is in; it gets complex on some keyboards because the **Sysrq** key can be a special function key that requires a different key (such as **Fn** on many laptops).
Less likely to fail is using echo to insert information into proc, manually.

First, make sure that the sysrq system is enabled:

```
echo 1 > /proc/sys/kernel/sysrq
```

To reboot, you can use either **Alt** **Sysrq** **b** or type:

```
$ echo b > /proc/sysrq-trigger
```

This is not a reasonable way to reboot your machine on a regular basis, but it gets the job done in a pinch.


### Reboot upon crash with sysctl

Kernel parameters can be managed during runtime with ``sysctl``.
There are lots of kernel parameters, and you can see them all with ``sysctl --all``.
Most probably don't mean much to you until you know what to look for, and in this case you're looking for ``kernel.panic``.
You can query kernel parameters using the ``--value`` option:

```
$ sysctl --value kernel.panic
0
```

If you get a 0 back, then the kernel you're running has no special setting, at least by default, to reboot upon a kernel panic.
That's fairly typical, because rebooting immediately on a catastrophic system crash makes it difficult to diagnose the cause of the crash.
Then again, on systems that need to stay on no matter what might benefit from an automatic restart after a kernel failure, so it's an option that does get switched on in some cases.

You can activate it as an experiment (if you're following along, try this in a virtual machine rather than your actual computer):

```
$ sudo sysctl kernel.reboot=1
```

Now, should your computer experience a kernel panic, it is set to reboot instead of wait patiently for you to diagnose the problem.
You can test this by simulating a catastrophic crash with sysrq.

Make sure that Sysrq is enabled:

```
$ echo 1 > /proc/sys/kernel/sysrq
```

And then simulate a kernel panic:

```
$ echo c > /proc/sysrq-trigger
```

Your computer reboots immediately.


## Rebooting

Rebooting is a unique process on each operating system.
Even within [POSIX](https://opensource.com/article/19/7/what-posix-richard-stallman-explains) systems, the commands to power-down and reboot may behave differently due to different init systems or command design.
Despite that, two concepts are vital:

* Rebooting is rarely requisite on a POSIX system. Your Linux machine can operate for weeks or months at a time without a reboot, if that's what you need. There's no need to "freshen" your computer with a reboot unless specifically advised to do so by a software installer or updater. Then again, it doesn't hurt to reboot, either, so it's up to you.
* Rebooting is meant to be a friendly process, allowing time for programs to exit, files to be saved, temporary files to be removed, filesystem journals updated, and so on. Whenever possible, reboot using the intended interfaces, whether in a GUI or a terminal, and only force your computer off when there's no other option.

Have I left out your favourite method of rebooting or powering-down a system? List what I've missed in the comments!