Shutdown commands halt, poweroff, shutdown -h

Common shutdown commands under linux are: shutdown, halt, poweroff, init;

The restart commands are: reboot.

In this section, the script editor will introduce some commonly used shutdown commands and the differences and specific usage of various shutdown commands.

The first part, some commonly used shutdown commands under linux.

Shutdown command:

1. halt to shut down immediately 
2. poweroff to shut down immediately 
3. shutdown -h now to shut down immediately (for root users) 
4. shutdown -h 10 to automatically shut down after 10 minutes reboot

restart command:

1. reboot 2. shutdown -r now restarts immediately (for root users) 3. shutdown -r 10 automatically restarts after 10 minutes (for root users) 4. shutdown -r 20:35 restarts at 20:35 (root users) User) If the restart is set through the shutdown command, you can cancel the restart with the shutdown -c command

Let's take a look at the differences between these specific shutdown commands of linux and their respective usages

1.shutdown safe shutdown command

For the shutdown command, it is a safe command recommended by everyone, and the shutdown or restart is completed by the cooperation of the parameter -h or -r. However, this command can only be used in Linux systems with root privileges.
So, although everyone recommends this command, it is really inconvenient to use: Do you want to use this command? Go get root first.

Shutdown executes a shutdown by sending a signal to init, asking it to change the run level to shut down. Shutdown or restart is actually a run level adjustment, so you can also use init to directly adjust the run level to shut down or restart.
When using this command, the machine shuts down or restarts immediately. It also requires root privileges.

Why is the shutdown command said to safely shut down the system?

In practice, some users will shut down linux by directly cutting off the power supply, which is very dangerous. Because linux is different from windows, there are many processes running in the background, so forced shutdown may cause data loss of the process and make the system in an unstable state. Even in some systems, hardware devices will be damaged. And using the shutdown command before the system shuts down, the system administrator will notify all logged in users that the system will be shut down. And the login command will be frozen, that is, new users can no longer log in. It is possible to shut down directly or delay the shutdown for a certain period of time, and it is also possible to restart. This is determined by all processes (process) will receive the signal sent by the system (signal).

shutdown does its job by sending a signal to the init program, asking it to change the runlevel.
Runlevel 0 is used to halt [halt], runlevel 6 is used to reactivate [reboot] the system, and runlevel 1 is used to put the system into a state where management work can proceed, which is the default.
Assume no -h nor -r arguments to shutdown. Want to know what actions are done during a shutdown (halt) or reboot (reboot)?
You can see information about these runlevels in this file /etc/inittab.

Description of the shutdown parameter:

[-t] Tell init how long to shut down before changing to another runlevel.
[-r] Restart calculator.
[-k] doesn't actually shutdown, just sends a warning signal to every login [login].
[-h] Power off after shutdown [halt].
[-n] Shutdown by itself without init. The use of this option is discouraged, and the consequences of this option are often not always what you expect.
[-c] cancel current process cancels the currently executing shutdown procedure. So of course this option doesn't have a time parameter, but an explanation message can be entered, and this information 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 shutdown [shutdown].

2.halt the simplest shutdown command

When using the halt command to shutdown, the actual call is shutdown -h. When halt is executed, the application process will be killed, and the kernel will be stopped after the file system write operation is completed by executing the sync system call.

halt parameter description:

[-n] Prevent the sync system call, which is used after patching the root partition with fsck to prevent the kernel from overwriting the patched superblock with an older version of the superblock.
[-w] does not really restart or shutdown, just write wtmp [/var/log/wtmp] records.
[-d] Do not write wtmp records [included in option [-n]].
[-f] Force shutdown or reboot without calling shutdown.
[-i] Shut down all network interfaces before shutting down (or rebooting).
[-p] This option is the default option. It is to call poweroff when shutdown.

3.poweroff commonly used shutdown command

For poweroff, it is said on the Internet that it is a link to the halt command, and the basic usage is similar to that of halt.

4.init

Init is the ancestor of all processes, and it is one of the indispensable programs in Linux system operation. Its process number is always 1, so sending the TERM signal to init will kill all user processes, daemons, etc.
shutdown uses this mechanism. init defines 8 runlevels, init 0 is shutdown, init 1 is restart.

5.reboot reboot command

The work process of reboot is almost the same as that of halt. But it is to cause the host to restart, and halt is to shut down. Its parameters are similar to halt.

 

