一天一命令-系统关机和重启
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一天一命令-系统关机和重启相关的知识,希望对你有一定的参考价值。
系统启动:关机和重启
halt,poweroff,shutdown,ctrl+alt+del,init 0356,reboot
系统软硬件环境平台:
VMware Workstation Pro 12.5.5 build-5234757
CentOS Linux release 7.3.1611
内核版本:3.10.0-514.el7.x86_64
测试时间:2017年5月30日
操作用户:root
注意:centos7和centos6部分关机命令用法不同,未说明的默认为centos7.3环境。
halt关闭系统但不关闭电源
halt命令会先检测系统的runlevel,若runlevel为0或6,则关闭系统,否则即调用shutdown来关闭系统。
halt [OPTIONS...]
-p 执行poweroff
-f 强制关闭系统,不调用init
-w 只在/var/log/wtmp文件中记录而不实际执行关机操作
-d 不写入wtmp文件中
--no-wall 关机前不发送消息
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)
poweroff关机
poweroff [OPTIONS...]
参数同halt
-h 关闭操作系统之前将系统中所有的硬件设置为备用模式
reboot重启
reboot [OPTIONS...]
参数同halt
shutdown关机或重启
shutdown [OPTIONS...] [TIME] [WALL...]
-H 关闭系统Halt
-P 关机Power-off(默认)
-r 重启Reboot
-h 等同于-P
-k 不进行任何操作,只是发送警告消息
-c 取消操作
--no-wall 关机或重启前不发送消息
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]时间格式
now 立刻
+m 几分钟之后
hh:mm 具体时间
#shutdown //centos6必须指定TIME时间参数 shutdown: time expected Try `shutdown --help‘ for more information. #shutdown -h now //centos6推荐使用此命令来关机 Broadcast message from [email protected] (/dev/pts/1) at 13:28 ... The system is going down for maintenance NOW! shutdown //默认1分钟后关机,并显示提示消息 shutdown now //立即关机 shutdown +5 "System will shutdown after 5 minutes" //5分钟后关机,并发送提示信息"sys..." shutdown -r +5 "system will be reboot" //5分钟之后重启 shutdown -k +1 "haha" //提示消息,但不会关机 shutdown -c //取消关机 #shutdown +16 //默认会提示用shutdown -c取消关机的消息 Shutdown scheduled for Tue 2017-05-30 13:18:47 CST, use ‘shutdown -c‘ to cancel. #shutdown +15 //注意关机时间在15分钟之内的才会显示广播消息 Broadcast message from [email protected] (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.
ctrlaltdel命令用来设置组合键“Ctrl+Alt+Del”的功能,格式设置如下:
ctrlaltdel hard|soft
hard:当按下组合键时,立即重启,而不是先调用sync和其他的准备操作。
soft:当按下组合键时,首先向init进程发送SIGINT(interrupt)信号。由init进程处理关机操作。
init进程初始化
Init是所有进程的父进程。它的首要任务是根据/etc/inittab文件创建进程。有多个运行级别
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
推荐使用的关机命令:
halt,poweroff,init 0,shutdown,shutdown +5 "warning system will be shutdown after 5m"
推荐使用的重启命令:
reboot,ini 6,shutdown -r
此文章为个人学习总结,如有任何问题,可发送邮件至[email protected],互相交流。
本文出自 “rackie” 博客,请务必保留此出处http://rackie386.blog.51cto.com/11279229/1930686
以上是关于一天一命令-系统关机和重启的主要内容,如果未能解决你的问题,请参考以下文章