How to reduce computer shutdown time in linux. Soft restart and instant computer shutdown in Ubuntu

File Buffers Linux systems 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 have been very demanding in terms of shutdown procedures. Modern systems are more tolerant (especially when it comes to a highly secure filesystem like ext3fs), but it is still better to shutdown gracefully if possible. Incorrect shutdown of the computer can lead to the appearance of hard-to-find, subtle errors, and sometimes to a complete system crash.

Reboot the system to personal computer- a means of solving almost all problems. But when working in Linux, we advise you to think first and only then reboot. Problems in Linux are usually hidden and complex, so reboots give the expected result much less often than on other systems. In addition, the Linux reboot process takes a long time, which is inconvenient 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 the configuration file is modified, which is polled only at initial boot, then the changes will take effect only 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 in order to check whether the system is functioning successfully after the changes. If any problem does not appear in the next few weeks, later you will hardly remember the details of the latest changes.

Unlike bootstrapping, which is done in a single way, you can stop and reboot the system in different ways:

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

Power off in Linux

Even in systems desktop computers turning off the power is not the best way to shutdown the system. This can lead to data loss and damage to file systems.

Some computers have a software stop button that, when pressed, executes a series of commands that gracefully shut 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 for a correct shutdown of the system. Once upon a time, there was an emergency button in the machine rooms, which made it possible to turn off all equipment at the same time.

Team shutdown: the correct way to shutdown the system

The shutdown command is the safest and most correct way to shutdown 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 command sends messages to registered users at gradually decreasing intervals, warning of an impending event. By default, the messages indicate that the system is shutting down and indicate the time remaining until the shutdown. If desired, the administrator can add his own short message, which explains why the system is halting, and approximately how long it will have to wait before you can log in again. After executing the shutdown command, users will not be able to log in, but they will see the message provided by the administrator.

The shutdown command can be used to specify what the system should do after executing the command: stop (-h) or reboot (-r). You can also specify whether a forced disk check should be performed after a reboot using the fsck command (-F) or not (-f). By default, Linux will automatically skip this check if the filesystems have been properly unmounted.

The following command reminds users of the scheduled service 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 the relative shutdown time. For example, the command below will start the shutdown process after 15 minutes:

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

Team halt: an easier way to stop

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

It is usually invoked with shutdown -h, but it can be used by itself. The command logs the shutdown, kills nonessential processes, executes the sync system call, waits for disk writes to complete, and then terminates the kernel.

The -n option suppresses the sync system call. The halt -n command is used after restoring the root partition with the fsck command so that the kernel cannot overwrite patches with older 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 and does not stop. The reboot mode is also invoked by the shutdown -r command. The reboot command also supports the -n flag.

Team telinit: change the runlevel of the daemon init

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

The shutdown command safely shuts down the system. All logged on users receive a notification that the system is shutting down and login operations are blocked. You can turn off the system immediately or after a specified delay.

Shutting down Linux from command line is very convenient, and many users of the system control their PC through the command line in such things. All processes are first notified that the system is preparing to sleep or reboot via SIGTERM. This gives programs like vi time to save the file being edited, mail and news handlers, the ability to log off, and so on.

Shutdown does its job by signaling init to change the runlevel. Runlevel 0 is used to stop the system, runlevel 6 is used to reboot the system, and runlevel 1 is used to put the system in a state where administrative tasks can be performed (single user mode). The default runlevel is 1 unless the -h or -r options are specified.

Your system may have a different set of parameters for the shutdown command; Check the documentation for the device.

Shutting down Linux from the command line

shutdown [-akrhPHfFnc] [-t sec] time [message]

  1. -a Control access to the shutdown command using the control access file /etc/shutdown.allow. For getting additional information see the Access Control section below.
  2. -k Do not shutdown, but send warning messages as if shutdown was real.
  3. -h Tells the system to shutdown and then stop it.
  4. -P Instructs the system to shutdown and then shutdown.
  5. -H If the -h option is specified, this option specifies that the system should boot into the boot monitor on systems that support it.
  6. -f Skip fsck after reboot.
  7. -F Force fsck after reboot.
  8. -n Do not invoke init to terminate processes; Instruct shutdown to do this yourself.
  • This option is not recommended and its results are not always predictable.
  1. -c Cancel pending shutdown. (This does not apply to "shutdown now", which does not wait until shutdown.) You cannot specify a time argument with this option, but you can specify an explanatory message to be sent to all users.
  2. t sec... Tell the initialist to wait seconds between sending a warning and a kill signal before going to another runlevel.
  3. time The time argument specifies when to perform the shutdown operation.

