3 commands to reboot Linux (plus 4 more ways to do it safely)

Learn how to reboot Linux through many different methods, from the GUI to deep within the command line.
213 readers like this.

Linux is fully capable of running not weeks, but years, without a reboot. 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. 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 when it’s time to start over.

Understand your options

Before continuing though, a note on rebooting. Rebooting is a unique process on each operating system. Even within POSIX systems, the commands to power down and reboot may behave differently due to different initialization systems or command designs.

Despite this factor, two concepts are vital. First, 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 up" 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.

Second, 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. If you force your computer to shut down or reboot, you risk losing unsaved and even recently-saved data, and even corrupting important system information; you should only ever force your computer off when there’s no other option.

Click the button

The first way to reboot or shut down Linux is the most common one, and the most intuitive for most desktop users regardless of their OS: It’s the power button in the GUI. Since powering down and rebooting are common tasks on a workstation, you can usually find the power button (typically with reboot and shut down options) in a few different places. On the GNOME desktop, it's in the system tray: 

The GNOME power button.

It’s also in the GNOME Activities menu:

The GNOME Activities menu power button.

On the KDE desktop, the power buttons can be found in the Applications menu:

The KDE power buttons via the Applications menu.

You can also access the KDE power controls by right-clicking on the desktop and selecting the Leave option, which opens the window you see here:

The KDE power buttons via the Leave option.

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

Push the physical button

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

ACPI is important but it’s limited in scope, so there’s not much to configure from the user’s perspective. Usually, ACPI options are generically called Power and are set to a sane default. If you want to change this setup, you can do so in your system settings.

On GNOME, open the system tray menu and select Activities, and then Settings. Next, select the Power category in the left column, which opens the following menu:

GNOME’s power button settings.

In the Suspend & Power Button section, select what you want the physical power button to do.

The process is similar across desktops. For instance, on KDE, the Power Management panel in System Settings contains an option for Button Event Handling.

KDE Power Management

opensource.com

After you configure how the button event is handled, pressing your computer’s physical power button follows whatever option you chose. Depending on your computer vendor (or parts vendors, if you build your own), a button press might be a light tap, or it may require a slightly longer push, so you might have to do some tests before you get the hang of it.

Beware of an over-long press, though, since it may shut your computer down without warning.

Run the systemctl command

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) is 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 (halts disk activity but does not cut power) reboot (halts disk activity and sends a reset signal to the motherboard) and poweroff (halts disk acitivity, and then cut power). These commands are mostly equivalent to starting the target file of the same name.

For instance, to trigger a reboot:

$ sudo systemctl start reboot.target

Run the shutdown command

