Centos restart commands commonly used shutdown and restart commands in Linux include shutdown, halt, reboot, and init, which can be used to shut down and restart, however, the internal working process of each command is different. we will introduce it one by one. 1. the shutdownshutdown command is used to safely shut down the Linux system. Centos restart command
Common shutdown and restart commands in Linux include shutdown, halt, reboot, and init, which can be used for shutdown and restart. However, the internal working process of each command is different, next we will introduce them one by one.
1. shutdown
The shutdown command is used to safely shut down the Linux system. It is very dangerous for some users to disable Linux by directly disconnecting the power supply. Because Linux and Windows run many processes in the background, forced shutdown may lead to data loss in the process, making the system unstable and even damaging hardware devices.
When the shutdown command is executed, the system notifies all logged-on users that the system will be shut down and the login command will be frozen. that is, new users cannot log on to the system. You can use the shutdown command to directly shut down the system, delay the specified time before shutting down the system, and restart the system. If the system is shut down after a specified delay, the user can have time to store the files being processed and to close the opened programs.
Some parameters of the shutdown command are as follows:
[-T] specifies how long the system will be shut down
[-R] restart the system
[-K] does not actually shut down, but sends a warning signal to every logged-on user.
[-H] shut down the system (halt)
The job of the shutdown command is to send a signal to the init Program and require it to switch the Runlevel of the system ). The system running level includes:
Common CentOS interface parameters are as follows:
-T sec: the number of seconds between sending a warning message and deleting the message before notifying init to execute a run-level switch.
-K: The system is not really shut down, but a warning message is sent to each user.
-R: shut down and restart the system.
-H: shut down and stop the system.
-F: fsck is not required to check the disk after the disk is restarted.
-F: force fsck to check the disk after restart
For example:
# Warn all users that the system will restart in 5 minutes
# Shutdown-r + 5 "System will be reboot in 5 minites, Please save your work ."
# Immediately shut down the system
# Shutdown-h now
# Immediately restart the system and force the fsck to check the disk after the restart
# Shutdown-h-F now
0: shut down the system
1: in single-user mode, if the-h or-r parameter is not specified for the shutdown command, the system will switch to this running level by default.
2: Multi-user mode (NFS not supported)
3: Multi-user mode (supporting NFS), which is usually used
5: Multi-user mode (GUI mode)
6. restart the system.
2. halt
Halt is the simplest shutdown command. it actually calls the shutdown-h command. When halt is executed, the application process is killed. after the file system writes, the kernel is stopped.
Some parameters of the halt command are as follows:
[-F] force shutdown or restart without calling shutdown
[-I] disable all network interfaces before shutting down or restarting
[-P] poweroff is called upon shutdown. this option is the default option.
3. reboot
The reboot process is similar to that of halt. its function is to restart and halt is to shut down. Its parameters are similar to those of halt.
4. init
Init is the ancestor of all processes, and its process number is always 1. Init is used to switch the running level of the system. The switchover is completed immediately. The init 0 command is used to immediately switch the system running level to 0, that is, shutdown. the init 6 command is used to switch the system running level to 6, that is, restart.
In the CentOS interface switch issue, many people may be used to entering the character work mode for operations. So how do I switch to the character working mode? Below we will introduce three methods to enter the character work mode:
In the graphic environment, enable the terminal window to enter the character working mode. After the system starts, it directly enters the character working mode. Use remote login (Te lne t or SSH) to enter the character working mode.
Virtual Console
After you directly enter the character working mode when the system starts, the system provides multiple (6 by default) virtual consoles. Each virtual console can be used independently without affecting each other. You can use Alt + F1 ~ Alt + F6 switch between multiple virtual consoles. If you use the startx command to start the graphical environment on the CentOS page, you can use C trl + Alt + F1 ~ C trl + Alt + F6 switch character Virtual Terminal, use C trl + Alt + F7 to switch to the graphic interface.
Local logon and logout
Login: enter the user name (such as root) and password (pwd) on the logon terminal. Log out: you can enter the logout command on the current logon terminal or use the + shortcut key.
Log on to a remote Linux system using ssh in a Linux environment. The ssh command in Linux is the client program of O pe nSSH. To log on to the remote Linux system, make sure that the O pe nSSH server is started on the remote Linux system. Use ssh
The command format for logging on to the remote O pe nSSH server is: $ username on the ssh remote host @ IP address or FQDN of the remote host
Go to the CentOS page and enter
The Linux system runs on a specified running level at any time, and different running-level programs and services are different. the work to be done and the purpose to be achieved are different. Centos sets the running level as shown in the following table, and the system can switch between these running levels to complete different tasks. Running description
0. all processes will be terminated, and the machine will be stopped in an orderly manner. when the machine is shut down, the system will be in this running level.
1. single-user mode. Used for system maintenance. only a few processes run and all services are not started.
2-user mode. Like Level 3, the Network File System (NFS) service is not started.
3 Multi-user mode. Allows multiple users to log on to the system, which is the default startup level of the system.
4 left to the user's custom running level
5-user mode. after the system is started, run X-Window to provide a graphical logon Window.
6. all processes are terminated and the system restarts.
1. if you enter the character logon CentOS page after the system starts, the default running level is 3. if you enter the graphical logon CentOS page after the system starts, the default running level is 5.
2. if you have enabled the CentOS page, you can run the following command to access the CentOS page:
$ Startx &
View and switch at run level
You can use the following command to view the running runlevel of the current system. you can use the following command to switch the running level init [0123456Ss], that is, the init command is followed by a parameter, this parameter is the runtime code to switch to, for example:
Use the init 0 command to switch to the running level 0, that is, shutdown
Use the init 1 command to switch to running Level 1, that is, enter the single-user running mode
Use the init 6 command to switch to running level 6, that is, restart
You can also use the te linit command. in CentOS, the te linit command is the symbolic link of the init command.
Here is an example of using the runle ve l and init commands:
# Display the current running level of the system
# Runlevel
N 3
# The current running level of the system is "3", but the previous running level does not exist (represented by "N)
# Init 2
# After executing the "init 2" command, the system console displays the information about stopping the service.
# Runlevel
3 2
# The current running level of the system is "2", the last running level is "3", and the conversion operation level is successful
You can also use the shutdown and restart command to go to the CentOS page.
When the system is shut down and restarted, the operation level is switched. You can use the init command to shut down and restart the instance. The init command is used to immediately shut down or restart the instance. However, in a multi-user system, if you want to send a shutdown warning to each user to complete their work and log out, you must use shutdown, halt, and re boot
.
In a multi-user environment, the shutdown command is usually used to close and restart the system. The shutdown command can shut down the system in a safer way. all users logging on to the system will be notified that the system will be shut down, and new login operations will be blocked; at the same time, all processes will be notified that the system will shut down, so that some programs, such as vi, will be able to save the files edited by the user in time and exit.