Soft reboot and instant shutdown of the computer in Ubuntu. Shutdown Linux from the command line How to shutdown Linux from the console

None operating system not ideal. Even if this is the case, there may be problems with drivers and applications. Linux is no exception. Even though it is more stable than Windows, there will probably come a time when you need to restart your Linux computer.

But how could you do it? Several commands are available to shut down or restart a Linux computer through the terminal.

Let's take a look at them one by one and see how and when these commands should be used.

1. Shutdown

If you're done with Linux, the solution is simply to disable it, for this you can use the command syntax:

shutdown

For example, to immediately shut down the computer, you would use:

Where -h means stop and now— now, which means the instruction must be executed immediately. Various delays can be used. For example, instead you can use +5 , which will tell the computer to perform the shutdown procedure in five minutes.

If you want to use message(message), it will flash to all registered users:

shutdown -h +5 "Server is shutting down, save your work and log out."

Remember that you can find the full list of switches for these commands by typing:

Restart with -r

An alternative is to use the command -r to restart your computer. It is used instead -h, therefore, to restart your computer or server, you can use:

shutdown -r +5 "Server is restarting in five minutes, save your work and log out."

Any scheduled shutdown or restart can be canceled by issuing the command -c:

2. Reboot

Since the shutdown command has a restart option, it's not surprising that the reboot command has a shutdown option.

Standard reboot command:

This will prompt your computer to turn off and on again. However, if you want to turn off the device, then the key -p will work:

Another option is a forced reboot. This can be useful if an application or service is frozen and you need to quickly reboot:

This command will force reboot your Linux PC.

3. Stop

We have already seen the switch -h above, but stop can be used as a command by itself. This will immediately shut down the computer with a simple four letter word:

Switch -f can also be used with a stop, but the results are inconsistent, and may lead to system stability problems.

4. power off

You may prefer command terminology power off. This does the same thing as halt, except that typing takes twice as long.

However, apart from using -f to force power off, you can also use the key -w to log a call to reboot the system in /var/log/wtmp. This is a potentially useful debugging tool, like -verbose, which can help with shutdown issues.

poweroff --verbose

5. Emergency option: REISUB

All of the above commands can be used in situations where the system works without problems. But what if the computer or server freezes and cannot be restarted in an acceptable way?

The answer then is a keyboard shortcut. If you have switched from Windows, you probably know that Ctrl+Alt+Del displays menu with shutdown as an option. If you hold it longer, the machine will turn off automatically. At the same time, on a Mac, you just have to hold down the power button (an option that also works on Windows hardware).

On Linux, the keyboard shortcut to reboot Alt+PrintScreen+B. However, if this doesn't work or there is a more complex issue, you can change the combination using up to six keys.

This is known as REISUB, due to the following forced abbreviation:

  • un R aw - returns keyboard control back from the X display server.
  • t E rminate - Sends a SIGTERM termination signal to all processes for graceful termination.
  • k I ll - As above, but the SIGKILL signal, which causes the processes to terminate immediately.
  • S ync flushes data to disk.
  • U nmount - Remounts all filesystems to a read-only state.
  • re B oot - which is to be expected.

For this to work, you must hold Alt + PrintScreen, and then, one by one, press the keys: R E I S U B, in the same order. The delay between each press should be 1-2 seconds. This is necessary in order to give a little time to complete all of the above processes. Please note that this method usually does not work on ARM architecture computers.

Help, I accidentally turned off my Linux computer or server!

We have seen how to cancel a shutdown or restart command. However, there are situations that you run the shutdown command when a vital process is running, especially on a remote server. You can get around this by setting molly guard, which can undo the shutdown by checking certain parameters.

For example, there is a script that checks for SSH sessions. If you send a reboot, stop or shutdown command, molly-guard will require the name of the host you are about to close.

To do this, install molly-guard in the terminal:

sudo apt-get install molly-guard

Because molly-guard works in background, it will detect a command like power off, and report that an SSH session was detected. You can then enter the server hostname to confirm the shutdown, or press ctrl+c to cancel. Healthy!

These five ways to shut down a Linux computer from command line are particularly useful as they can be used on the machine itself or via remote SSH. Since these commands are very concise, they are suitable for quick use - which can lead to random reboots from time to time! Fortunately, the molly-guard utility is enough to avoid this.

To learn more about , check out our reference table.

Linux file system buffers are stored in memory and only occasionally written to disk. This speeds up disk I/O operations, but increases the risk of data loss in the event of a sudden failure.

Traditional UNIX and Linux systems were very picky about the shutdown procedure. Modern systems are more tolerant (especially when it comes to a highly reliable filesystem like ext3fs), but it's still best to gracefully shut down if possible. Incorrect shutdown of the computer can lead to the appearance of hard-to-find, non-obvious errors, and sometimes to a complete crash of the system.

Rebooting the system on a personal computer is a remedy for almost all problems. But when working in Linux, we advise you to think first and only then reboot. Problems that occur in Linux tend to be subtle and complex, so rebooting produces the expected result much less frequently than on other systems. In addition, the Linux reboot process takes a long time, which creates inconvenience for users.

