Reboot/halt/shutdown command on CentOS 7

简介:

和Windows相比,Linux提供了多种关机、重启的命令,包括reboot/halt/shutdown等,而如果在服务器上,BMC还会提供ipmitool chassis power reset/ipmitool  chassis power cycle/ipmitool chassis power off等命令,那么面对这么多可行的命令,该如何选择呢?

    

    由于Linux内核和OS版本众多,不同的OS和内核版本上的reboot/halt/shutdown等命令实现方式可能会有差异,这就需要基于具体的OS和内核进行分析。下面基于CentOS 7,分享一下认识reboot/halt/shutdown差异的过程。


1.确定是否都是链接到同一个命令

    通过下面的命令可以看到,在CentOS 7上所有的reboot命令都链接到systemctl:

[root@localhost etc]# which shutdown

/usr/sbin/shutdown

[root@localhost etc]# which poweroff

/usr/sbin/poweroff

[root@localhost etc]# which reboot

/usr/sbin/reboot

[root@localhost etc]# cd /usr/sbin/

[root@localhost sbin]# ls -alrt shutdown

lrwxrwxrwx. 1 root root 16 Apr  5 13:07 shutdown -> ../bin/systemctl

[root@localhost sbin]# ls -alrt poweroff

lrwxrwxrwx. 1 root root 16 Apr  5 13:07 poweroff -> ../bin/systemctl

[root@localhost sbin]# ls -alrt reboot

lrwxrwxrwx. 1 root root 16 Apr  5 13:07 reboot -> ../bin/systemctl

[root@localhost sbin]# which systemctl

/usr/bin/systemctl



2.认识怎样关机保证不造成数据丢失

    除了要求能按照期望实现开关机、重启之外,在服务器尤其是存储服务器的工作环境下,用户对关机和重启能否造成数据丢失也特别关心。为此,弄清楚哪种使用方式不会造成数据丢失很有意义。还是以CentOS为例,根据systemctl的说明,reboot、halt与poweroff一样,只要不带 –force --force后缀,就不会造成数据丢失。下面是关于这些命令的具体说明:


halt

Shut down and halt the system. This is mostly equivalent to start halt.target --irreversible, but also prints a wall message to all users. If combined with --force, shutdown of all running services is skipped, however all processes are killed and all file systems are unmounted or mounted read-only, immediately followed by the system halt. If --force is specified twice, the operation is immediately executed without terminating any processes or unmounting any file systems. This may result in data loss.


poweroff

Shut down and power-off the system. This is mostly equivalent to start poweroff.target --irreversible, but also prints a wall message to all users. If combined with --force, shutdown of all running services is skipped, however all processes are killed and all file systems are unmounted or mounted read-only, immediately followed by the powering off. If --force is specified twice, the operation is immediately executed without terminating any processes or unmounting any file systems. This may result in data loss.


reboot [arg]

Shut down and reboot the system. This is mostly equivalent to start reboot.target --irreversible, but also rints a wall message to all users. If combined with --force, shutdown of all running services is skipped, however all processes are killed and all file systems are unmounted or mounted read-only, immediately followed by the reboot. If --force is specified twice, the operation is immediately executed without terminating any processes or unmounting any file systems. This may result in data loss.


Shutdown

    如果后面什么参数都不加,效果和shutdown -P +1相同,即先调用wall向所有登录的用户发出即将关机的信息,然后组织新的用户登录,接着等待60s,最后执行poweroff。因此,

区别于halt/poweroff,shutdown更安全,在不带任何参数的情况下,shutdown本质是delayed shutdown,当前我们的CentOS上默认是延迟60s后关机,具体请参考下面的命令和日志文件:

[root@localhost ~]# cat /var/log/messages | tail -n 2

Apr 28 22:50:30 localhost systemd: Started Session 195 of user root.

Apr 28 22:50:30 localhost systemd-logind: New session 195 of user root.

[root@localhost ~]# date

Thu Apr 28 22:51:25 CST 2016

[root@localhost ~]# shutdown -k

Shutdown scheduled for Thu 2016-04-28 22:52:30 CST, use 'shutdown -c' to cancel.

[root@localhost ~]#

Broadcast message from root@localhost.localdomain (Thu 2016-04-28 22:51:30 CST):


The system is going down for power-off at Thu 2016-04-28 22:52:30 CST!



[root@localhost ~]# cat /var/log/messages | tail -n 4

Apr 28 22:51:30 localhost systemd: Starting Delayed Shutdown Service...

Apr 28 22:51:30 localhost systemd: Started Delayed Shutdown Service.

Apr 28 22:51:30 localhost systemd-shutdownd: Shutting down at Thu 2016-04-28 22:52:30 CST (poweroff)...

Apr 28 22:51:30 localhost systemd-shutdownd: Creating /run/nologin, blocking further logins...


关于shutdown和poweroff/halt/reboot的关系可参考下面的说明:

SYNOPSIS

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


DESCRIPTION

shutdown may be used to halt, power-off or reboot the machine.


The first argument may be a time string (which is usually "now"). Optionally, this may be followed by a wall

message to be sent to all logged-in users before going down.


The time string may either be in the format "hh:mm" for hour/minutes specifying the time to execute the

shutdown at, specified in 24h clock format. Alternatively it may be in the syntax "+m" referring to the

specified number of minutes m from now.  "now" is an alias for "+0", i.e. for triggering an immediate

shutdown. If no time argument is specified, "+1" is implied.


Note that to specify a wall message you must specify a time argument, too.


If the time argument is used, 5 minutes before the system goes down the /run/nologin file is created to ensure

that further logins shall not be allowed.


OPTIONS

The following options are understood:


--help

Print a short help text and exit.


-H, --halt

Halt the machine.


-P, --poweroff

Power-off the machine (the default).


-r, --reboot

Reboot the machine.


-h

Equivalent to --poweroff, unless --halt is specified.


-k

Do not halt, power-off, reboot, just write wall message.


--no-wall

Do not send wall message before halt, power-off, reboot.


-c

Cancel a pending shutdown. This may be used cancel the effect of an invocation of shutdown with a time

argument that is not "+0" or "now".


3.利用IPMI命令开关机

    如果机器支持BMC,可以通过BMC使用ipmitool去开关机。这种情况下,BMC直接关掉给host系统的DC电源,如果是chassis power reset/chassis power cycle还会间隔一会重新上电,因此在host系统上运行的应用程序和IO数据都来不及killed掉并同步到硬盘,这就会造成数据丢失。当是它的好处是:快捷,并且可以基于BMC Lan 接口去远程开关、重启机器。

这些命令包括:

ipmitool chassis power off #通过BMC关必DC

ipmitool chassis power on # 通过BMC给DC上电

ipmitool chassis power cycle # 先把DC掉店,间隔约1s后给DC上电

ipmitool chassis power reset # 先把DC掉店,然后给DC上电



















本文转自存储之厨51CTO博客,原文链接:http://blog.51cto.com/xiamachao/1769160 ,如需转载请自行联系原作者


相关文章
|
6月前
49Linux - 系统管理(关机重启:reboot、shutdown、init)
49Linux - 系统管理(关机重启:reboot、shutdown、init)
21 0
|
Shell Linux
Centos7:“Entering emergency mode. Exit the shell to continue”错误解决方法
想过很多朋友有遇到这种情况,就是正在远程使用centos7系统时,一旦让远程虚拟机或服务器断电或强制关机,那么再次重启时就会出现“Entering emergency mode. Exit the shell to continue.”的错误。
9954 0
Centos7:“Entering emergency mode. Exit the shell to continue”错误解决方法
|
Linux 开发工具 数据安全/隐私保护
CentOS7开机提示welcome to emergency mode!after logging in...
CentOS7.3昨天用的还好好的的,但是今天开机提示如下(如图提示): welcome to emergency mode!after logging in ,type “journalctl -xb” to view system logs,“systemctl reboot” to reboot ,“systemctl default” to try again to boot into default mode。
4546 0
|
10月前
|
搜索推荐 Unix Linux
init x, halt, shutdown, poweroff, reboot等之间的区别和联系
init x, halt, shutdown, poweroff, reboot等之间的区别和联系
141 0
|
10月前
|
安全 Linux
在企业里linux你用什么关机?shudown?halt?poweroff?init 0? 你是否不知道他们的区别,而娘下大错?
在企业里linux你用什么关机?shudown?halt?poweroff?init 0? 你是否不知道他们的区别,而娘下大错?
223 0
|
Shell Linux vr&ar
Linux Command echo
Linux Command echo
Linux Command echo
RHEL6.6 start_udev报错处理
RHEL6.6 start_udev报错处理
149 0
|
安全 缓存
centos6.5下关于shutdown -r 和reboot
版权声明:转载请注明出处:http://blog.csdn.net/dajitui2024 https://blog.csdn.net/dajitui2024/article/details/79396698 reboot过程会把系统的缓存写到硬盘,先发送SIGTERM再发送SIGKILL;shutdown过程友好地通知线上用户,然后完好地保存。
1292 0
|
Ubuntu
ubuntu Emergency Mode
1 sudo fsck -y /dev/sda# 1 e2fsck -f -y -v -C 0 /dev/sda#
1156 0
|
Shell Linux
CentOS7下-bash: nano: command not found
由于安装的是纯净版系统,运行nano命令是提示没有找到该命令,以下是解决方法,用root权限的用户运行以下命令安装nano: yum install nano 遇到询问时一路点y即可。 安装好后运行:nano a.txt,如果该文件不存在就会创建一个。
3735 0

热门文章

最新文章