Linux switch command (shutdown, reboot, halt, init)

  
        

Command Introduction

Shutdown, poweroff, reboot, halt, init can be shut down, approximate usage.

/sbin/halt [-n] [-w] [-d] [-f] [-i] [-p] [-h] /sbin/reboot [-n] [-w] [-d] [-f] [-i] /sbin/poweroff [-n] [-w] [-d] [-f] [-i] [-h]

[root@linux ~]$ reboot --h usage: reboot [-n] [-w] [-d] [-f] [-h] [-i] -n: Not synchronized before stopping the system -w: Write only wtmp reboot record And leave -d: Do not write wtmp record -f: Force shutdown or restart -h: Let the hard disk in stand-alone mode -i: Close all network interfaces

Shutdown process

1. Refresh the hard disk Cache: 2. Record the restart event: (/var/run/utmp, /var/log/wtmp) 3. Kill all processes: 4. Finally restart the machine:

Shutdown example

# shutdown -h now # shutdown now # shutdown -h 2:30 'halt' #2点30 minutes shutdown, pay attention to the local time # halt -p # immediately shut down # init 0 # immediately switch the system running level to 0, ie shutdown # shutdown now #Switch to single-player mode (without any options)

Restart example
# shutdown -k now 'reboot' #Warning message, but no real shutdown .# shutdown -t5 -r now #Restart now, but between warning and deletion, delay 5 seconds.# Init 6 # Immediately switch the system run level to 6, ie reboot # shutdown -r +10 'reboot' #10 minutes restart # shutdown -c # cancel the previous shutdown command # shutdown -r now # immediately restart

shutdown Prepare

Linux is no better than Windows. If you can't shut down properly, it may cause file system corruption if you don't have time to write data back to the file. So pay attention before shutting down:

1. Observe the system status
Use the who command to view the online user with the netstat -a command, view the network connection status with the ps aux command, view the background execution program

2. Notify online users #shutdown -k now 'System will reboot in 30 minutes!'

3. Use the correct command # first to find out whether it is shutdown or restart, followed by the parameters

4. Note Data Synchronization #Sync to disk using sync data

Additional Notes

1. View the restart log

# last reboot


2. Remote boot machine

# ssh root@server /sbin/reboot # ssh [email protected] /sbin/shutdown -r now

Copyright © Windows knowledge All Rights Reserved