The time can be formatted in different ways:

First, it can be an absolute time in the format hh: mm, where hh is the hour (1 or 2 digits, from 0 to 23) and mm is the minute of the hour (in two digits).

Second, it can be in the + m format, where m is the number of minutes to wait.

Also, the word is now the same as indicating +0; He immediately shuts down the system.

  1. Message. A message sent to all users, along with a standard shutdown notification.

Details

If the shutdown is scheduled for the future, it will create an advisory file / etc / nologin, which forces programs like login to not allow new users. This file is generated five minutes before the shutdown sequence starts. Shutdown removes this file if it is stopped before it can signal initialization (that is, it was canceled or something went wrong). It also removes it before calling init to change the runlevel.

The -f flag means "reboot fast". This only creates an advisory / fastboot file that can be checked by the system when it reappears. The system boot rc file (“rc” stands for “runcom”, which is short for “run commands”) can check for the presence of this file and decide not to run fsck because the system was shut down properly. After that, the boot process should remove / fastboot.

The -F flag stands for "force fsck". This only creates an advisory / forcefsck file that can be checked by the system when it reappears. The boot rc file can check to see if the file is present and decides to run fsck with the special "force" flag to check that the filesystems are unmounted correctly. After that, the boot process should remove / forcefsck.

The -n flag makes shutdown not call init, but kill everything running processes... Shutdown will disable quota, accounting and swaps, and unmounting all file systems.

Access control

Shutdown can be called from init when CTRL-ALT-DEL is pressed, if a corresponding entry exists in / etc / inittab. This means that everyone who has physical access to the console keyboard, may close the system.

To prevent this, shutdown can check if an authorized user is logged in. If shutdown is called with the -a argument (add this to the shutdown call in / etc / inittab), it checks if the / etc /shutdown.allow file is present. It then compares the logins in that file to the list of people who are logged in on the virtual console (from / var / run / utmp). Only if one of the authorized users or root is logged in will it take effect. Otherwise, it will write a message

Shutdown: no authorized users logged in

