One Daily Command - System Shutdown and Restart

Posted by CarbonCopy on Thu, 27 Jun 2019 00:21:07 +0200

System startup: shutdown and restart

halt,poweroff,shutdown,ctrl+alt+del,init 0356,reboot


System hardware and software environment platform:

VMware Workstation Pro 12.5.5 build-5234757

CentOS Linux release 7.3.1611

Kernel version: 3.10.0-514.el7.x86_64

Test time: May 30, 2017

Operating user:root

Note: The usage of the shutdown commands in centos7 and centos6 is different. The unspecified default is centos7.3 environment.


halt shuts down the system but does not turn off the power supply

The halt command detects the runlevel of the system first. If the runlevel is 0 or 6, it closes the system. Otherwise, it calls shutdown to shut down the system.

halt [OPTIONS...]

- p executes poweroff

- f Forces system shutdown without calling init

- w records only in / var/log/wtmp file and does not actually perform shutdown operation

- d is not written to the wtmp file

no-wall does not send messages before shutdown

centos7.3

#halt --help
halt [OPTIONS...]
Halt the system.
     --help      Show this help
     --halt      Halt the machine
  -p --poweroff  Switch off the machine
     --reboot    Reboot the machine
  -f --force     Force immediate halt/power-off/reboot
  -w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
  -d --no-wtmp   Don't write wtmp record
     --no-wall   Don't send wall message before halt/power-off/reboot

centos6.8

#halt --help
Usage: halt [OPTION]...
Halt the system.
Options:
  -n, --no-sync               don't sync before reboot or halt
  -f, --force                 force reboot or halt, don't call shutdown(8)
  -p, --poweroff              switch off the power when called as halt
  -w, --wtmp-only             don't actually reboot or halt, just write wtmp record
  -q, --quiet                 reduce output to errors only
  -v, --verbose               increase output to include informational messages
      --help                  display this help and exit
      --version               output version information and exit
#halt --version
halt (upstart 0.6.5)


Power off

poweroff [OPTIONS...]

The parameters are identical with halt

- h Set all hardware in the system in standby mode before shutting down the operating system


reboot restart

reboot [OPTIONS...]

The parameters are identical with halt


Shut down or restart

shutdown [OPTIONS...] [TIME] [WALL...]

- H shuts down Halt

- P Shutdown Power-off (default)

- r Restart Reboot

- h is equivalent to -P

- k doesn't do anything, just send a warning message

- c Cancel operation

no-wall does not send messages before shutdown or restart

centos7.3

#shutdown --help
shutdown [OPTIONS...] [TIME] [WALL...]
Shut down the system.
     --help      Show this help
  -H --halt      Halt the machine
  -P --poweroff  Power-off the machine
  -r --reboot    Reboot the machine
  -h             Equivalent to --poweroff, overridden by --halt
  -k             Don't halt/power-off/reboot, just send warnings
     --no-wall   Don't send wall message before halt/power-off/reboot
  -c             Cancel a pending shutdown

centos6.8

#shutdown --help
Usage: shutdown [OPTION]... TIME [MESSAGE]
Bring the system down.
Options:
  -r                          reboot after shutdown
  -h                          halt or power off after shutdown
  -H                          halt after shutdown (implies -h)
  -P                          power off after shutdown (implies -h)
  -c                          cancel a running shutdown
  -k                          only send warnings, don't shutdown
  -q, --quiet                 reduce output to errors only
  -v, --verbose               increase output to include informational messages
      --help                  display this help and exit
      --version               output version information and exit

[TIME] Time Format

now

+ m In a few minutes

hh:mm

#Shutdown //centos6 must specify TIME time parameters
shutdown: time expected
Try `shutdown --help' for more information.
#Shutdown-h //centos6 recommends using this command to shut down
Broadcast message from root@c68.com
        (/dev/pts/1) at 13:28 ...
The system is going down for maintenance NOW!

shutdown  //By default, shut down after 1 minute and display prompt message
shutdown now  //now
shutdown +5 "System will shutdown after 5 minutes"  //Shut down after 5 minutes and send a prompt message "sys..."
shutdown -r +5 "system will be reboot"  //Restart in 5 minutes
shutdown -k +1 "haha"  //Prompt message, but not shutdown
shutdown -c  //shutdown -a

#shutdown +16 // / By default, the message to cancel shutdown with shutdown-c will be prompted
Shutdown scheduled for Tue 2017-05-30 13:18:47 CST, use 'shutdown -c' to cancel.
#shutdown +15 // / Note that the shutdown time will not show broadcast messages until 15 minutes
Broadcast message from root@c73.com (Tue 2017-05-30 13:02:50 CST):
The system is going down for power-off at Tue 2017-05-30 13:17:50 CST!
Shutdown scheduled for Tue 2017-05-30 13:17:50 CST, use 'shutdown -c' to cancel.

The ctrlaltdel command is used to set the function of the combination key "Ctrl+Alt+Del", and the format is as follows:

ctrlaltdel hard|soft

hard: When you press the key combination, restart immediately instead of calling sync and other preparations first.

soft: When the key combination is pressed, the SIGINT (interrupt) signal is first sent to the init process. The shutdown operation is handled by the init process.


init process initialization

Init is the parent of all processes. Its primary task is to create processes based on the / etc/inittab file. There are multiple runtime levels

centos7.3

#init --help
init [OPTIONS...] {COMMAND}
Send control commands to the init daemon.
     --help      Show this help
     --no-wall   Don't send wall message before halt/power-off/reboot
Commands:
  0              Power-off the machine
  6              Reboot the machine
  2, 3, 4, 5     Start runlevelX.target unit
  1, s, S        Enter rescue mode
  q, Q           Reload init daemon configuration
  u, U           Reexecute init daemon

Recommended shutdown commands:

halt,poweroff,init 0,shutdown,shutdown +5 "warning system will be shutdown after 5m"

Recommended restart commands:

reboot,ini 6,shutdown -r


This article is a summary of personal learning. If you have any questions, you can send an email to 729815616@qq.com to communicate with each other.


Topics: Vmware Linux