How to Reboot and Shutdown Linux Servers?

As Sysadmin, probably the most frequent actions is restarting or shutting down servers.

This can be because of common upkeep actions, akin to patching the working system, or a {hardware} failure that requires the system to be shut down for upkeep.

A Linux system provides a number of methods to restart or shut down the server. A standard system ought to reply to each command, whereas a degraded server might require a forceful reboot. Please notice that almost all of those instructions require a sure privilege stage, both as a superuser or with sudo, to run efficiently, as a system reboot is an administrative process and for a system or server with a number of customers working important processes restart or shut down disruptive exercise.

This text covers some such strategies that may assist you to reboot/shut down Linux.

GUI technique

If you’re utilizing a GUI desktop atmosphere for Linux, akin to Gnome, KDE, Mate, XFCE, and so on., you can see an influence button within the system/software menu that gives actions akin to logging out, rebooting, hibernating, or Swap off. The choices accessible might fluctuate barely relying on the distribution, desktop atmosphere, and model of the working system in use. However you’ll actually discover power-related settings within the accessible menus that help you change the facility state of your system.

For instance, on my Ubuntu Mate desktop, I discover the Shut down possibility within the energy menu on the high proper of my display.

Ubuntu mate shut down gui

As soon as you choose the “Shut Down…” possibility, you’ll be introduced with a dialog field with a number of choices, akin to Droop, Restart, Cancel, and Exit. You possibly can proceed with Restart or Shut Down by clicking the suitable button, or you possibly can cancel and return to your desktop atmosphere.

Ubuntu mate shut down

The GUI and choices provided might fluctuate barely relying on the distribution and desktop atmosphere you’re utilizing, however relaxation assured that there’s an possibility to alter the system’s energy state. And with GUI, it is only a few clicks in the primary menu.

systemctl command

On a Linux field with systemd as init system, you need to use the systemctl command to reboot your machine.

$ sudo systemctl begin reboot.goal

Or you possibly can simply use systemctl with the required possibility, akin to for reboot if:

$ sudo systemctl reboot

To begin a shutdown, systemctl command goes like:

$ sudo systemctl shutdown

To cease the system use:

$ sudo systemctl halt

shut command

shutdown command can be utilized to close down and reboot a Linux system. To reboot a system instantly, use:

$ sudo shutdown -r now

Or use to close down a system with no ready time -h or -P flag:

$ sudo shutdown -P now 

We will add a delay to it shutdown command to reboot/shut down the system after a specified interval. This may be achieved if:

$ sudo shutdown -r 10

To cease a system with out asking the {hardware} to close down, you need to use -H flag:

$ sudo shutdown -H now

In the event you simply specify shutdown command, the shutdown is scheduled after one minute. To show off at a particular time:

$ sudo shutdown 22:30

In lots of circumstances, whereas taking place, the system broadcasts a message to the console of logged-in customers. If you wish to add your individual message to this broadcast, you possibly can add a message shutdown command as:

$ sudo shutdown 23:00 "Powering off system for upkeep...save your work"

To cancel a scheduled shutdown, you need to use -c flag:

$ sudo shutdown -c

On some techniques it’s shutdown command name systemctl within the backend to attain the specified restart/shutdown operation.

Restart command

To carry out a clear reboot of a system, you can even use reboot command (could also be wanted to make use of with sudo).

$ sudo reboot

Use to energy down the system with the reboot command -p flag:

$ sudo reboot -p

To drive restart (for techniques not responding to regular reboot command), you possibly can attempt -f flag as:

$ sudo reboot -f

Cease command

To cease a system you possibly can merely use halt command:

$ sudo halt

Shutdown command

To disable a system, you will have the choice to utilize poweroff command:

$ sudo poweroff

init command

For techniques not working on systemd, init (telinit additionally works) offers choices to alter the system runlevel. To reboot a system utilizing inityou need to use:

$ sudo init 6

In the identical approach to cease a system, the init command to make use of is:

$ sudo init 0

Calling a particular runlevel with init causes the system’s init course of to execute a collection of init scripts in a particular order to make sure that the system reaches the specified runlevel. Runlevel 6 is outlined for rebooting, whereas runlevel 0 is outlined for stopping the system.

Energy button

For Linux on a desktop or laptop computer, urgent the facility button by default causes the system to fall asleep or shut down by sending a shutdown sign. This selection might be adjusted by way of the system’s energy settings. Though ideally it must be used as a final possibility if regular instructions do not work.

On a distant server working Linux, the system is normally turned off with the facility button. However these positioned in distant information facilities have the extra possibility of being rebooted or powered down by way of their CLI/GUI distant lighting administration instruments supplied by the respective server distributors.

Alt + SysRq mixture

For an unresponsive, frozen system, it’s troublesome to reboot or shut down. When you’ve got no different alternative and as a final resort, you possibly can attempt urgent Alt + PrintScreen + a sequence of keys to right away restart the system. It might not be a most popular or beneficial possibility, however it will probably nonetheless be used as a final resort.

All the time needless to say there’s a risk of knowledge loss and corruption when utilizing this technique, identical to another unsavory, compelled restart or shutdown possibility. Guarantee system finest practices for backups and redundancy and use warning when utilizing this feature.

For this feature to work, it should be enabled within the Linux kernel. You possibly can examine this through the use of the command beneath:

$ cat /proc/sys/kernel/sysrq

An output of 1 signifies that it’s absolutely enabled, whereas a quantity better than signifies that some options are partially enabled. To allow this explicitly, you need to use:

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

Maintain to reboot a system utilizing this technique Alt + SysRq (PrintScreen) after which press the next keys in sequence with an interval of some seconds between every key:

R E I S U B

or press to exit O as an alternative of B on the finish:

R E I S U O

Here is what the keys imply:

  • R: Swap the keyboard from uncooked to XLATE mode
  • E: Ship a SIGTERM sign to all processes besides init
  • I: Ship a SIGKILL sign to all processes besides init
  • S: Synchronize all mounted file techniques
  • U: Remount all mounted file techniques as read-only

Lastly, now we have B or O, which stands for:

  • B: Reboot the system instantly, with out dismounting or synchronizing partitions

OR

  • O: Shut down the system instantly, with out dismounting or synchronizing partitions

Resume

So listed here are a number of methods you possibly can reboot or shut down a Linux system. It offers you choices starting from easy GUI interfaces to comparatively complicated terminal instructions that may make your life simple and even help you automate issues. For techniques that bought caught for some cause, we have lined compelled methods to enter a reboot or shutdown state, which might not be the perfect means, however must be utilized in uncommon circumstances.

Take precautions when utilizing the instructions mentioned on this article as they have an effect on system state and might doubtlessly have an effect on a number of customers and companies within the case of a company server. Take a look at the command man pages recommended on this article to study extra about them and what choices they every provide.

Discover ways to configure WS to cease asking for password throughout shutdown right here.

Rate this post
Leave a Comment