第二章 Linux 的啟動與關閉
壹. Linux 的版本
Linux Distribution 版本就是看你所使用的 Distribution 是哪一家的, 他們會有固定的版 本數字, 例如: RedHat 有 6.2, 7.2, 7.3等版本數字. 而這些 Distribution 都會包含 Linux kernel, 這時候 Linux kernel 版本的數字, 則是有一定規則可尋. 下面圖表說明 kernel 版本的數字所代表的意思.
kernel 2.2.12 |
kernel 2.2.14 |
kernel 2.2.16 |
kernel 2.4.2 |
kernel 2.4.7 |
kernel 2.4.18 |
RedHat 6.1 |
RedHat 6.2 |
RedHat 7.0 |
RedHat 7.1 |
RedHat 7.2 |
RedHat 7.3 |
SuSE 7.3(2.4.10) |
SuSE 8.0 |
||||
Mandrake 8.2 |
貳. RedHat Linux 安裝
一. 安裝前需知
本文將簡單介紹 Redhat Linux 安裝的過程。在開始安裝之前, 你需要先瞭解你的電腦的一些參數。通常比較需要注意的是:
1. 安裝硬體需求
80486以上(ISA 、EISA、VESA Local Bus or PCI均可)
RAM:至少16M (建議至少32M以上for X-Window)
Floppy:3.5" 1.44M Floppy or 5.25" 1.2M Foopy x1
磁碟空間:至少80 Mbyte(System Basic + Application + Network)
3. VGA 卡的規格
4. 螢幕的型號5. SCSI 卡的型號 (如果有裝 SCSI 卡)
6. 機器上網路之後所使用的 IP,Net Mask,Gateway,DNS (網路管理員詢問)。一般來說 Fedora可以自動偵測到電腦的 VGA,網路卡等硬體的組態。但為使安裝過程順利,請先將硬體相關文件準備在手邊。
若要了解有哪些硬體週邊能夠正確在 Linux 上執行, 請參考網址
Fedora hardware compatible list: https://www.redhat.com/mailman/listinfo/fedora-list
二. 軟體及說明文件取得
1. 由網路中取得
Linux的軟體及各式各樣說明文件,均可見於國內各大ftp站,只要你可上線,均可免費取得。
2. 由書本中取得光碟
市面上很多Linux的書,均附有Linux軟體的光碟,其中內容豐富,且安裝快速方便,是一個取得Linux軟體的捷徑。只是要留意書的出版日期。由於Linux版本更新太快,出版日期太過久遠的書,所附光碟通常版本均較舊,使用或學習起來可能就有點落伍
!
3. 複製
當然如果你借得到光碟,複製一下也是一個不錯的辦法;版權的問題就不用擔心了,Linux軟體是免費的!
可以自光碟機直接安裝或從ftp server下載安裝。 若自光碟機安裝則不用製作安裝磁片,直接由光碟機開機即可。
1. 製作安裝磁片
類似MS Windows, Linux中也有製作安裝磁片的功能。
製作完畢請在磁碟片上貼上Boot Disk標籤,以備系統搶救或安裝時使用。
2. 開始安裝
下表為常見的步驟 :
a.使用boot磁片開機後出現第一個畫面:按下Enter選擇安裝新系統。 b.使用的語言:可選擇中文或英文。 c.使用的鍵盤的種類:請選擇預設的US。 d.選擇的安裝方式:我們選擇CD-ROM或FTP安裝。 e.安裝新系統或是升級舊系統:在此我們選擇安裝新系統。 f.安裝的類別(Installation Class):分成數種類型,分別為Workstation、Server、Custom及Update System。 建議選擇Custom,以便系統能有較大的彈性(注意,有些選項[如:Workstation,Server]的預設值是將整棵硬碟全部 給 Linux 使用,若不小心處理可能會造成原有硬碟資料損毀)。 g.選擇系統的SCSI卡:請選一個型號跟你系統所裝的SCSI卡最接近的項目。3. 網路設定
首先我們要先讓系統抓到你的網路卡。通常系統會自動抓到網路卡。如果沒有,系統會出現選單讓你選一個跟你網路卡型號最接近的驅動程式,甚至還會問你網路卡的 IO port, IRQ 等。這時你就需要查閱你購買網路卡時所附的文件。 (當然也有可能你的網路卡並未被支援)
接下來系統會問你一些網路的資訊,如 IP address, Net Mask 等。你應該在安裝前就要查明。
一般 網路參數設定如下:
* Hostname : linuxxx
(xx代表你的組別)
* Domain Name : im.cyut.edu.tw
* Lookback Only ? --> 請選擇"NO"(這代表電腦可以連接網路)
* IP : 163.17.xx.xx
(xx請務必依規則訂定IP address,以免IP address 相衝突造成網路無法運作)* Gateway : 163.17.xx.254
* Netmask : 255.255.255.0
* Use a name server ? --> 請回答"YES"(代表我們要設定Domain Name Server)
* Name Server : 163.17.1.1
--> Network Setup Completed !!!接下來系統會問安裝資料的來源,如果選的是 FTP 安裝,所以你將會被要求輸入 FTP 站的位址以及目錄。
4. 分割硬碟
我們將先說明什麼是硬碟分割,以及說明 Linux 的檔案系統與硬碟分割的關係之後,才說明如何真正的做硬碟分割,最後才將硬碟分割真正的掛 (mount) 到檔案系統上。
4.1 什麼是硬碟分割
一個實體硬碟可以切成若干份,每一份做為系統軟體在管理上的一個單位,稱為一個分割 (partition)。 一個硬碟可以切成四份,稱為四個主要分割 (primary partition)。有時四份分割並不敷使用,我們可以將其中一份主要分割替換成一份延伸分割 (extended partition)。在一份延伸分割中,可以再切成若干份邏輯分割 (Logical Partition) 。而這每一份延伸分割,對於 Linux 來說其作用與任何一份主要分割一樣。這樣子通常就足以滿足我們的需求。
4.2 Linux 的檔案系統與硬蝶分割
Linux 並不像 Dos 或是 Windows95/98 那樣有 C:, D: 等。而是使用一個分割作為根目錄,先在這個目錄上建立檔案系統,然後在這個分割中建立子目錄,然後將其它的硬碟分割上的檔案系統掛在 (mount) 根目錄中的子目錄上。
4.2.1 Linux下的硬碟代號
在UNIX之下,所有硬體設備均以檔案的形態存在,一般而言Linux下的硬碟及分割區相對應的檔案名稱如下:/dev/hda代表IDE 1排線上,jumper設定為master的硬碟(or CDROM)
/dev/hdb代表IDE 1排線上,jumper設定為slave的硬碟(or CDROM)
/dev/hdc代表IDE 2排線上,jumper設定為master的硬碟(or CDROM)
/dev/hdd代表IDE 2排線上,jumper設定為slave的硬碟(or CDROM)
/dev/hda1 代表第一個IDE排線的master硬碟之主要分割區1
/dev/hda2 代表第一個IDE排線的master硬碟之主要分割區2
/dev/hda5 代表第一顆IDE硬碟邏輯分割區1
/dev/hda6 代表第一顆IDE硬碟邏輯分割區2
...其餘/dev/hdb、/dev/hdc、/dev/hdd類推/dev/fd0 代表第一個軟式磁碟槽(A:)
/dev/fd1 代表第二個軟式磁碟槽(B:)如果在前面系統有經過 SCSI 卡抓到 SCSI 硬碟,SCSI 硬碟的代號分別會依序出現在 /dev/sda, /dev/sdb 等等。
在 Linux 中,每個硬碟中的四個主要硬碟分割分別使用 1 到 4 的編號,而邏輯分割則使用編號 5 以後。例如:
- 第一個 IDE 硬碟的第一個硬碟分割的代號是 /dev/hda1
- 第二個 SCSI 硬碟上的第三個硬碟分割的代號是 /dev/sdb3。
- 第一個 IDE 硬碟的第一個邏輯分割是 /dev/hda5
切割硬碟磁區前,我們必須了解PC中硬碟or光碟實際連接方式,才能正確切割出我們想要切割的磁區,也才不致因『誤切』,而損毀原本存在這台PC上的系統。
需注意的是,在建立主要分割時,程式會問你所要建立的分割的代號。也就是說,你可以先建立編號 2 的主要硬碟分割,再建立編號 1 的主要硬碟分割。但在邏輯分割中,編號則會變動。第一個建立的邏輯分割的編號一定是編號 5 的分割;若你建立了編號 5 和編號 6 兩個邏輯分割之後,刪除編號 5 的邏輯分割 , 原先編號 6 的分割會變成編號 5 的硬碟分割。
4.2.2 置換空間(Swap Space)
作業系統如 Linux, Windows XP 等,通常都會利用硬碟的空間,來當做記憶體空間不足時,暫時將不用的資料存到硬碟去。Linux 需要利用 一個硬碟分割來當做暫存空間,稱為 SWAP space。 Linux 也可以用檔案當做 SWAP 空間,但是這樣做效率比較差,通常都特別獨立開一個硬碟分割做為 SWAP space。
置換空間是系統建立的虛擬記憶體(Virtual Memory),swap space 和 RAM的大小決定了你這個系統所能執行的程式大小及數量。實際上的swap space應給多少,端視系統用量及程式性質而定。一 般設定成與實際的RAM一樣大,例如你的RAM大小是512MB,則建議設定的swap partition是512MB。
4.3 動手做硬碟分割
安裝至此,螢幕畫面上會要你選擇處理硬碟分割的方式,分別是選單式與命令式 ( fdisk)。如果你是專家,為了比較精確的控制,可選用命令式的 fdisk。
進入 fdisk 後, 你可以輸入 m 來查看程式提供的指令. 通常比較常用的指令有:
- p (print) 可列出硬碟分割現況
- n (new) 可建立新的硬碟分割
- d (delete) 可以刪除硬碟分割
- t (type) 可以設定硬碟分割的型別
- a (active) 可以設定硬碟是否可開機的屬性
- w(write) 將設定好的硬碟分割寫入硬碟並離開 fdisk
- q (quit) 放棄設定的硬碟分割並離開 fdisk
4.4 建立分割區的注意事項
1. Linux至少必須要有兩個partitions, 一個是root partition,將它掛在根目錄 " / " 下面; 另一個則是swap space。
2. 如果根目錄的硬碟分割同時也扮演了開機的功能,必須將該分割設定為可開機 (active),在 fdisk 中可以用指定 "a" 來達成。
3. 通常建議開一個約 4GB 的空間給根目錄 ( / ),用於安裝系統公用程式以及其他的軟體,其他的空間是需要開成使用者空間 (/home) 。
4. 分割完成之後,系統會讓你選擇要將硬碟分割掛(mount)在那裡,也就是設定 mount point。
如果你還切了一個分割給使用者空間, 建議掛在 "/home" 下面。
5. 如果機器同時要安裝 Linux 及 Windows XP 的話, 則建議先安裝 Windows XP 完, 再安裝 Linux。
6. You can have up to 63 partitions on an IDE hard disk. A SCSI hard disk can have up to 15 partitions. You won't need nearly that many partitions.
7. Multiple partitions within Linux offer the following advantages:
Protection from attacks — Denial-of-service attacks sometimes take action that tries to fill up your hard disk. If public areas, such as /var, are on separate partitions, a successful attack can fill up a partition without shutting down the whole computer.
Protection from corrupted file systems — If you have only one file system (/), corruption of that file system can cause the whole Red Hat Linux system to be damaged. Corruption of a smaller partition can be easier to correct and can often allow the computer to stay in service while the corruption is fixed.
8. Here are some directories that you may want to consider making into separate file system partitions.
/boot — Sometimes the BIOS in older PCs can access only the first 1024 cylinders of your hard disk. To make sure that the information in your /boot directory is accessible to the BIOS, create a separate disk partition (of only a few MB) for /boot and make sure that it exists below cylinder 1024. Then, the rest of your Linux system can exist outside of that 1024-cylinder boundary if you like. Even with several boot images, there is no need for /boot to be larger than 64MB. For newer hard disks, you can sometimes avoid this problem by selecting "linear mode" during installation. Then the boot partition can be anywhere on the disk.
/usr — This directory structure contains most of the applications and utilities available to Red Hat Linux users. Having /usr on a separate partition lets you mount that file system as read-only after the operating system has been installed. This prevents attackers from replacing or removing important system applications with their own versions that may cause security problems. A separate /usr partition is also useful if you have diskless workstations on your local network. Using NFS, you can share /usr over the network with those workstations.
/var — Your FTP (/var/ftp) and Web server (/var/www) directories are stored under /var. Having a separate /var partition can prevent an attack on those facilities from corrupting or filling up your entire hard disk.
/home — Because your user account directories are located in this directory, having a separate /home account can prevent an indiscriminate user from filling up the entire hard disk.
/tmp — Protecting /tmp from the rest of the hard disk by placing it on a separate partition can ensure that applications that need to write to temporary files in /tmp are able to complete their processing, even if the rest of the disk fills up.
5. Firewall 功能
在此選項分成
Security Level : ( ) High, ( ) Midium, ( ) No Firewall
Security Level 存在一些副作用,例如不能 telnet, ftp 自己的機器。因此測試練習時, 請選擇 No Firewall。
6. 指定相關資源及其他
輸入完畢後,如果成功,接下來系統會問你要裝的軟體。請選擇你所需要的軟體。
如果你不知道那些軟體對你是不是有用,你的硬碟空間又相當的充足,你可以選擇最下面的選項 Everything,這個選項會安裝所有的軟體及文件 ,但會花很久的時間。
在你選擇開始安裝之後,而你又不是選擇 Everything 時,系統可能會提示你有些程式你必須安裝。這是因為在 Linux 中的軟體之間是有依存關係的。也就是說,當你可能選擇了安裝 A 軟體,但是 A 軟體執行時會用到 B 軟體的程式,這時系統就會要你也安裝 B 軟體。
之後便是等待系統安裝軟體,根據你安裝的內容 ,網路的速度等因素,約須數十分鐘不等。裝完之後就只剩下一些最後的設定了。
6.1.選擇滑鼠:請選擇與您所使用最為相近的滑鼠型號,通常可以選MS Mouse並打開Emulate 3 Buttons。 若是使用具有滾輪功能的滑鼠, 請設定 wheel mouse 即可。 6.2.設定 X-Window : 你必須成功設定好滑鼠後才能設 X-Window。 在設定過程中,程式會要求你選擇你的螢幕規格。請不要選擇超過你螢幕所能承受的規格, 否則根據 Redhat 文件說明,你可能會因而對你的螢幕造成損害。 6.3.重新設定網路:通常選 Keep this setup。若安裝時與安裝後所使用之網路不同時,請選擇其他兩個選項。6.4.設定時間:TIMEZONE 請選 ROC。(todo:local time) 6.5.設定開機時的服務:選擇您所需要的背景服務程式。如果不清楚這些程式的作用,建議保留的服務程式有atd, crond, gpm inet, kerneld, keytable, network, protmap, random,sendmail, syslog。 6.6.設定印表機:若不知如何設定,請先略過。 6.7.設定系統管理者(root)密碼:請輸入一英文字典上查不到的文字,其中包含數字或特殊符號。 6.8.建立一張開機磁片:可以在緊急時作為系統維護開機之用。例如:別的程式不小心把GRUB蓋掉時使用。通常這樣子你就安裝好一個可以從硬碟開機的 Linux 系統。
7. 重新開機後的測試
(1). 網路測試
瀏覽一下網頁, 例如 www.cyut.edu.tw
ping www.cyut.edu.tw
(2). 其他系統功能測試
試試圖形桌面的各項功能
8. Using GRUB boot loaders
With multiple operating systems installed and several partitions set up, how does your computer know which operating system to start? To select and manage which partition is booted and how it is booted, you need a boot loader. The boot loader that is installed by default with Red Hat Linux is called the GRand Unified Boot loader (GRUB).
8.1 the features of GRUB
GRUB is a GNU software package (www.gnu.org/software/grub). GRUB offers the following features:
Support for multiple executable formats.
Support for Multiboot operating systems (such as Red Hat Linux, FreeBSD, NetBSD, OpenBSD, and other Linux systems).
Support for non-Multiboot operating systems (such as Windows 95, Windows 98, Windows NT, Windows ME, Windows XP and OS/2) via a chain-loading function. Chain-loading is the act of loading another boot loader (presumably one that is specific to the proprietary operating system) from GRUB to start the selected operating system.
Support for multiple filesystem types.
Support for automatic decompression of boot images.
Support for downloading boot images from a network.
For more information on how GRUB works, type man grub or info grub. The info command contains more details about GRUB.
8.2 Booting with GRUB
Simply restart your computer. When you see the GRUB boot screen, do one of the following:
Default: If you do nothing, the default operating system will boot automatically after a few seconds.
Select an operating system: Use the up and down arrow keys to select any of the operating systems shown on the screen. Then press Enter to boot that operating system.
Edit the boot process: If you want to change any of the options used during the boot process, use the arrow keys to select the operating system you want and type the letter e to select it.
If you want to change your boot options so that they take effect every time you boot your computer, edit the /boot/grub/grub.conf file.
參. Linux的開機與關機 - Booting & Shutdow
1. 開機
1.1 開機時系統做了些什麼?
開機時,系統會將相關硬體驅動程式及系統之設定與背景程式建立,
並提供使用者操作介面。
1.2 Linux開機方式
按下電源,有可能是由軟碟、硬碟或者是隨身碟啟動系統,如果有多重作業系統,直接選擇開啟 Linux。
2. 關機
2.1 關機時系統做了些什麼?
Linux是一個多人多工環境,作業系統中有許多分屬不同user、功能各異的程式(process)在執行著﹔關機時系統必須通知所有線上使用者、停止其他user進入系統、update儲存空間資料、結束所有正在執行的程序,並將系統帶到一個管理者所指定的狀態(reboot、halt、single
user)。對於一個多人多工的系統,正常的關機程序是一個相當重要的事。
2.2 關機指令
(1). /sbin/shutdown [-t sec] [-rkhncf] time [warning-message]
-t sec : shutdown設定時間到後,再等sec秒後開始關閉機器。
-r :關機後重新開機(reboot)。
-k :Just sending warning message to all users,not really shutdown 。
-h :shutdown後halt機器。
-c : shutdown設定時間到之前,取消shutdown動作。
-f :a fast reboot。
time :time分鐘後shutdown 機器。
warning-message :送給所有online user的關機警告訊息,通知使用者採取必要程序後,logout系統。
Example 1: /sbin/shutdown -r 10 "系統十分鐘後關機"
設定系統10分鐘後自動關機、將警告訊息"系統十分鐘後關機"送給所有線上使用者,並於系統關機後,自動重新啟動。
Example 2: sync;sync;sync;/sbin/shutdown -h now
對系統進行三次同步動作後,立即關機,關機後並自動halt 機器。
建議:系統關機或重開之前,最好手動進行RAM與硬碟資料的同步(With Command 『sync』),以確保系統資料的安全。
Example 3: /sbin/shutdown -h 10
十分鐘內再輸入指令 /sbin/shutdown -c "Shutdown Canceled"
設定系統10分鐘後自動關機後,取消關機設定,並告訴user關機已取消。
Example 4: halt
相當於shutdown -h now
一些可以找到 Linux 安裝或說明文件的網址.
RedHat 首頁:
http://www.redhat.com/
RedHat Official Documents:
http://www.redhat.com/apps/support/documentation.html
CLDP -- Linux 中文文件計劃
http://www.linux.org.tw/CLDP/
...或到
http://www.google.com/ 鍵入 "Linux + install"
來搜尋相關網頁.
伍. Linux作業系統典型的啟動程序
Linux及Unix作業系統典型的啟動程序如下:
(1). 核心程式的載入memory, 通常由Rom中的程式來啟動執行
(2). 核心程式檢查硬體的組態
(3). 建立一些系統執行需要的特別用途的process(自發行行程)
(4). 若在手動模式, 操作者已可接手, 繼續未完的啟動(若設定為自動模式, 則系統自動完成)
(5). Startup script 的執行: 主要執行的工作有設定電腦名稱, 時區, 及啟動磁碟和網路系統
(6). 轉變成多人使用的模式
Linux啟動過程中的重點說明如下:
一. Linux的啟動流程
1. 當啟動電源之際,電腦的 BIOS
就會找尋有無系統開機磁片,有可能使用軟碟、硬碟或者是隨身碟開機,BIOS會將boot
loader載入RAM中,接者 boot Loader 會載入
Linux Kernel,而 Kernel 一旦起動後,第一件事就是切入保護模式 (protected mode),此時,所有的硬體交由 Kernel
來控制,也意味掙脫 BIOS 的羈絆。
2. 當 Kernel 載入完畢後,便開始初始化系統所有硬體設備。而當所有的硬體初始化的動作也告完成之際,系統將嘗試掛載
root partition。 Root partition就是被掛上當作 "/" 目錄,如果無法正確掛載
root partition, 系統將無法運作。
3. 當 root file system 成功的掛載後,就會去執行 init 這個程式。
init 會檢查 /etc/inittab,找出該檔中標明 sysinit 這一行,並執行該 script,在Redhat Linux 上為
rc.sysinit,於是 rc.sysinit 肩負系統的初始化的大任,有以下任務:
. 呼叫 /sbin/initlog 紀錄系統初始化過程
. 設定 path、hostname 等資訊
. banner 畫面:一般我們看到 "Welcome to RedHat Linux" 的訊息
. 系統會執行 mount -t proc /proc /proc 命令﹐為核心掛載一個特殊的檔案系統
. 執行 /sbin/setsysfont 來設定系統使用的字型
. Configure kernel parameters
. 設定好系統時鐘(system clock)
. 載入 keymap﹐按照您安裝時指定的鍵盤資訊來確定您的鍵盤類型
. 啟動系統的置換(swap)空間
. Remount the root filesystem read-write、清空 mtab﹐
. 載入一系列的核心模組
. 對檔案系統進行檢查
. 關於 rc.sysinit 在啟動過程中所顯示的所有信息﹐都會存放到 /var/log/dmesg 裡面去
如果您有興趣研究的話﹐可以深入追蹤 /etc/rc.d/rc.sysinit 這個檔案
4. 當 rc.sysinit 執行完畢,控制權立即移轉回 init 手中,然後根據 /etc/inittab
選擇預設的 run level﹐來決定執行哪些服務程式。實際要執行的程式﹐會按照 /etc/rc.d/rcX.d/ ( X 代表不同的 run
level 號碼)目錄裡面的 script 內容而定。
. 若內定的
runlevel 為 3:
init 執行 /sbin/mingetty 啟動 virtual console,並且以 "login:"
提示讓使用者登入,以完成開機。登入後系統會提供一個 shell 給使用者,就可以使用 Linux 。
. 若 runlevel 為 5:
在開啟 virtual console 後,init 會再執行 xdm 啟動 X window system,讓使用者以
xdm 界面登入。
5. init 將系統交由 login 程式接管﹐正式完成開機使命。
二. Linux Run level
◎ 7 Run Level
因應不同需求,Linux(UNIX)可以分為七種不同啟動模式,一般正常使用的系統多開啟為Level 3 或5
Run level |
代表意義 |
0 | 關機 |
1 | 單人模式(Single User Mode) |
2 | 多人使用模式,無NFS功能(網路是啟動的) |
3 | 完整多人使用模式 |
4 | unused |
5 | 完整多人使用模式,xdm啟動(圖形Login畫面) |
6 | 重新開機(Reboot) |
◎Run Level的改變
root可以使用init切換到不同Run
Level
init 0 =
shutdown -h
init 6 =
reboot
◎/etc/inittab內容解讀
/etc/inittab內容(Just For RedHAT Linux)
id : 3 : initdefault :
si : : sysinit: /etc/rc.d/rc.sysinit
l0 : 0 : wait: /etc/rc.d/rc 0
l1 : 1 : wait: /etc/rc.d/rc 1
l2 : 2 : wait: /etc/rc.d/rc 2
l3 : 3 : wait: /etc/rc.d/rc 3
l4 : 4 : wait: /etc/rc.d/rc 4
l5 : 5 : wait: /etc/rc.d/rc 5
l6 : 6 : wait: /etc/rc.d/rc 6
ud : : once : /sbin/update
ca : : ctrlaltdel : /sbin/shutdown -t3 -r now
pf : : powerfail :/sbin/shutdown -f -h +2 "Power Failure; System Shutting
Down"
pr : 12345 : powerokwait:/sbin/shutdown -c "Power Restored; Shutdown
Cancelled"
1 : 2345 : respawn : /sbin/mingetty tty1
2 : 2345 : respawn : /sbin/mingetty tty2
3 : 2345 : respawn : /sbin/mingetty tty3
4 : 2345 : respawn : /sbin/mingetty tty4
5 : 2345 : respawn : /sbin/mingetty tty5
6 : 2345 : respawn : /sbin/mingetty tty6
x : 5 : respawn : /etc/X11/prefdm -nodaemon
/etc/inittab每一行的意義
Format: code:runlevels:action:process
code:
這是每"項目"(行)的識別碼,他的格式可以是一個字元或兩個字元,某些特殊動作必須搭配特酥識別碼,系統預定的識別碼建議不要更動它。
runlevels:這是這個"項目"(行)指定的Run
Level,他的格式可以是0~6任何數目字元的組合,只要系統目前Run
Level符合這個項目指定的層級,則這行的內容會自動生效,這行所指定的Command也將會被執行。
例如:當系統開機至Run Level
5時,項目『x
: 5 : respawn : /etc/X11/prefdm -nodaemon』就會被執行,當系統開機至Run
Level
2、3、4、5時,項目『1
: 2345 : respawn : /sbin/mingetty tty1』都會生效。
action:這個欄位告訴"init"如何處理這個項目,可用選項有:initdefault、wait、respawn等共15種不同的值,他們所代表的意義請用"man
initttab"一窺究竟。
process:要執行的命令與參數。
id
: 3 : initdefault :
action "initdefault"告訴
init 將系統開至Run Level 3
si
: : sysinit: /etc/rc.d/rc.sysinit
runlevel 欄位空白告訴init不管系統開到哪一個Run
Level都要執行這一項目(rc.sysinit)
action "sysinit"告訴init優先執行這個項目。"sysinit"將忽略runlevel欄位。
ca
: : ctrlaltdel : /sbin/shutdown -t3 -r now
action "ctrlaltdel"告訴init當系統收到SIGINT(or
User同時按下Alt+Ctrl+Del時),執行這個項目(/sbin/shutdown
-t3 -r now)。如果你不希望你的系統因為有人在Console按下Alt+Ctrl+Del而重新開機時,你可以修改這個項目。
5 : 2345
: respawn : /sbin/mingetty tty5
表示在進入RunLevel 2/3/4/5/6時執行
"/sbin/mingetty
tty5 ",action "respawn"表示在一個session結束後(User由logout
Console tty5),在執行一次"/sbin/mingetty
tty5 ",如果此處不用repawn的話,當User
Logout tty5,這個Virtual Terminal將一去不復返,也就是"Ctrl+Alt+F5"將不再發生作用。