天天看點

linux關機指令詳解

關機指令有三個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 得到以下内容,可以作為對照

shutdown - bring the system down

/sbin/shutdown [-t sec] [-arkhncfF] time [warning-message]

-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.

下一篇: crontab-at

繼續閱讀