To the physical console of the system. The format /etc/shutdown.allow is one username per line. Blank lines and comment lines (prefixed with #) are allowed. This file currently has a limit of 32 users.

Note that if /etc/shutdown.allow is missing, the -a argument is ignored.

Shutting down Linux and powering the computer

The -H option simply sets the initialization environment variable INIT_HALT to HALT, and the -P option simply sets this variable to POWEROFF. The shutdown script that calls halt as the last thing in the shutdown sequence must check these environment variables and call halt with the correct parameters for those parameters to actually have any effect.

Files

  • / fastboot
    / etc / inittab
    /etc/init.d/halt
    /etc/init.d/reboot
    /etc/shutdown.allow

Shutting down Linux from the command line: examples

Schedule a system shutdown at 8 am.

Schedule a system shutdown at 8 pm.

shutdown +15 "Upgrading hardware, downtime should be minimal"

Schedule a system shutdown in fifteen minutes. Along with the usual system shutdown notification, users will be given a descriptive hardware upgrade message.

Shutdown Linux immediately

Power down the system immediately and reboot automatically.

Shut down and automatically shut down the system immediately.

Related commands

  • Halt - Stop the computer.
  • Poweroff - Stop the computer.
  • Reboot - Stop the computer.
  • Wall - Send a message to all logged in users.

Translation from a wonderful English resource computerhope.

If you still have any questions on the topic "Shutting down Linux from the command line", you can write them to us in the comments form on the site.

If you find an error, please select a piece of text and press Ctrl + Enter.

Let's take a look at how to restart or shutdown your computer from the command line. I use this when installing a driver or heavy load on the processor, the interface stops responding to my actions (although this happens extremely rarely). You can kill a "gluttonous" process through the command line, but it is not always known what process it is, so a quick solution is to restart the computer.

Restart your computer

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

Sudo reboot

You will need to enter the administrator password again 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 you can use.

Then SysRq can help out in the most seemingly hopeless situations, unless, of course, the kernel is in a "panic", as is usually evidenced by chaotically blinking keyboard LEDs. Interesting? Then read on.

The SysRq key appeared long before Windows started taking screenshots. IBM originally intended the SysRq key to switch between applications without stopping them. But that's already history. Linux has adapted SysRq to give the user emergency access to the kernel. But here, too, everything is not simple. The fact is that for compatibility with Windows in Linux graphical environments, a single SysRq key works like PrintScreen, and the Alt + SysRq combination recommended in the textbooks on the console, just like in Windows, stupidly puts the picture of the active window into the clipboard. Therefore, in windowed Linux, the SysRq key ... is not there either! Instead of this key, in Linux graphical environments, the magic combination Alt + Ctrl + SysRq + Latin letter / number is used, which significantly increases your power over the machine.

M - displays the amount of used memory. Works in Ubuntu if you pre-install high level the details of the output.

N - displays a list of real-time tasks. Also works if you set the output level high beforehand.

E - Abnormally terminates all processes except init.

I - kills all processes, including init.

T - prints a list of tasks to the console.

S - Synchronizes all file systems, writing all buffered data to the hard drive.

R - forcibly returns the keyboard to working state. In this case, the kernel starts working with the keyboard directly, bypassing the X-server, and only in ASCII codes.

T - displays a list of processes. Again, only works at a high level of verbosity.

P - dump of processor registers. The request may be of interest to those who are engaged in software debugging.

Q - Displays hard timer events. Works if output verbosity is set to high.

O - urgently shuts down the computer.

B - restarts the computer. True, it is reported that with the kernel 3.8.0-25, there is no reboot, but a shutdown. But I haven't tested it myself.

U - Remounts all file systems read-only.

V - restores the console framebuffer. Let's say you are watching a video in the virtual console (yes, Linux, unlike Windows, allows this too), and you urgently need to remember what you were doing in the console before starting the video. The command will restore the console framebuffer. In general, it would be worthwhile to tell in more detail about this amusing thing - the framebuffer, but not in this article.

W - Shows all hung tasks, if any.

Z - Outputs the contents of the kernel trace buffer.

So, SUDDENLY your Linux hangs so that even rebooting the Xs with Alt + Del + BS does not help. Calm, only calm. In no case do not rush to press the reset button on the computer case. There is a very high probability that you will not lose data when you press consecutively. keys R-E-I-S-U-B(hold Alt + Ctrl + SysRq!). And you know what? You can always instantly turn off a normally working computer by pressing Alt + Ctrl + SysRq + O. Unless, of course, you closed your programs. :)

However, it seems dangerous to make the magic SysRq available if you let other users work remotely on your machine, or if you yourself work with it remotely. The fact is that the break signal sent from the remote console can be interpreted as Alt + SysRq, with all the ensuing consequences. Therefore, if you decide to give remote access to your machine, just in case, first reset the kernel.sysrq variable in the system config. You can also write a simple script on the bash for this and even screw a button on the desktop to it so that you do not bother editing the system config control file every time. Good luck!

This article is aimed at the most Linux newbies 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 basis, not all beginners know it and I need to write about it.

Today we will look at issues such as the Linux reboot command from the console, rebooting remotely, and directly rebooting into graphical interface... Let's start with a simple system reboot.

Here that being said, what could be easier. Consider rebooting into Ubuntu Unity first. It is enough to press the button with the gear in the right upper corner 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 the reboot.

Restart Linux in Terminal

And here the scope is much wider, there are about a dozen commands that can be used to restart Linux. Some need root privileges, others do not, some look simple and easy to remember, while others are long and complex. We'll look at all of them below.

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 reboot.

The shutdown utility, which is used for shutdown, 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 the init systems compatible with Init Scripts, there were system load levels - 0,1,2,3,4,5,6, level 0 meant shutdown, 6 reboot, the rest of the system operating modes are not of interest to us now. You can switch between levels with the init command. Only 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 another, non-standard, or even two. These are magic SysRq keys. Linux kernel monitors the pressing of certain keyboard shortcuts, and in response to them takes the desired action. 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 shortcuts hold Alt + SysRq and press the key code. For a normal reboot, the following sequence is recommended: R E I S U B, press the keys in the same sequence at intervals of about a second.

  • R- returns control of the keyboard if the X server was terminated incorrectly;
  • E- the kernel sends the 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, no synchronization, and additional preparations.

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

SysRq can be used without keyboard shortcuts by writing required code operations to file / proc / sysrq-trigger:

echo b> / proc / sysrq-trigger

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

Remote Linux reboot

If you have access to the server via ssh, then you can very easily 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 a 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 entries: