linux關機詳解

火星人 @ 2014-03-09 , reply:0


關機命令有三個halt,shutdown,poweroff,以及重啟命令reboot
halt確有其命令,以及man內容.
shutdown也是專門負責關機的命令,並是獨立的程序.
poweroff命令並不存在,但他直接調用的是halt -p的默認命令參數,是link過來的,下面我也提到了
reboot是重啟命令,作用內容可以參考halt的man
......
[root@acnis root]# halt --help
usage: halt [-n] [-w] [-d] [-f] [-i] [-p]
-n: don't sync before halting the system
-w: only write a wtmp reboot record and exit.
-d: don't write a wtmp record.
-f: force halt/reboot, don't call shutdown.
-p: power down the system (if possible, otherwise halt)
參數說明:
[-n] 防止 sync 系統調用,它用在用fsck修補根分區之後,以阻止內核用老版本的超級塊(superblock)覆蓋修補過的超級塊.
[-w] 並不是真正的重啟或關機,只是寫 wtmp(/var/log/wtmp)紀錄.
[-d] 不寫 wtmp 紀錄(已包含在選項 [-n] 中).
[-f] 沒有調用 shutdown 而強制關機或"重啟"(指的是reboot).
[-i] 關機(或重啟)前,關掉所有的網路介面.
[-p] 該選項為預設選項.就是關機時調用 poweroff. (isher喜歡直接用poweroff命令)
[-h] 在系統關閉之前,從系統中正確的移除所有的磁碟驅動器.
說明poweroff命令很多人不知道,這也是在/sbin下面的命令,是一個link,連接到halt -p的命令上.

[root@acnis sbin]# ll |grep pow
lrwxrwxrwx 1 root root 4 2002-01-13 poweroff -> halt

為了說明,MAN一下poweroff
MAN poweroff(halt) 得到以下內容,可以作為對照,對於halt -h
同時包含了halt命令和reboot的解釋,因為poweroff本就是halt的快捷方式而已(windows的話)
NAME
halt, reboot, poweroff - stop the system.


SYNOPSIS
/sbin/halt [-n] [-w] [-d] [-f] [-i] [-p] [-h]
/sbin/reboot [-n] [-w] [-d] [-f] [-i]
/sbin/poweroff [-n] [-w] [-d] [-f] [-i] [-h]
OPTIONS
-n Don't sync before reboot or halt.
-w Don't actually reboot or halt but only write the wtmp record (in
the /var/log/wtmp file).
-d Don't write the wtmp record. The -n flag implies -d.
-f Force halt or reboot, don't call shutdown(8).
-i Shut down all network interfaces just before halt or reboot.
-h Put all harddrives on the system in standby mode just before
halt or poweroff.
-p When halting the system, do a poweroff. This is the default when
halt is called as poweroff.

[root@acnis root]# shutdown --help
shutdown: invalid option -- -
Usage: shutdown [-akrhfnc] [-t secs] time [warning message]
-a: use /etc/shutdown.allow
-k: don't really shutdown, only warn.
-r: reboot after shutdown.
-h: halt after shutdown.
-f: do a 'fast' reboot (skip fsck).
-F: Force fsck on reboot.
-n: do not go through "init" but go down real fast.
-c: cancel a running shutdown.
-t secs: delay between warning and kill signal.
** the "time" argument is mandatory! (try "now") **
參數說明
shutdown 命令可以安全地關閉或重啟Linux系統,它在系統關閉之前給系統上的所有登錄用戶提示一條警告信息.該命令還允許用戶指定一個時間參數,可以是一個精確 的時間,也可以是從現在開始的一個時間段.精確時間的格式是hh:mm,表示小時和分鐘;時間段由“ ”和分鐘數表示.系統執行該命令后,會自動進行數據同步的工作.
該命令的一般格式為: shutdown [選項] [時間] [警告信息] 命令中各選項的含義為:
[-t] seconds : 設定在幾秒鐘之後進行關機程序


[-k] 並不真正關機,而只是發出警告信息給所有用戶.
[-r] 關機后立即重新啟動.
[-h] 關機后不重新啟動.
[-f] 快速關機,重啟動時跳過fsck.
[-F] : 關機時,強迫進行 fsck 動作
[-n] 快速關機,不經過init程序.
[-c] 取消一個已經運行的shutdown.
×需要特別說明的是,該命令只能由超級用戶使用.
time : 設定關機的時間
message : 傳送給所有使用者的警告訊息
MAN shutdown 得到以下內容,可以作為對照
NAME
shutdown - bring the system down
SYNOPSIS
/sbin/shutdown [-t sec] [-arkhncfF] time [warning-message]
OPTIONS
-a Use /etc/shutdown.allow.
-t sec Tell init(8) to wait sec seconds between sending processes the
warning and the kill signal, before changing to another run-
level.
-k Don't really shutdown; only send the warning messages to every-
body.
-r Reboot after shutdown.
-h Halt after shutdown.
-n [DEPRECATED] Don't call init(8) to do the shutdown but do it
ourself. The use of this option is discouraged, and its results
are not always what you'd expect.
-f Skip fsck on reboot.
-F Force fsck on reboot.
-c Cancel an already running shutdown. With this option it is of
course not possible to give the time argument, but you can enter
a explanatory message on the command line that will be sent to
all users.




[火星人 via ] linux關機詳解已經有95次圍觀

http://www.coctec.com/docs/linux/show-post-50590.html