Common shutdown commands under linux are: shutdown, halt, poweroff, init;
restart commands are: reboot.

In this section, the script editor will introduce some commonly used shutdown commands and the differences and specific usage of various shutdown commands.

The first part, some commonly used shutdown commands under linux.

Shutdown command:

1. halt to shut down immediately 
2. poweroff to shut down immediately 
3. shutdown -h now to shut down immediately (for root users) 
4. shutdown -h 10 to automatically shut down after 10 minutes reboot

restart command:

1. reboot 2. shutdown -r now restarts immediately (for root users) 3. shutdown -r 10 automatically restarts after 10 minutes (for root users) 4. shutdown -r 20:35 restarts at 20:35 (root users) User) If the restart is set through the shutdown command, you can cancel the restart with the shutdown -c command

Let's take a look at the differences between these specific shutdown commands of linux and their respective usages

1.shutdown safe shutdown command

For the shutdown command, it is a safe command recommended by everyone, and the shutdown or restart is completed by the cooperation of the parameter -h or -r. However, this command can only be used in Linux systems with root privileges.
So, although everyone recommends this command, it is really inconvenient to use: Do you want to use this command? Go get root first.

Shutdown executes a shutdown by sending a signal to init, asking it to change the run level to shut down. Shutdown or restart is actually a run level adjustment, so you can also use init to directly adjust the run level to shut down or restart.
When using this command, the machine shuts down or restarts immediately. It also requires root privileges.

Why is the shutdown command said to safely shut down the system?

In practice, some users will shut down linux by directly cutting off the power supply, which is very dangerous. Because linux is different from windows, there are many processes running in the background, so forced shutdown may cause data loss of the process and make the system in an unstable state. Even in some systems, hardware devices will be damaged. And using the shutdown command before the system shuts down, the system administrator will notify all logged in users that the system will be shut down. And the login command will be frozen, that is, new users can no longer log in. It is possible to shut down directly or delay the shutdown for a certain period of time, and it is also possible to restart. This is determined by all processes (process) will receive the signal sent by the system (signal).

shutdown does its job by sending a signal to the init program, asking it to change the runlevel.
Runlevel 0 is used to halt [halt], runlevel 6 is used to reactivate [reboot] the system, and runlevel 1 is used to put the system into a state where management work can proceed, which is the default.
Assume no -h nor -r arguments to shutdown. Want to know what actions are done during a shutdown (halt) or reboot (reboot)?
You can see information about these runlevels in this file /etc/inittab.

Description of the shutdown parameter:

[-t] Tell init how long to shut down before changing to another runlevel.
[-r] Restart calculator.
[-k] doesn't actually shutdown, just sends a warning signal to every login [login].
[-h] Power off after shutdown [halt].
[-n] Shutdown by itself without init. The use of this option is discouraged, and the consequences of this option are often not always what you expect.
[-c] cancel current process cancels the currently executing shutdown procedure. So of course this option doesn't have a time parameter, but an explanation message can be entered, and this information 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 shutdown [shutdown].

2.halt the simplest shutdown command

When using the halt command to shutdown, the actual call is shutdown -h. When halt is executed, the application process will be killed, and the kernel will be stopped after the file system write operation is completed by executing the sync system call.

halt parameter description:

[-n] Prevent the sync system call, which is used after patching the root partition with fsck to prevent the kernel from overwriting the patched superblock with an older version of the superblock.
[-w] does not really restart or shutdown, just write wtmp [/var/log/wtmp] records.
[-d] Do not write wtmp records [included in option [-n]].
[-f] Force shutdown or reboot without calling shutdown.
[-i] Shut down all network interfaces before shutting down (or rebooting).
[-p] This option is the default option. It is to call poweroff when shutdown.

3.poweroff commonly used shutdown command

For poweroff, it is said on the Internet that it is a link to the halt command, and the basic usage is similar to that of halt.

4.init

Init is the ancestor of all processes, and it is one of the indispensable programs in Linux system operation. Its process number is always 1, so sending the TERM signal to init will kill all user processes, daemons, etc.
shutdown uses this mechanism. init defines 8 runlevels, init 0 is shutdown, init 1 is restart.

5.reboot reboot command

The work process of reboot is almost the same as that of halt. But it is to cause the host to restart, and halt is to shut down. Its parameters are similar to halt.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324788884&siteId=291194637