It is necessary to reboot when a new device is connected or a working device freezes so that it cannot be initialized. If a configuration file is modified that is only queried on boot, the changes will only take effect after a reboot. And, finally, if it is impossible to register in the system, there is simply no other way out but to reboot.

If one of the system startup scripts is modified, then you need to reboot at least to check if the system functions successfully after the changes. If a problem doesn't surface within the next few weeks, you won't remember the details of the latest changes afterwards.

Unlike booting, which is the only way, you can stop and reboot the system in different ways:

  • turn off the power;
  • enter the shutdown command;
  • use halt and reboot commands;
  • change the runlevel of the init daemon using the telinit command;
  • run the poweroff command to ask the system to turn off the power.

Power off in Linux

Even on desktop systems, turning off the power is not the best way to shut down the system. This can result in data loss and file system corruption.

Some computers have a soft stop button that, when pressed, executes a series of commands that gracefully shuts down the system. If you are not sure if your computer supports this feature, do not try to find out by pressing the power button while the system is running! There will be much less problems if you stop the system manually.

Of course, foresight is good within reason. In the event of a flood or fire, it is better to turn off the power if there is simply no time to properly shut down the system. Once upon a time in the machine rooms there was an emergency button that allowed you to turn off all the equipment at the same time.

Team shutdown: the correct way to shut down the system

The shutdown command is the safest and most correct way to shut down or reboot the system, or return to single user mode.

You can instruct the command to pause before shutting down the system. While waiting, the team sends messages to registered users at gradually shortening intervals, warning of an upcoming event. By default, the messages indicate that the system is shutting down and indicate the time remaining before the shutdown occurs. Optionally, the administrator can add their own short message explaining why the system is being stopped and approximately how long it will take before being able to log in again. After issuing the shutdown command, users will be prevented from logging in, but they will see the message provided by the administrator.

With the shutdown command, you can specify what the system should do after executing the command: stop (-h) or reboot (-r). You can also specify whether the fsck (-F) command should force a disk check after a reboot or not (-f). By default, Linux automatically skips this check if the file systems have been properly unmounted.

The following command reminds users of a scheduled maintenance procedure and shuts down the system at 9:30 AM:

$ shutdown -h 09:30 "Going down for scheduled maintenance. Expected downtime is 1 hour"

You can also set a relative shutdown time. For example, the following command will start the shutdown process after 15 minutes:

$ shutdown -h +15 "Going down for emergency disk repair."

Team halt: an easier way to stop

The halt command performs all the basic operations required to halt the system.

It is usually invoked with the shutdown -h command, but can also be used on its own. The command logs the fact of the halt, kills non-essential processes, executes the sync system call, waits for disk writes to complete, and then terminates the kernel.

With the -n option, the sync system call is suppressed. The halt -n command is used after restoring the root partition with the fsck command, so that the kernel cannot overwrite fixes with old versions of the partition stored in the cache.

Team reboot: fast restart

The reboot command is almost identical to the halt command. The only difference is that the system reboots instead of stopping. The reboot mode is also invoked by the shutdown -r command. The reboot command also supports the -n flag.

Team telinit: change daemon runlevel init

You can use the telinit command to instruct the init daemon to jump to a particular runlevel. For example, the command

The Ubuntu Linux interface is fairly stable, but sometimes you still need to restart it. This can be done in several ways. In this article, I will provide ways to restart multiple desktop environments.

What to do if the entire Ubuntu interface freezes

AT latest versions Ubuntu, Lubuntu and Xubuntu systems require a restart of LightDM. This is done by the command:

sudo service lightdm restart

For the Kubuntu environment, use the command:

sudo /etc/init.d/kdm restart

What to do if the program freezes

What if the program window does not respond? If there is no need to restart the entire interface, for example, if a certain graphical application is frozen, then in this case you can use the convenient utility xkill.
To use this utility to close a specific application, you need to press the key combination ALT+F2 and write xkill, then click Enter on keyboard.
After the operation is completed, the mouse cursor on the screen will turn into a cross, and when you click on any selected window with such a cursor, the process running in it (the program itself, which has hung) will end.

What to do if everything freezes completely

If the computer with ubuntu does not respond to any user actions, then you should use the following instructions:

Ubuntu was stuck

What should I do if the Ubuntu operating system freezes completely and does not even respond to the keyboard shortcut to switch to the terminal (ALT + F1-F7)?
In this situation, you can apply a soft (safe) reboot method using a specific command.
Keys must be pressed at the same time Alt + PrtScnSysRq and without releasing them in turn, press the following combination: R E I S U B
After that, the PC will restart.
What happens when you use this combination?

In order to remember this command, you can remember the word BUSIER in English (association with busyness, equal to the unavailability of the system).

Let's consider how to restart or shut down the computer from the command line. I use this when, when installing a driver or under heavy load on the processor, the interface stops responding to my actions (although this happens extremely rarely). It is possible to kill the "gluttonous" process through the command line, but it is not always known which process it is, so a quick solution is to restart the computer.

