How to use

  
in different situations in Linux system

When performing Linux system operation, if there is a situation such as hardware replacement, system configuration change and crash, you need to restart the computer, and restart the system in different situations. The difference is also that the commands used are different. The following small series will introduce you to the restart method of different situations under Linux.

different from the desktop, as a server, we have less of a Linux system to restart the system, but in the following situations arise, we will restart the machine:

replacing hardware < Br>

Change system configuration

System is dead, need to restart recovery

Shut down and restart system mode

Booting system can only use one method in essence, The difference is that there are several ways to shut down or reboot the system:

Power off (power off)

Use the shutdown command

Use the halt, poweroff or reboot command
>

Using telinit to change the init runlevel

Turning off the power

It is not a good habit to power off the machine directly for two reasons:

May cause hardware damage

Some data may still be in memory and not written back to disk. At this time, power loss may result in data loss or file system damage;

Therefore, try to use other methods to shut down or reboot. system.

shutdown command

Use shutdown to suspend or reboot the system, use the -h option to suspend the system, and use the same function as the halt command; use -r The option indicates to reboot the system and has the same effect as the reboot command.

After executing the shutdown command, the system will send a suspend or restart message to all login users.

Sending a suspend message after executing shutdown –h now:

The code is as follows:

[sql]

# shutdown -h now]

Broadcast message from root (tty1) (Thu May 3 10:58:22 2012):

The system is going down for system halt NOW!

INIT: Switching to runlevel: 0

INIT: Sending processes the TERM signal

Sending a restart message after executing shutdown –r now:

Code As follows:

[sql]

# shutdown -r now

Broadcast message from root (tty1) (Thu May 3 11:18:22 2012):

The system is going down for system reboot NOW!

INIT: Switching to runlevel: 6

INIT: Sending processes the TERM signal

After performing shutdown, other users can no longer log in to the system, and we can specify the system to hang Or the time and description of the restart, the following two cases:

1:00 in the morning to stop maintenance:

The code is as follows:

[sql]

shutdown –h 1:00 “going down for scheduled maintenance. Expected downtime is 1 hour.”

Specify the shutdown time after 15 minutes of shutdown:

The code is as follows:

[sql] shutdown –h +15 <quo;going down for emergency check.”

halt and reboot commands

halt records shutdown, terminates unnecessary processes, executes sync system Call, wait for the file system write operation to complete, then stop the kernel, the poweroff command is equivalent to halt.

From the above <;shutdown –h” and “shutdown –r” execution output, you can execute halt Enter run level 0 I.e., the reboot run level 6, the log file /var /log /messages logged in the appropriate log.

System restart log:

The code is as follows:

[sql] May 3 11:45:25 slot14 shutdown[11119]: shutting down for system reboot

May 3 11:45:25 slot14 init: Switching to runlevel: 6

May 3 11:45:25 slot14 user_cmd: 2012-05-03 11:45:25 shutdown -r now by root from [root tty1 May 3 11:44]

System hangs the log:

The code is as follows:

[sql] May 3 10:50:22 slot14 shutdown[11561] : shutting down for system halt

May 3 10:50:22 slot14 init: Switching to runlevel: 0

May 3 10:50:22 slot14 user_cmd: 2012-05-03 10: 50:22 shutdown -h now by root from [root tty1 May 3 10:48]

By looking at the /var/log/messages log record, you can determine whether the machine is restarting unintentionally or manually.

telinit Command

Executing the telinit command can direct init to the specified run level, such as rebooting the system:

The code is as follows:

[sql]

#telinit 6

When using telinit, you won't get a friendly warning message like running shutdown, less of a suspend and restart command, but a server that modifies the /etc/inittab file. Restarting the system is a relatively large move. When an operating system related failure occurs, we should first consider collecting log information and then restarting the system if necessary.

The above is the introduction of different restart methods for different situations under Linux. There are many kinds of restart commands. You need to apply the most appropriate commands to restart the machine to prevent machine errors.

Copyright © Windows knowledge All Rights Reserved