现在的位置: 首页 > 综合 > 正文

linux下shutdown, halt, reboot的区别

2013年10月04日 ⁄ 综合 ⁄ 共 2813字 ⁄ 字号 评论关闭

原文:http://unix.stackexchange.com/questions/8690/what-is-the-difference-between-halt-and-shutdown-commands

http://askubuntu.com/questions/190202/difference-between-halt-and-shutdown-now

Generally, one uses the
shutdown command
. It allows a time delay and warning message before shutdown or reboot, which is important for system administration of multiuser shell servers; it can provide the users with advance notice of the downtime.

As such, the shutdown command has to be used like this to halt/switch off the computer immediately (on Linux and FreeBSD at least):

shutdown -h now

Or to reboot it with a custom, 30 minute advance warning:

shutdown -r +30 "Planned software upgrades"

After the delay, shutdown tells
init
to change to runlevel 0 (halt) or 6 (reboot). (Note that omitting
-h or -r will cause the system to go into single-user mode (runlevel 1), which kills most system processes but does not actually halt the system; it still allows the administrator to remain logged in as root.)

Once system processes have been killed and filesystems have been unmounted, the system halts/powers off or reboots automatically. This is done using the
halt or
reboot
command
, which syncs changes to disks and then performs the actual halt/power off or reboot.

On Linux, if halt or reboot is run when the system has not already started the shutdown process, it will invoke the
shutdown command automatically rather than directly performing its intended action. However,

on systems such as FreeBSD
, these commands first log the action in
wtmp
and then will immediately perform the halt/reboot themselves, without first killing processes or unmounting filesystems.

halt basically just calls shutdown -h and
reboot runs shutdown -r. Note that if you pass the
-f
(force) option to halt or reboot, shutdown is
not called

halt is not shutdown, they are different commands. The former does not turn the power off, unless
-p option is used

From the manual (man halt): "-p, --poweroff : Instructs the halt command to instead behave as poweroff."

And, in your case, -p was not used in the haltcommand, hence your computer was
not powered off.

Do not confuse this -p with the one from sudo, it's a different parameter for a different command. From
man sudo:

  • -S The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.
  • -p prompt The -p (prompt) option allows you to override the default password prompt and use a custom one.

In your case, prompt is empty (no message displayed for sudo when asking password), and -S makes sudo accept root password vi stdin (so password may be supplied using pipes and redirection from other commands instead of being typed)

halt brings the system down to its lowest state, but leaves it powered on.

shutdown brings the system down to its lowest state, and will turn off power (soft power switch) if it can. Most computers now can do so.

reboot restarts the system. It brings the system down to its lowest state, then starts it up again.

Which to do depends on what you want to do. halt is usually to get to a state where you can perform low level maintenance.
shutdown is to power the system off, and reboot is to reboot it.

其他参考:http://www.linuxforums.org/forum/slackware-linux/63551-halt-vs-shutdown.html---对于该话题的讨论

抱歉!评论已关闭.