We restart the computer

I do so. Go to the console by pressing a keyboard shortcut Ctrl+Alt+F1. In the console, you must first enter your username and password (characters are not displayed when entering a password). And I run the command:

sudo reboot

You will again need to enter the administrator password and press Enter. The computer will restart.

You can also use the command to restart your computer. shutdown, for this you need to use the key -r:

Sudo shutdown -r now

Turn off the computer

To turn off the computer from the command line, you need to run the command:

sudo shutdown -h now

You can also turn off the computer by running the command:

Sudo halt

And also can be used.

This article is aimed at the most new to Linux and those who are interested in how to reboot Linux from the console. For me, restarting the computer in the terminal or using the graphical interface is elementary, but this is the base, not all beginners know it and I need to write about it.

Today we'll cover issues such as the command to reboot Linux from the console, reboot remotely, and directly reboot in the graphical interface. Let's start with the usual reboot of the system.

Here, as they say, what could be easier. Consider first rebooting in Ubuntu Unity. Just click on the gear button in the upper right corner of the screen, and select the item Shutdown:

Then, in the window that opens, click on the item:

In the Gnome desktop environment, everything is very similar to Unity, but in KDE you need to open the main menu, go to the tab exit, and select the item reload:

Then confirm reboot.

Restart Linux in Terminal

And here the scope is much wider, there are about a dozen commands that can be used to reboot Linux. Some need root privileges, others don't, some look simple and easy to remember, while others are long and complex. Next, we will look at all of them.

The first Linux reboot command, the most common and simplest:

As you can see, the utility needs superuser rights. After pressing Enter, the computer will immediately go into reboot.

The shutdown utility, which is used to shut down, also allows you to restart the computer; for this, you need to pass the -r parameter to it. Plus, you can also specify the reboot time. Now - 0 or now, after one minute +1 after two - +2, and so on:

sudo shutdown -r +1

In initialization systems compatible with Init Scripts, there were system boot levels - 0,1,2,3,4,5,6, level 0 - meant shutdown, 6 reboot, other modes of the system are not of interest to us now. You can switch between levels with the init command. But again, you need superuser rights. In this way:

The dbus system message service can also restart the computer:

/usr/bin/dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart

You no longer need superuser rights. These were the usual ways to reboot Linux, but there is one more, non-standard or even two. These are the magic SysRq keys. The Linux kernel listens for certain key combinations being pressed, and performs the desired action in response to them. First enable sysrq support:

echo 1 > /proc/sys/kernel/sysrq

It is better to do this in advance, since this method is useful when the system is frozen and does not react to anything:

nano /etc/sysctl.conf

kernel.sysrq=1

To activate SysRq combinations hold Alt + SysRq and press the key code. For a normal reboot, it is recommended to use the following sequence: R E I S U B, press the keys in the same sequence with an interval of about a second.

  • R- returns keyboard control if the X server was terminated incorrectly;
  • E- the kernel sends a SIGTERM signal to all processes except init;
  • I- sends a SIGKILL signal to all processes except init;
  • S- the kernel synchronizes file systems, all data from the cache is transferred to the hard disk;
  • U- remounts all file systems in read-only mode;
  • B- immediate reboot, without synchronization, and additional preparations.

Before rebooting, the system waits for all processes to terminate, stops all services, dismounts, and mounts read-only file systems. This is what we do by pressing these key combinations in sequence. But if you need to reboot the system now without waiting for the shutdown of all processes, for example, the server, you can immediately send a signal B. Like this: Alt+SysRq+B.

SysRq can be used without keyboard shortcuts by writing the desired operation code to the /proc/sysrq-trigger file:

echo b > /proc/sysrq-trigger

The system will be rebooted as is, without stopping services and preparing file systems, so unsaved data may be lost, and file system damaged.

Linux remote reboot

If you have access to the server via ssh, then it is very easy to reboot linux remotely using one of the above commands, for example:

ssh [email protected]/sbin/reboot

But again, for this operation, you need to have root rights on the remote server.

conclusions

Now you know how to reboot linux, you even know how to reboot the server via ssh. If you have any questions, ask in the comments!

Related posts:


 
Articles on topic:
Delete data permanently Erase all data from the hard drive
Order in the computer is the key to user well-being - no glitches, maximum performance. Yes, and it is clear visually where which file lies, what programs are installed, what they are for. But if, on the contrary, chaos reigns on PC disks ... - this is, def
Messenger usage statistics
They are the main means of communication among users of mobile devices and computers. SMS, MMS, and even email are becoming obsolete and less convenient than instant messaging apps, which often use your phone number.
Fundamentals of client-server technology Network login
Client-server technology is a method of connection between a client (user's computer) and a server (powerful computer or equipment that provides data), in which they interact directly with each other. What is a “client-server”? Common
Shutdown Linux from the command line How to shutdown Linux from the console
No operating system is perfect. Even if this is the case, there may be problems with drivers and applications. Linux is no exception. Although it is more stable than Windows, there will probably come a time when you need to restart your computer.