Detail summary of linux shutdown command

  • 2020-05-14 05:54:00
  • OfStack

Common shutdown commands under linux are: shutdown, halt, poweroff, init; The restart command is: reboot. This article mainly introduces 1 some commonly used shutdown commands and various shutdown commands between the differences and specific usage.

First, take a look at some of the more common shutdown commands in linux

Shutdown command:

halt shut down immediately 2, poweroff shut down immediately 3, shutdown-h now shut down immediately (for root users) 4, shutdown-h 10 automatically shut down after 10 minutes. If the shutdown is set by shutdown command, the restart can be cancelled by shutdown-c command

Restart command:

reboot 2, shutdown-r now restart immediately (for root users) 3, shutdown-r 10 restart automatically after 10 minutes (for root users) 4, shutdown-r 20:35 restart at 20:35 (for root users

Let's take a look at the differences and USES of linux's specific shutdown commands

1.shutdown safe shutdown command

For the shutdown command, it is recommended as a secure command to complete shutdown or restart with the support of the -h or -r parameters. However, in the linux system, this command can only be used if you have root permissions. So, while this command is recommended, it's really not that convenient to use: want to use this command? Go ahead and get the root permissions. When shutdown performs a shutdown, it sends a signal to init asking it to change its runlevel so that it can shut down. Shutdown or restart is actually a run-level adjustment, so we can also use init to directly adjust the run-level for shutdown or restart. When this command is used, the machine is immediately shut down or restarted. It also requires root permissions.

So why is the shutdown command safe to shut down the system?

In practice, some users will turn off linux by simply cutting off the power supply, which is 10 percent dangerous. Because linux is different from windows in that it has many processes running in the background, forcing a shutdown may result in data loss of the process and leave the system in an unstable state. It can even damage hardware in some systems. Using the shutdown command before the system is shut down, the system administrator notifies all logged users that the system is about to shut down. And the login directive is frozen, meaning that new users can no longer log in. It is possible to shut down the computer or delay it by a certain amount of time. It is also possible to restart the computer. This is determined by the fact that all processes (process) receive a signal from the system (signal).

shutdown performs its job by sending a signal [signal] to the init program asking it to change runlevel. runlevel 0 is used to shut down the system (halt), runlevel 6 to reactivate the system (reboot), and runlevel 1 to put the system into a state where administrative work can be done, by default. Assume that there is no -h and no -r parameter for shutdown. Want to know what was done during the shutdown (halt) or reboot (reboot)? You can see the information about runlevels in this file /etc/inittab.

Description of shutdown parameters:

[-t] before changing to other runlevel, tell init how long to turn off.

[-r] restart the calculator.

[-k] doesn't really shut down, just sends a warning signal to everyone who logs in [login].

[-h] power off after shutdown [halt].

[-n] don't use init, turn it off yourself. Use of this option is discouraged, and the consequences of this option are not always what you expect.

[-c] cancel current process cancels the shutdown program currently being executed. So this option, of course, has no time parameter, but you can enter a message for interpretation, which will be sent to each user.

[-f] ignore fsck when restarting the calculator [reboot].

[-F] force fsck when restarting the calculator [reboot].

[-time] set the time before the shutdown (shutdown).

2.halt's simplest shutdown command

When the halt command is used to power down, shutdown-h is actually called. The application process is killed when halt is executed, and the kernel is stopped when the sync system call file system write is completed.

halt parameter description:

[-n] prevents the sync system call, which is used after the root partition has been patched with fsck, to prevent the kernel from overwriting the patched superblock with the older version of the superblock (superblock).

[-w] is not really a restart or shutdown, just a record of wtmp [/var/log/wtmp].

[-d] does not write wtmp record [included in option [-n]].

[-f] forced shutdown or restart without calling shutdown.

[-i] shut down all network interfaces before shutting down (or restarting).

[-p] this option is the default. That is, poweroff is called when it is turned off.

3.poweroff common shutdown command

For poweroff, the web says it is a link to the halt command, and the basic usage is similar to halt, but I won't say much more about it here.

4.init

init is the ancestor of all processes. It is an indispensable part of the operation of the Linux system. Its process number is always 1, so sending an TERM signal to init will terminate all user processes, daemons, etc. shutdown USES this mechanism. init defines eight runlevels (runlevel), init 0 for shutdown, and init 1 for restart.

5.reboot restart command

reboot works in much the same way as halt1. However, it triggers a host reboot, while halt is a shutdown. Its parameters are similar to halt.


Related articles: