与关机、重新启动相关的命令
* 将数据同步写入硬盘中的命令 sync
* 惯用的关机命令 shutdown
* 重新启动、关机 reboot halt poweroff
sync 强制将内存中的数据写入到硬盘当中。因为linux系统中,数据会缓存在内存当中,所以为了保证数据完整保存在硬盘中,通常会在关机前使用sync命令,强制将内存中的数据写入到缓存中。但是一般情况下,我们使用shutdown ,halt命令时,系统会自动调用 sync 命令,将缓存写入硬盘后再关机。
shutdown 根据目前已启动的服务逐次关闭各项服务后才关机;
halt 可以在不理会系统的情况下,进行硬件关机;
NAME
shutdown - Halt, power-off or reboot the machine
SYNOPSIS
shutdown [OPTIONS...] [TIME] [WALL...]
shutdown 参数 时间字段 通知(wall message 也可以叫大字报)
DESCRIPTION
shutdown may be used to halt, power-off or reboot the machine.
shutdown 用于关闭、重启服务器
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.
第一个参数可以是一个关于时间的字段(通常是 now).通常,后面会跟一个消息,这个消息会在执行命令前被发送给每一个使用者。
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.时间字段 time string 也可以是格式化的时间 (hh:mm),表示在多长时间之后关闭服务器,时间使用24h制。+m 表示从现在开始几分钟之后关闭服务器。'now'表示时间是0,立即触发shutdown.如果没有指明参数,默认在一分钟之后关闭服务器。
Note that to specify a wall message you must specify a time argument, too.
记得指明时间参数的时候也指明(wall message) 标语。
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. 仅仅写wall message,不用关闭、重启服务器。
--no-wall
Do not send wall message before halt, power-off, reboot. 关闭、重启服务器之前不发送wall message
-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". 取消关闭服务器 通常之前执行的关机命令,它的时间参数不是 +0 或 ‘now’
EXIT STATUS
On success, 0 is returned, a non-zero failure code otherwise.
SEE ALSO
systemd(1), systemctl(1), halt(8), wall(1)
systemd 219
halt 关机但不关闭电源
halt -p 关机并且关闭电源
运行等级的切换
* run level 0 : 关机
* run level 3 : 纯文本模式
* run level 5 : 含有图形接口模式
* run level 6 : 重新启动
使用 init 0 也可以关机