Traditional UNIX, before the days of systemd (and for some Linux distributions, like Slackware, 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.

This command requires a time argument, in minutes, so that shutdown knows when to execute. To reboot immediately, append the -r flag:

$ sudo shutdown -r now

To power down immediately:

$ sudo shutdown -P now

Or you can use the poweroff command:

$ poweroff

To reboot after 10 minutes:

$ sudo shutdown -r 10

The shutdown command is a safe way to power off or reboot your computer, allowing disks to sync and processes to end. This command prevents new logins within the final 5 minutes of shutdown commencing, which is particularly useful on multi-user systems.

On many systems today, the shutdown command is actually just a call to systemctl with the appropriate reboot or power off option.

Run the reboot command

The reboot command, on its own, is basically a shortcut to shutdown -r now. From a terminal, this is the easiest and quickest reboot command:

$ sudo reboot

If your system is being blocked from shutting down (perhaps due to a runaway process), you can use the --force flag to make the system shut down anyway. However, this option skips the actual shutting down process, which can be abrupt for running processes, so it should only be used when the shutdown command is blocking you from powering down.

On many systems, reboot is actually a call to systemctl with the appropriate reboot or power off option.

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 (the numbers in between denote states such as 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 this command is a link to systemctl with the appropriate options.

To power off your computer by sending it into runlevel 0:

$ sudo telinit 0

To reboot using the same method:

$ sudo telinit 6

How unsafe this command is for your data depends entirely on your init configuration. Most distributions try to protect you from pulling the plug (or the digital equivalent 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 the systemd targets in /lib/systemd/system/.

Apply brute force

So far I’ve covered all the right ways to reboot or shut down your Linux computer. To be thorough, I include here 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 shut down 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 only in emergencies.

Proc

A step lower than the init system is the /proc filesystem, which is a virtual representation of nearly everything happening on your computer. For instance, you can view your CPUs as 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 to access (such as Fn on many laptops).

An option less likely to fail is using echo to insert information into /proc, manually. First, make sure that the Sysrq system is enabled:

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

To reboot, you can use either Alt+Sysrq+B or type:

$ sudo echo b > /proc/sysrq-trigger

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

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:

$ sudo sysctl --value kernel.panic

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 situation is fairly typical since rebooting immediately on a catastrophic system crash makes it difficult to diagnose the cause of the crash. Then again, 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 this feature as an experiment (if you’re following along, try this in a virtual machine rather than on your actual computer):

$ sudo sysctl kernel.reboot=1

Now, should your computer experience a kernel panic, it is set to reboot instead of waiting patiently for you to diagnose the problem. You can test this by simulating a catastrophic crash with sysrq. First, make sure that Sysrq is enabled:

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

And then simulate a kernel panic:

$ sudo echo c > /proc/sysrq-trigger

Your computer reboots immediately.

Reboot responsibly

Knowing all of these options doesn't mean that you should use them all. Give careful thought to what you're trying to accomplish, and what the command you've selected will do. You don't want to damage your system by being reckless. That's what virtual machines are for. However, having so many options means that you're ready for most situations.

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

What to read next
Seth Kenlon
Seth Kenlon is a UNIX geek, free culture advocate, independent multimedia artist, and D&D nerd. He has worked in the film and computing industry, often at the same time.

12 Comments

For me shutdown command is the most used in any case. But always is interesting to know other options available. Thanks for share.

To shut down, I usually use ``poweroff``.

I very rarely reboot, but when I do I just use ``reboot``.

I think it was great that they get remapped appropriately across distros, as I use Slackware on my main workstation and RHEL or Fedora on my laptop.

In reply to by marco.bravo

When your system is hopelessly frozen, the only option is to hold the power button in until it shuts off. You may lose some data, but I save anything important that I'm working on at frequent intervals.

Something else which can be useful for the shutdown command is specify a time of shutdown/reboot, like 13:30, 'sudo shutdown -r 13:30' to reboot at 1:30pm or some interval, 'sudo shutdown -r +40' to reboot in 40 minutes. You might use these when you are in the middle of something like compiling software or updating, which will take some time, but you know will be done after some interval.

Thanks Greg. I can't believe I left that out of the article! (Shows you how rarely I schedule shutdowns, I guess.)

In reply to by Greg P

scripting is the problem . . .

Why is it that In the GUI I can just click a couple of times to suspend (or shutdown) without being asked for the root password, yet trying to script something to do the same thing requires authorisation? Makes no sense to me.

The most recent occasion I encountered this problem was with a script that was transcoding using handbrakeCLI and wanting the system to suspend when it completed (sometime during the night). All I could come up with was running the script in a "sudo -s" terminal, then changing ownerships later, which seems fairly ridiculous.

(And I don't think this was always the case either. I'm fairly sure years ago I could run shutdown from a script without requiring authorisation)

The desktop environment itself has permissions associated with it; were you to kill it, you would have to authorize to restart KDM or GDM or whatever login manager you use.

If you want a regular user to be able to reboot or halt or shutdown without special authorisation, you can add that user to your sudoers file:

%admin ALL=NOPASSWD: /usr/sbin/halt, /usr/sbin/reboot, /usr/sbin/poweroff

If your current user is not a member of the ``wheel`` group already, add yourself to that group with

$ sudo usermod -a -G wheel $USER

Now your user can issue commands like ``sudo reboot`` without entering a password. Pre-authorisation is already granted through sudo.

You may also be able to just add yourself to a special group that already has permission to reboot and halt without auth, but which group that is depends on how your distro has set up groups.

Another possibility is that your user has permission to shutdown or reboot, but does not have access to the location where they are stored (/sbin or /usr/sbin, for example). Again, adding that user to an administrative group is the easy way to provide access.

In reply to by Gen Agg (not verified)

"shutdown -hP now" for me. This after struggling with a system once that wouldn't power off until it was halted first.
Thanks for a couple of the other tricks, which might be useful in a pinch.

That's a great data point. I don't think I've encountered a system that made that distinction (either that, or I've never encountered one with that distinction, upon which I've also had permission to halt or shut it down).

In reply to by Simon Harrison (not verified)

If my computer his stuck, I use REISUB command.
No one ever heard about ?
It's kernel call map on keyboard shortcut.
Pressing Alt+sys+ R then E then I then S then B.
The last one will reboot, one of them will stop disk write and so on.

I hadn't heard of that one, actually! I've heard of similar calls mapped to keyboard shortcuts (and I mention one in the article). This one's great to know about, thanks!

In reply to by William (not verified)

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.