diff --git a/zh_TW.Big5/books/handbook/basics/chapter.sgml b/zh_TW.Big5/books/handbook/basics/chapter.sgml index e9dc78b35c..4ed225bafc 100644 --- a/zh_TW.Big5/books/handbook/basics/chapter.sgml +++ b/zh_TW.Big5/books/handbook/basics/chapter.sgml @@ -1,2538 +1,2395 @@ Chris Shumway Rewritten by UNIX 基礎概念 - + 概述 - 接下來的這一章將含蓋 FreeBSD 作業系統的基本指令及功能。 - 大部份的內容在 &unix;-like 作業系統中都是相通的。 - 如果您對這些內容熟悉的話,可以放心的跳過。 - 如果您剛接觸 FreeBSD ,那您一定要仔細的讀完這章。 + 接下來的這一章將涵蓋 FreeBSD 作業系統的基本指令及功能。 + 大部份的內容在 &unix;-like 作業系統中都是相通的。 + 如果您對這些內容熟悉的話,可以放心的跳過。 + 如果您剛接觸 FreeBSD,那您一定要仔細的讀完這章。 讀完這一章,您將會了解: 如何使用 FreeBSD 的virtual consoles &unix; 檔案權限運作的方式以及 &os; 中檔案的 flags。 預設的 &os; 檔案系統配置。 &os; 的磁碟結構。 如何掛載(mount)、卸載(umount)檔案系統 - 什麼是processes 、 daemons 以及 signals 。 + 什麼是processes、daemons 以及 signals 。 什麼是 shell ,以及如何變更您預設的登入環境。 如何使用基本的文字編輯器。 什麼是 devices 和 device nodes 。 &os; 下使用的 binary 格式。 如何閱讀 manual pages 以獲得更多的資訊。 Virtual Consoles 和終端機 virtual consoles terminals - 有很多方法可以操作 FreeBSD ,其中一種就是在文字終端機上打字。 - 如此使用 FreeBSD 即可輕易的體會到 &unix; 作業系統的威力和彈性。 - 這一節描述什麼是終端機console,及以您在 FreeBSD 中可以怎麼使用它們。 + 有很多方法可以操作 FreeBSD ,其中一種就是在文字終端機上打字。 + 如此使用 FreeBSD 即可輕易的體會到 &unix; 作業系統的威力和彈性。 + 這一節描述什麼是終端機console + ,以及可以如何在 FreeBSD 中運用它們。 The Console console - 如果您沒有將 FreeBSD 設定成開機時自動進入圖形化模式,系統會在啟動的 script 跑完之後顯示登入的提示符號。 - 您將會看到像是這樣的東西: + 如果您沒有將 FreeBSD 設定成開機時自動進入圖形化模式,系統會在啟動的 + script 跑完之後顯示登入的提示符號。 您將會看到像是這樣的東西: Additional ABI support:. Local package initialization:. Additional TCP options:. Fri Sep 20 13:01:06 EEST 2002 FreeBSD/i386 (pc3.example.org) (ttyv0) login: 這個訊息在您的系統上會有些許的不同,但是應該會看到類似的東西。 - 我們感興趣的是最後兩行,最後兩行是: + 我們感興趣的是最後兩行,最後兩行是: FreeBSD/i386 (pc3.example.org) (ttyv0) - 這行包含了剛開機完系統的資訊。 您看到的是在 Intel 或相容處理器的 x86 - 架構上執行的FreeBSD的 console這就是 i386 的意義。 - 注意即使您不是在 Intel 的 386 處理器上執行 FreeBSD ,一樣是i386。 - 這不是指你的處理器的型號,這裡顯示的是你處理器的架構 - 。 - 這台機器的名字 (每台 &unix; 機器都有一個名字) 是 pc3.example.org - ,而您現在看到的是它的系統 console— ttyv0終端機。 + 這行包含了剛開機完系統的資訊。 您看到的是在 Intel 或相容處理器的 + x86 架構上執行的 FreeBSD的 console + 這就是 i386 的意義。 注意即使您不是在 + Intel 的 386 處理器上執行 FreeBSD ,一樣是i386。 + 這不是指你的處理器的型號,這裡顯示的是你處理器的架構 + + 。 這台機器的名字(每台 &unix; 機器都有一個名字)是 + pc3.example.org,而您現在看到的是它的系統 + console— ttyv0終端機。 最後的一行應該都會是: login: - 這是您應該要輸入您的帳號名稱的地方。 - 下一小節將描述如何登入 FreeBSD。 + 這是您應該要輸入您的帳號名稱的地方。 + 下一小節將告訴您如何登入 FreeBSD。 登入 FreeBSD - FreeBSD 是一個 multiuser 、 multiprocessing 的系統。 - 這是一個正式的名稱,指的是一個在單一機器上可以同時被不同的人使用,同時可以執行很多程式的系統。 + FreeBSD 是一個 multiuser、multiprocessing 的系統。 + 這是一個正式的名稱,指的是在單一機器上可以同時被不同人使用, + 但同時可以執行很多程式的系統。 每一種多使用者系統都需要可以分辨不同使用者的方法。 - 在 FreeBSD (以及所有的 &unix;-like 作業系統) 中,所有的使用者在執行程式之前必須先登入系統。 - 每個使用者都有一組獨特的帳號名稱(username)及密碼(password) - 。FreeBSD 在允許使用者執行程式前將會先問這兩個問題。 + 在 FreeBSD (以及所有的 &unix;-like 作業系統) + 中,所有的使用者在執行程式之前必須先登入系統。 + 每個使用者都有一組獨特的帳號名稱 + (username)及密碼(password)。 + FreeBSD 在允許使用者執行程式前將會先問這兩個問題。 startup scripts - 在 FreeBSD 開機並跑完起動的 script 之後 - 這些起動的 script 是在開機的時候 FreeBSD 會自動執行的程式。 - 他們主要的功能是將所有該執行的東西設定好,並將您設定成背景執行的服務啟動。 - ,它將會印出提示字元要求您輸入正確的帳號名稱: + 在 FreeBSD 開機並跑完起動的 script 之後 + 這些起動的 script 是在開機的時候 FreeBSD 會自動執行的程式。 + 他們主要的功能是將所有該執行的東西設定好, + 並將您設定成背景執行的服務啟動。 + ,它將會印出提示字元要求您輸入正確的帳號名稱: login: - 在這個範例裡,我們假設您的帳號是john。 - 在提示字元處輸入john並按下Enter,您應該會看到另一個提示字元要您輸入密碼 + 在這個範例裡,我們假設您的帳號是john。 + 在提示字元處輸入 john 並按下 Enter + 。 接著您應該會看到另一個提示字元要您輸入密碼 login: john Password: - 輸入 john 的密碼, 再按下 - Enter。 輸入的密碼 不會顯示在螢幕上。 - 您不需要擔心這個,這樣做是為了安全上的問題。 + 輸入 john 的密碼,再按下 + Enter。 輸入的密碼 + 不會顯示在螢幕上。 + 您不需要為此擔心,這樣做是為了安全上的問題。 - 如果您輸入了正確的密碼,您應該已經登入 FreeBSD,可以嘗試所有可用的指令了。 + 如果您輸入了正確的密碼,您應該已經登入 FreeBSD。 + 現在就可以嘗試所有可用的指令了。 - 您應該會看到MOTD (即今日訊息、Messages Of The Day),後面接著命令提示字元 - (一個 #,$, 或是 % 字元)。 - 這就表示您已經成功登入 FreeBSD 了。 + 您應該會看到MOTD + (即今日訊息、Messages Of The Day),後面接著命令提示字元 + (一個 #,$, 或是 + % 字元)。 這就表示您已經成功登入 + FreeBSD 了。 多重 Console - 在一個 Console 下執行 &unix; 當然是沒有問題,然而FreeBSD是可以同時執行很多程式的。 - 像 FreeBSD 這樣可以同時執行一大堆程式的作業系統,只有一個 console 可以輸入指令是有點浪費。 - 在此virtual consoles就很有用了。 - + 在一個 Console 下執行 &unix; 當然是沒有問題,然而 FreeBSD + 是可以同時執行很多程式的。 像 FreeBSD + 這樣可以同時執行一大堆程式的作業系統,只有一個 + console 可以輸入指令實在是有點浪費。 因此 + virtual consoles 就顯得相當好用。 - FreeBSD 可以被設定成同時有很多 virtual console ,用幾個按鍵的組合就可以從一個 virtual console 跳到別的 virtual console 去。 每一個 console 都有自已不同的輸出頻道, 當從某一個 virtual console 切換到下一個的時候,FreeBSD 會適當的處理鍵盤輸入及螢幕輸出。 + 可以設定讓 FreeBSD 同時有很多 virtual console, + 用幾個按鍵的組合就可以從一個 virtual console 跳到別的 virtual console + 。 每一個 console 都有自已不同的輸出頻道,當從某一個 virtual console + 切換到下一個的時候,FreeBSD 會自動處理鍵盤輸入及螢幕輸出。 - FreeBSD 保留了特別的按鍵組合來切換 console - - 在 &man.syscons.4;、 &man.atkbd.4;、 &man.vidcontrol.1;、以及 - &man.kbdcontrol.1;等 manual page 中,對於 FreeBSD 的 console - 及鍵盤驅動程式有十分技術性且詳細的描述。 - 我們在這裡不討論細節,有興趣的讀者隨時可以在 manual page - 中查到關於運作方式的更詳細且完整的解釋 - 。 您可以用 - AltF1、 - AltF2、到 - AltF8來切換 FreeBSD - 的不同 console。 + FreeBSD 保留了特別的按鍵組合來切換 console + 在 &man.syscons.4;、&man.atkbd.4;、&man.vidcontrol.1;、以及 + &man.kbdcontrol.1;等 manual page 中,對於 FreeBSD 的 console + 及鍵盤驅動程式有詳細的技術說明。 我們在這裡不討論細節, + 有興趣的讀者隨時可以在 manual pages + 中查到關於運作方式的更詳細且完整的解釋。。 + 您可以用 AltF1、 + AltF2、到 + AltF8 + 來切換 FreeBSD 的不同 console。 - - 當您從一個 console 切換到下一個的時候, FreeBSD 會處理螢幕輸出的儲存及回復。 - 這就好像有很多虛擬的螢幕和鍵盤可以讓您輸入指令給 - FreeBSD 執行。 在某一個 console 上執行的程式並不會因為切到別的 console - 而停止執行,當您切換到另一個 console 的時候,他們會繼續執行。 - + 當您從一個 console 切換到下一個的時候,FreeBSD + 會處理螢幕輸出的儲存及回復。 + 這就好像有很多虛擬的螢幕和鍵盤, + 可以讓您輸入指令到 FreeBSD 執行。 在某一個 console + 上執行的程式並不會因為切到別的 console 而停止執行,切換到另一個 + console 時,它們仍會繼續執行。 - The <filename>/etc/ttys</filename> File - - The default configuration of FreeBSD will start up with eight - virtual consoles. This is not a hardwired setting though, and - you can easily customize your installation to boot with more - or fewer virtual consoles. The number and settings of the - virtual consoles are configured in the - /etc/ttys file. - - You can use the /etc/ttys file to configure - the virtual consoles of FreeBSD. Each uncommented line in this file - (lines that do not start with a # character) contains - settings for a single terminal or virtual console. The default - version of this file that ships with FreeBSD configures nine virtual - consoles, and enables eight of them. They are the lines that start with - ttyv: + <filename>/etc/ttys</filename> 檔 + + FreeBSD 預設的虛擬 console 總共有 8 個, + 但這並非硬性規定,您可輕鬆設定這些虛擬 console 的數量增減。 + 有關虛擬 console 的編號跟設定都在 + /etc/ttys 這檔案內設定。 + + 可以用 /etc/ttys 檔案來設定 + FreeBSD 的虛擬 console。 檔案內每行非註解文字(該行開頭沒有 + # 這字)都是設定終端機或虛擬 console。 + FreeBSD 預設有 9 個虛擬 console 但只啟動 8 個,也就是以下以 + ttyv 開頭的那幾行設定。 # name getty type status comments # ttyv0 "/usr/libexec/getty Pc" cons25 on secure # Virtual terminals ttyv1 "/usr/libexec/getty Pc" cons25 on secure ttyv2 "/usr/libexec/getty Pc" cons25 on secure ttyv3 "/usr/libexec/getty Pc" cons25 on secure ttyv4 "/usr/libexec/getty Pc" cons25 on secure ttyv5 "/usr/libexec/getty Pc" cons25 on secure ttyv6 "/usr/libexec/getty Pc" cons25 on secure ttyv7 "/usr/libexec/getty Pc" cons25 on secure ttyv8 "/usr/X11R6/bin/xdm -nodaemon" xterm off secure - For a detailed description of every column in this file and all - the options you can use to set things up for the virtual consoles, - consult the &man.ttys.5; manual page. + 有關各欄位的設定以及其他選項,請參閱 &man.ttys.5; 說明。 - Single User Mode Console + Single User 模式的 Console - A detailed description of what single user mode is - can be found in . It is worth noting - that there is only one console when you are running FreeBSD in single - user mode. There are no virtual consoles available. The settings of - the single user mode console can also be found in the - /etc/ttys file. Look for the line that starts - with console: + 有關 single user 模式 的介紹在 + + 這邊有詳盡介紹。 在 single user 模式時,能夠使用的 console + 只有一個,並無虛擬 console 可用。 而 single user 模式相關設定值可以在 + /etc/ttys 檔做調整。 下面以 + console 開頭的那行,就是了: # name getty type status comments # # If console is marked "insecure", then init will ask for the root password # when going to single-user mode. console none unknown off secure - As the comments above the console line - indicate, you can edit this line and change secure to - insecure. If you do that, when FreeBSD boots - into single user mode, it will still ask for the - root password. - - Be careful when changing this to - insecure. If you ever forget - the root password, booting into single user - mode is a bit involved. It is still possible, but it might be a bit - hard for someone who is not very comfortable with the FreeBSD - booting process and the programs involved. + console 那行前面的註解有提到,可以把那行的 + secure 改為 insecure, + 如此一來,即使 FreeBSD 進入 single user 模式, + 仍會要求您輸入 root 的密碼。 + + 請審慎考慮是否要改為 + insecure。 因為萬一忘記 + root 密碼的話,若要登入 single user + 模式就有些麻煩了。儘管還有其他方式可以登入,但對不熟 FreeBSD + 開機程序的人而言,就會相當棘手。 - Permissions + 權限 UNIX - FreeBSD, being a direct descendant of BSD &unix;, is based on - several key &unix; concepts. The first and - most pronounced is that FreeBSD is a multi-user operating system. - The system can handle several users all working simultaneously on - completely unrelated tasks. The system is responsible for properly - sharing and managing requests for hardware devices, peripherals, - memory, and CPU time fairly to each user. - - Because the system is capable of supporting multiple users, - everything the system manages has a set of permissions governing who - can read, write, and execute the resource. These permissions are - stored as three octets broken into three pieces, one for the owner of - the file, one for the group that the file belongs to, and one for - everyone else. This numerical representation works like - this: + FreeBSD 源自於 BSD &unix;,繼承了幾個重要的 &unix; 概念。 + 首先也最明顯,它是一款 multi-user 作業系統。 它可以同時處理多人多工, + 負責徹底的分享與管理來自每位使用者對硬碟裝置、週邊設備、記憶體及 + CPU 時間的要求。 + + 也因為系統能夠支援多使用者, + 所以系統管理的一切都有權限來決定誰可以讀取、寫入或執行資源。 + 這些權限分別使用三組八進位的數字儲存,一組代表檔案的所有者, + 一組代表檔案所屬的群組,而最後一組則代表其他所有人。 + 表示這些數字的方式如下: permissions file permissions - Value - Permission - Directory Listing + + 權限 + 目錄顯示 0 - No read, no write, no execute + 不可讀取, 不可寫入, 不可執行 --- 1 - No read, no write, execute + 不可讀取, 不可寫入, 可執行 --x 2 - No read, write, no execute + 不可讀取, 可寫入, 不可執行 -w- 3 - No read, write, execute + 不可讀取, 可寫入, 可執行 -wx 4 - Read, no write, no execute + 可讀取, 不可寫入, 不可執行 r-- 5 - Read, no write, execute + 可讀取, 不可寫入, 可執行 r-x 6 - Read, write, no execute + 可讀取, 可寫入, 不可執行 rw- 7 - Read, write, execute + 可讀取, 可寫入, 可執行 rwx ls directories - You can use the command line - argument to &man.ls.1; to view a long directory listing that - includes a column with information about a file's permissions - for the owner, group, and everyone else. For example, a - ls -l in an arbitrary directory may show: + 使用 &man.ls.1; 指令時,可以加上 參數, + 來檢視詳細的目錄清單。 + 清單中欄位的資訊包含檔案對所有者、群組及其他人的權限。 + 在任一個目錄底下執行 ls -l,會顯示如下的結果: + &prompt.user; ls -l total 530 -rw-r--r-- 1 root wheel 512 Sep 5 12:31 myfile -rw-r--r-- 1 root wheel 512 Sep 5 12:31 otherfile -rw-r--r-- 1 root wheel 7680 Sep 5 12:31 email.txt ... - Here is how the first column of ls -l is - broken up: + 在這裡告所您該如何區分 ls -l + 第一欄當中的資訊: -rw-r--r-- - The first (leftmost) character - tells if this file is a regular file, a directory, a special - character device, a socket, or any other special - pseudo-file device. In this case, the - - indicates a regular file. The next three characters, - rw- in this example, give the permissions for the owner of the - file. The next three characters, r--, give the - permissions for the group that the file belongs to. The final three - characters, r--, give the permissions for the - rest of the world. A dash means that the permission is turned off. - In the case of this file, the permissions are set so the owner can - read and write to the file, the group can read the file, and the - rest of the world can only read the file. According to the table - above, the permissions for this file would be - 644, where each digit represents the three parts - of the file's permission. - - This is all well and good, but how does the system control - permissions on devices? FreeBSD actually treats most hardware - devices as a file that programs can open, read, and write data to - just like any other file. These special device files are stored on - the /dev directory. - - Directories are also treated as files. They have read, write, - and execute permissions. The executable bit for a directory has a - slightly different meaning than that of files. When a directory is - marked executable, it means it can be traversed into, that is, it is - possible to cd (change directory) into it. This also means that - within the directory it is possible to access files whose names are - known (subject, of course, to the permissions on the files - themselves). - - In particular, in order to perform a directory listing, - read permission must be set on the directory, whilst to delete a file - that one knows the name of, it is necessary to have write - and execute permissions to the directory - containing the file. - - There are more permission bits, but they are primarily used in - special circumstances such as setuid binaries and sticky - directories. If you want more information on file permissions and - how to set them, be sure to look at the &man.chmod.1; manual - page. + 第一個 (最左邊) 的字元用來表示這個檔案的類型為何, + 除標準檔案以外,尚有目錄、特殊字元裝置 (Special character device)、 + Socket 及其他特殊虛擬檔案裝置 (Special pseudo-file device), + 在此例當中,- 表示該檔案為一個標準的檔案。 + 範例中接下來的三個字元中,rw- + 代表所有者對檔案擁有的權限。 再接下來的三個字元, + r-- 則代表群組對檔案擁有的權限, + 最後三個字元,r-- 則代表其他人對檔案擁有的權限。 + 破折號 (-) 表示沒有權限,範例中的這個檔案的權限, + 只允許所有者讀取、寫入檔案,群組以及其他人僅能讀取檔案。 + 根據以上的表格,此種權限的檔案可以使用 644 來表示, + 每組數字分別代表檔案的三種權限。 + + 以上是不錯的方式,但系統該如何控制裝置的權限? 實際上 FreeBSD + 對大多的硬碟裝置就如同檔案,程式可以開啟、讀取以及寫入資料如一般檔案。 + 這些特殊裝置檔案 (Special device file) 都儲存於 /dev + 目錄中。 + + + 目錄也同如檔案,擁有讀取、寫入及執行的權限, + 但在執行權限上與檔案有明顯的差異。 當目錄被標示為可執行時,代表可以使用 + cd (更改目錄) 進入該目錄。 + 也代表能夠存取在此目錄之中的已知檔名的檔案 + (當然,檔案仍擁有自己的權限) + + 尤其,要能夠列出目錄內容,必須擁有目錄的讀取權限。 + 而當要刪除已知檔名的檔案時,也必須擁有檔案所在目錄的寫入 + 以及 執行的權限。 + + 還有一些權限,但這些權限主要在特殊情況使用,如 + setuid binaries 及 sticky directories。 + 如果您還想知道更多檔案權限的資訊及使用方法,請務必參閱 + &man.chmod.1; 說明文件。 Tom Rhodes Contributed by - Symbolic Permissions + 權限符號 permissionssymbolic - Symbolic permissions, sometimes referred to as symbolic expressions, - use characters in place of octal values to assign permissions to files - or directories. Symbolic expressions use the syntax of (who) (action) - (permissions), where the following values are available: + 權限符號可稱做符號表示, + 使用字元的方式來取代使用數值來設定檔案或目錄的權限。 + 符號表示的格式依序為 (某人)(動作)(權限),可使用的符號如下: - Option - Letter - Represents + 項目 + 字母 + 意義 - (who) + (某人) u - User + 使用者 - (who) + (某人) g - Group owner + 群組所有者 - (who) + (某人) o - Other + 其他 - (who) + (某人) a - All (world) + 全部(world) - (action) + (動作) + - Adding permissions + 增加權限 - (action) + (動作) - - Removing permissions + 移除權限 - (action) + (動作) = - Explicitly set permissions + 指定權限 - (permissions) + (權限) r - Read + 讀取 - (permissions) + (權限) w - Write + 寫入 - (permissions) + (權限) x - Execute + 執行 - (permissions) + (權限) t Sticky bit - (permissions) + (權限) s - Set UID or GID + Set UID 或 GID - These values are used with the &man.chmod.1; command - just like before, but with letters. For an example, you could use - the following command to block other users from accessing + 如先前同樣使用 &man.chmod.1; 指令來設定,但使用的參數為這些字元。 + 例如,您可以使用下列指令禁止其他使用者存取檔案 FILE: &prompt.user; chmod go= FILE - A comma separated list can be provided when more than one set - of changes to a file must be made. For example the following command - will remove the groups and world write permission - on FILE, then it adds the execute - permissions for everyone: + 若有兩個以上的符號表示可以使用逗號 (,) 區隔。 + 例如,下列指令將會移除群組及其他人對檔案 + FILE 的寫入權限, + 並使全部人(world)對該檔有執行權限。 &prompt.user; chmod go-w,a+x FILE Tom Rhodes Contributed by - &os; File Flags + &os; 檔案旗標(Flag) - In addition to file permissions discussed previously, &os; - supports the use of file flags. These flags - add an additional level of security and control over files, but - not directories. + 除了前面提到的檔案權限外,&os; 支援使用 檔案旗標。 + 這些旗標增加了檔案的安全性及管理性,但不包含目錄。 - These file flags add an additional level of control over - files, helping to ensure that in some cases not even the - root can remove or alter files. + 檔案旗標增加了管理性,確保在某些時候 root + 不會意外將檔案修改或移除。 - File flags are altered by using the &man.chflags.1; utility, - using a simple interface. For example, to enable the system - undeletable flag on the file file1, - issue the following command: + 修改的檔案 flag 僅需要使用擁有簡易的介面的 &man.chflags.1; 工具。 + 例如,標示系統禁止刪除的旗標於檔案 + file1,使用下列指令: &prompt.root; chflags sunlink file1 - And to disable the system undeletable flag, simply - issue the previous command with no in - front of the . Observe: + 若要移除系統禁止刪除的旗標,只需要簡單在 + 前加上 no,例如: &prompt.root; chflags nosunlink file1 - To view the flags of this file, use the &man.ls.1; - with the flags: + 使用 &man.ls.1; 及參數 + 可檢視檔案目前的旗標: &prompt.root; ls -lo file1 - The output should look like the following: + 輸出的結果如下: -rw-r--r-- 1 trhodes trhodes sunlnk 0 Mar 1 05:54 file1 - Several flags may only added or removed to files by the - root user. In other cases, the file owner - may set these flags. It is recommended an administrator read - over the &man.chflags.1; and &man.chflags.2; manual pages for - more information. + 多數的旗標僅能由 root + 使用者來標示或移除,而部份旗標可由檔案所有者設定。 + 我們建議系統管理者可閱讀 &man.chflags.1; 及 &man.chflags.2; + 說明以瞭解相關細節。 - Directory Structure + 目錄結構 directory hierarchy - The FreeBSD directory hierarchy is fundamental to obtaining - an overall understanding of the system. The most important - concept to grasp is that of the root directory, - /. This directory is the first one mounted at - boot time and it contains the base system necessary to prepare - the operating system for multi-user operation. The root - directory also contains mount points for every other file system - that you may want to mount. - - A mount point is a directory where additional file systems can - be grafted onto the root file system. - This is further described in . - Standard mount points include - /usr, /var, /tmp, - /mnt, and /cdrom. These - directories are usually referenced to entries in the file - /etc/fstab. /etc/fstab is - a table of various file systems and mount points for reference by the - system. Most of the file systems in /etc/fstab - are mounted automatically at boot time from the script &man.rc.8; - unless they contain the option. - Details can be found in . - - A complete description of the file system hierarchy is - available in &man.hier.7;. For now, a brief overview of the - most common directories will suffice. + 認識 FreeBSD 的目錄架構,就可對系統有概略的基礎理解。 + 最重要的莫過於整個目錄的根目錄,就是 / 目錄, + 該目錄會在開機時最先掛載 (mount),裡面會有開機所會用到必備檔案。 + 此外,根目錄還有紀錄其他檔案系統的掛載點相關設定。 + + 「掛載點」就是讓新增的檔案系統,能接到上層的檔案系統 + (通常就是「根目錄」檔案系統) 的目錄。 + 在 這邊對此有更詳細介紹。 + 標準的掛載點包括了 /usr/var、 + /tmp/mnt 以及 + /cdrom。 這些目錄通常會記錄在 + /etc/fstab 設定檔內。 + /etc/fstab 是記錄各檔案系統及相關掛載點的表格。 + 大部分在 /etc/fstab 有記錄的檔案系統,會在開機時由 + &man.rc.8; script 來自動掛載,除非它們有設定 + 選項。 其中細節說明可參閱 + + 有關檔案系統架構的完整說明可參閱 &man.hier.7;。 + 現在呢,讓我們大致先一窺常見的目錄有哪些吧。 - Directory - Description + 目錄 + 說明 / - Root directory of the file system. + 檔案系統的根目錄。 - + /bin/ - User utilities fundamental to both single-user - and multi-user environments. + single-user、multi-user 兩種模式皆可使用的基本工具 + 。 - + /boot/ - Programs and configuration files used during - operating system bootstrap. + 作業系統開機過程會用到的程式、設定檔。 - + /boot/defaults/ - Default bootstrapping configuration files; see - &man.loader.conf.5;. + 預設的開機啟動設定檔,詳情請參閱 &man.loader.conf.5; + 。 - + /dev/ - Device nodes; see &man.intro.4;. + Device nodes,詳情請參閱 &man.intro.4;。 - + /etc/ - System configuration files and scripts. + 系統設定檔及一些 script 檔。 - + /etc/defaults/ - Default system configuration files; see &man.rc.8;. + 預設的系統設定檔,詳情請參閱 &man.rc.8;。 - + /etc/mail/ - Configuration files for mail transport agents such - as &man.sendmail.8;. + MTA(Mail Transport Agent)的相關設定檔,像是 + &man.sendmail.8;。 - + /etc/namedb/ - named configuration files; see - &man.named.8;. + named 設定檔,詳情請參閱 + &man.named.8;。 - + /etc/periodic/ - Scripts that are run daily, weekly, and monthly, - via &man.cron.8;; see &man.periodic.8;. + 每日、每週、每月透過 &man.cron.8;; 執行的定期排程 script, + 詳情請參閱 &man.periodic.8;。 - + /etc/ppp/ - ppp configuration files; see - &man.ppp.8;. + ppp 設定檔,詳情請參閱 + &man.ppp.8;。 - + /mnt/ - Empty directory commonly used by system administrators as a - temporary mount point. + 系統管理者慣用充當臨時掛載點的空目錄。 - + /proc/ - Process file system; see &man.procfs.5;, - &man.mount.procfs.8;. + Process 檔案系統,詳情請參閱 &man.procfs.5; 及 + &man.mount.procfs.8;。 /rescue/ - Statically linked programs for emergency recovery; see - &man.rescue.8;. + 緊急救援用途的一些 statically linked 程式,詳情請參閱 + &man.rescue.8;。 /root/ - Home directory for the root - account. + root 帳號的家目錄。 /sbin/ - System programs and administration utilities fundamental to - both single-user and multi-user environments. + 供 single-user 及 multi-user 環境使用的系統程式及管理工具 + 。 - - - /stand/ - Programs used in a standalone environment. - - - + /tmp/ - Temporary files. The contents of - /tmp are usually NOT - preserved across a system reboot. A memory-based file system - is often mounted at - /tmp. - This can be automated using the tmpmfs-related variables of - &man.rc.conf.5; (or with an entry in - /etc/fstab; see &man.mdmfs.8;, - or for FreeBSD 4.X, &man.mfs.8;). + 臨時檔案。 一般而言,重開機之後 + /tmp 內的東西會被清除掉。 + 而通常會將 memory-based 檔案系統掛載在 + /tmp 上。 + 這些瑣事可透過 tmpmfs 相關的 &man.rc.conf.5; 環境變數來自動完成 + 。(或是在 /etc/fstab 內做設定, + 詳情請參閱 &man.mdmfs.8;。) - - + /usr/ - The majority of user utilities and applications. + 主要是使用者所安裝的工具程式、應用程式存放處。 - + /usr/bin/ - Common utilities, programming tools, and applications. + 常用工具、開發工具、應用軟體。 - + /usr/include/ - Standard C include files. + 標準 C include 的相關 header 檔案庫。 - + /usr/lib/ - Archive libraries. + 函式庫存放處。 - - + /usr/libdata/ - Miscellaneous utility data files. + 其他各式工具的資料檔。 - + /usr/libexec/ - System daemons & system utilities (executed by other - programs). + 系統 daemons 及系統工具程式(透過其他程式來執行)。 - + /usr/local/ - Local executables, libraries, etc. Also used as - the default destination for the FreeBSD ports - framework. Within /usr/local, - the general layout sketched out by &man.hier.7; for - /usr should be used. Exceptions - are the man directory, which is directly under - /usr/local rather than under - /usr/local/share, and the ports - documentation is in - share/doc/port. + 存放一些自行安裝的執行檔、函式庫等等。 同時,也是 FreeBSD + ports 架構的預設安裝目錄。 /usr/local + 內的目錄架構大致與 /usr 相同,詳情請參閱 + &man.hier.7; 說明。 但 man 目錄例外,它們是直接放在 + /usr/local 底下,而非 + /usr/local/share,而 ports + 所安裝的說明文件則在 + share/doc/port - + /usr/obj/ - Architecture-specific target tree produced by building - the /usr/src tree. + 在編譯 /usr/src + 目錄時所產生的相關架構 object 檔案。 /usr/ports - The FreeBSD Ports Collection (optional). + FreeBSD Ports Collection (optional)。 /usr/sbin/ - System daemons & system utilities (executed by users). + 系統 daemon 及系統工具(直接由使用者執行)。 /usr/share/ - Architecture-independent files. + 各架構皆共通的檔案。 /usr/src/ - BSD and/or local source files. + BSD 本身的原始碼(或自行新增的)。 /usr/X11R6/ - X11R6 distribution executables, libraries, etc - (optional). + X11R6 相關套件的執行檔、函式庫等(optional)。 /var/ - Multi-purpose log, temporary, transient, and spool files. - A memory-based file system is sometimes mounted at - /var. - This can be automated using the varmfs-related variables of - &man.rc.conf.5 (or with an entry in - /etc/fstab; see &man.mdmfs.8;, - or for FreeBSD 4.X, &man.mfs.8;). + 存放各種用途的 log 檔、臨時或暫時存放、列印或郵件的 + spool 檔案。有時候,memory-based 檔案系統也會掛載在 + /var。 + 這些瑣事可透過 varmfs 相關的 &man.rc.conf.5 + 環境變數來自動完成。(或是在 + /etc/fstab 內做設定,相關細節請參閱 + &man.mdmfs.8;。) /var/log/ - Miscellaneous system log files. + 各項系統記錄的 log 檔案。 /var/mail/ - User mailbox files. + 各使用者的 mailbox 檔案。 /var/spool/ - Miscellaneous printer and mail system spooling directories. - + 各種印表機、郵件系統的 spool 目錄。 /var/tmp/ - Temporary files. - The files are usually preserved across a system reboot, - unless /var - is a memory-based file system. + 臨時檔案。 + 這些檔案在重開機後通常仍會保留,除非 + /var + 是屬於 memory-based 檔案系統。 /var/yp - NIS maps. + 記錄 NIS maps。 - Disk Organization - - The smallest unit of organization that FreeBSD uses to find files - is the filename. Filenames are case-sensitive, which means that - readme.txt and README.TXT - are two separate files. FreeBSD does not use the extension - (.txt) of a file to determine whether the file is - a program, or a document, or some other form of data. - - Files are stored in directories. A directory may contain no - files, or it may contain many hundreds of files. A directory can also - contain other directories, allowing you to build up a hierarchy of - directories within one another. This makes it much easier to organize - your data. - - Files and directories are referenced by giving the file or - directory name, followed by a forward slash, /, - followed by any other directory names that are necessary. If you have - directory foo, which contains directory - bar, which contains the file - readme.txt, then the full name, or - path to the file is - foo/bar/readme.txt. - - Directories and files are stored in a file system. Each file system - contains exactly one directory at the very top level, called the - root directory for that file system. This root - directory can then contain other directories. - - So far this is probably similar to any other operating system you - may have used. There are a few differences; for example, &ms-dos; uses - \ to separate file and directory names, while &macos; - uses :. - - FreeBSD does not use drive letters, or other drive names in the - path. You would not write c:/foo/bar/readme.txt - on FreeBSD. - - Instead, one file system is designated the root - file system. The root file system's root directory is - referred to as /. Every other file system is then - mounted under the root file system. No matter - how many disks you have on your FreeBSD system, every directory - appears to be part of the same disk. - - Suppose you have three file systems, called A, - B, and C. Each file system has - one root directory, which contains two other directories, called - A1, A2 (and likewise - B1, B2 and - C1, C2). - - Call A the root file system. If you used the - ls command to view the contents of this directory - you would see two subdirectories, A1 and - A2. The directory tree looks like this: + 磁碟組織 + + FreeBSD 用來尋找檔案的最小單位就是檔案的名稱了。 + 檔案的名稱有大小寫之分,所以說 readme.txt + 和 README.TXT 是兩個不同的檔案。 + FreeBSD 並不使用副檔名 (.txt) + 來判別這是一個程式檔、文件檔或是其他類型的檔案。 + + 檔案存在目錄裡面。 + 一個目錄中可能沒有任何檔案,也可能有好幾百個檔案。 + 目錄之中也可以包含其他的目錄; + 您可以建立階層式的目錄以便資料的管理。 + + 檔案或目錄的對應是藉由給定的檔案或目錄名稱,然後加上正斜線符號 + (/);之後再視需要加上其他的目錄名稱。 + 如果您有一個目錄 foo ,裡面有一個目錄叫作 + bar,這個目錄中又包含了一個叫 + readme.txt + 的檔案,那麼這個檔案的全名,或者說檔案的路徑就是 + foo/bar/readme.txt + + 目錄及檔案儲存在檔案系統之中。 + 每個檔案系統都有唯一一個最上層的目錄,叫做根目錄 + (root directory)。 + 然後在這個根目錄下面才能有其他的目錄。 + + 到目前為止大概和其他您用過的的作業系統都差不多。 + 還是有些不一樣的地方就是了,例如 &ms-dos; 用 \ + 當檔案和目錄名稱的分隔符號,而 &macos; 則是用 : + 符號。 + + FreeBSD 的路徑中並沒有使用磁碟機代號或其他的磁碟名稱。 + 因此,您不可以使用像 c:/foo/bar/readme.txt + 這樣子的檔案名稱。 + + 相對的,在 FreeBSD + 系統中有一個檔案系統被指定為根檔案系統。 + 根檔案系統的根目錄由 / 表示。 + 然後其他的檔案系統再掛載 (mount) + 在根檔案系統之下。因此無論您的 FreeBSD + 系統上有多少顆硬碟,每一個目錄看起來就像在同一個磁碟上。 + + 假設您有三個檔案系統,分別叫作 A、 + BC。 + 每個檔案系統都包含兩個目錄,叫做 + A1A2 (依此類推得 + B1B2 及 + C1C2)。 + + A 為主要的檔案系統;如果您用 + ls 指令查看此目錄的內容,您會看到兩個子目錄: + A1A2,如下所示: / | +--- A1 | `--- A2 - A file system must be mounted on to a directory in another - file system. So now suppose that you mount file system - B on to the directory A1. The - root directory of B replaces A1, - and the directories in B appear accordingly: + 一個檔案系統必須以目錄形式掛載於另一個檔案系統上。 + 因此,假設您將 B 掛載於 A1 + 之上,則 B 的根目錄就變成了 + A1,而在 B + 之下的任何目錄的路徑也隨之改變: / | +--- A1 | | | +--- B1 | | | `--- B2 | `--- A2 - Any files that are in the B1 or - B2 directories can be reached with the path - /A1/B1 or /A1/B2 as - necessary. Any files that were in /A1 have been - temporarily hidden. They will reappear if B is - unmounted from A. + B1B2 + 目錄中的任何檔案必須經由路徑 /A1/B1 + 或 /A1/B2 才能達到。 + 所有原來在 /A1 中的檔案會暫時被隱藏起來,直到 + B 被「移除 + (unmounted)」後才會再顯現出來。 - If B had been mounted on A2 - then the diagram would look like this: + 如果 B 掛載在 A2 + 之上,則會變成: / | +--- A1 | `--- A2 | +--- B1 | `--- B2 - and the paths would be /A2/B1 and - /A2/B2 respectively. + 上面的路徑分別為 /A2/B1 及 + /A2/B2 - File systems can be mounted on top of one another. Continuing the - last example, the C file system could be mounted on - top of the B1 directory in the B - file system, leading to this arrangement: + 檔案系統可以掛在其他檔案系統的目錄之上。 + 延續之前的例子,C 檔案系統可以掛在檔案系統 + BB1 + 目錄之上,如圖所示: / | +--- A1 | `--- A2 | +--- B1 | | | +--- C1 | | | `--- C2 | `--- B2 - Or C could be mounted directly on to the - A file system, under the A1 - directory: + 或者 C 直接掛載於 A 的 + A1 目錄之上: / | +--- A1 | | | +--- C1 | | | `--- C2 | `--- A2 | +--- B1 | `--- B2 - If you are familiar with &ms-dos;, this is similar, although not - identical, to the join command. + 如果您熟悉 &ms-dos; 的話,這和 join + 指令很類似 (雖然不儘相同)。 - This is not normally something you need to concern yourself with. - Typically you create file systems when installing FreeBSD and decide - where to mount them, and then never change them unless you add a new - disk. + 一般情況下您不需要擔心這些東西。 + 除非您要安裝新的磁碟,不然通常在您安裝 FreeBSD + 時建立好檔案系統並決定好要掛載在何處之後就不會再做任何更動了。 - It is entirely possible to have one large root file system, and not - need to create any others. There are some drawbacks to this approach, - and one advantage. + 您完全可以使用單一的一個大的根檔案系統 (root file system) + 而不建立其他的檔案系統。 這樣有好處也有有壞處。 - Benefits of Multiple File Systems + 使用多個檔案系統的好處 - Different file systems can have different mount - options. For example, with careful planning, the - root file system can be mounted read-only, making it impossible for - you to inadvertently delete or edit a critical file. Separating - user-writable file systems, such as /home, - from other file systems also allows them to be mounted - nosuid; this option prevents the - suid/guid bits on - executables stored on the file system from taking effect, possibly - improving security. + 不同的檔案系統在掛上的時候可以有不同的 + 掛載參數。 + 舉例來說,為求謹慎您可以將根檔案系統設成唯讀, + 以避免不小心刪除或修改掉重要的檔案。 + 將使用者可寫入的檔案系統 (例如 /home) + 獨立出來也可以讓他們用 nosuid + 的參數掛載,此選項可以讓在這個檔案系統中執行檔的 + suid/guid + bits 失效,也許可以讓系統更安全。 - FreeBSD automatically optimizes the layout of files on a - file system, depending on how the file system is being used. So a - file system that contains many small files that are written - frequently will have a different optimization to one that contains - fewer, larger files. By having one big file system this - optimization breaks down. + FreeBSD 會自動根據您檔案系統的使用方式來做最佳的檔案配置方式。 + 因此,一個有很多小檔案、 + 常常寫入的檔案系統跟只有幾個較大的檔案的檔案系統配置是不一樣的。 + 如果您只有單一一個大的檔案系統,這部分就沒用了。 - FreeBSD's file systems are very robust should you lose power. - However, a power loss at a critical point could still damage the - structure of the file system. By splitting your data over multiple - file systems it is more likely that the system will still come up, - making it easier for you to restore from backup as necessary. + FreeBSD 的檔案系統在停電的時候很穩固。 + 然而,在某些重要的時候停電仍然會對檔案系統結構造成損害。 + 分割成許多個檔案系統的話在系統在停電後比較能夠正常啟動, + 以便您在需要的時候將備份資料回存回來。 - Benefit of a Single File System + 使用單一檔案系統的好處 - File systems are a fixed size. If you create a file system when - you install FreeBSD and give it a specific size, you may later - discover that you need to make the partition bigger. This is not - easily accomplished without backing up, recreating the file system - with the new size, and then restoring the backed up data. + 檔案系統的大小是固定的。 + 您當初安裝 FreeBSD + 的時候應該會給定一個大小,可是後來您可能會想把空間加大。 + 如果沒有備份的話是很難達成的; + 您必須將檔案系統重新建立為您需要的大小,然後將備份回存回來。 - FreeBSD 4.4 and later versions feature the &man.growfs.8; - command, which makes it possible to increase the size of - file system on the fly, removing this limitation. + FreeBSD 的 &man.growfs.8; + 指令可以突破此限制直接變更檔案系統的大小。 - File systems are contained in partitions. This does not have the - same meaning as the common usage of the term partition (for example, &ms-dos; - partition), because of &os;'s &unix; heritage. Each partition is - identified by a letter from a through to - h. Each partition can contain only one file system, - which means that file systems are often described by either their - typical mount point in the file system hierarchy, or the letter of the - partition they are contained in. - - FreeBSD also uses disk space for swap - space. Swap space provides FreeBSD with - virtual memory. This allows your computer to - behave as though it has much more memory than it actually does. When - FreeBSD runs out of memory it moves some of the data that is not - currently being used to the swap space, and moves it back in (moving - something else out) when it needs it. - - Some partitions have certain conventions associated with - them. + 檔案系統包含在分割區裡面。 + 因為 &os; 承襲 &unix 架構,這邊講的分割區和一般提到的分割區 + (例如 &ms-dos; 分割區) 不同。 每一個分割區由一個代號(字母)表示,從 + ah。 + 每個分割區只能包含一個檔案系統。 + 因此除了說常見到用檔案系統同的掛載點來表示檔案系統外, + 也可以用包含他的分割區代號來表示。 + + FreeBSD 也會拿磁碟空間來當 swap space。 + Swap space 給 FreeBSD 當作虛擬記憶體用。 + 這讓您的電腦好像擁有比實際更多的記憶體。 + 當 FreeBSD 的記憶體用完的時候,它會把一些目前沒用到的資料移到 + swap space,然後在用到的時候移回去 (同時移出部份沒用到的)。 + + 某些分割區有慣例的使用方式如下: - Partition + 分割區 - Convention + 慣例 a - Normally contains the root file system + 通常包含根檔案系統 (root file system) b - Normally contains swap space + 通常是 swap space c - Normally the same size as the enclosing slice. This - allows utilities that need to work on the entire slice (for - example, a bad block scanner) to work on the - c partition. You would not normally create - a file system on this partition. + 通常和整個 slice 的大小一樣,給一些會用到整個 slice + 的工具程式 (例如硬碟壞軌檢查工具) 來使用。 + 一般來說您應該不會把檔案系統建立在這個分割區。 d - Partition d used to have a special - meaning associated with it, although that is now gone. To - this day, some tools may operate oddly if told to work on - partition d, so - sysinstall will not normally create - partition d. + 分割區 d + 曾經有代表特殊意義,但是已經不再使用。 + 所以現在 d + 就和其他一般的分割區相同了。 - Each partition-that-contains-a-file-system is stored in what - FreeBSD calls a slice. Slice is FreeBSD's term - for what the common call partitions, and again, this is because of - FreeBSD's &unix; background. Slices are numbered, starting at 1, - through to 4. + 每個包含有檔案系統的分割區是存在所謂的 + slice 裡面。 + FreeBSD 的 slice 就是指平常我們稱為分割區 (partition) 的東西。 + 同樣地,會這樣子稱呼也是因為 FreeBSD 的 &unix; 色彩。 + 而 slice 是有編號的,從 1 號編到 4 號。 slices partitions dangerously dedicated - Slice numbers follow - the device name, prefixed with an s, - starting at 1. So da0s1 - is the first slice on the first SCSI drive. There can only be - four physical slices on a disk, but you can have logical - slices inside physical slices of the appropriate type. These - extended slices are numbered starting at 5, so - ad0s5 is the first - extended slice on the first IDE disk. These devices are used by file - systems that expect to occupy a slice. - - Slices, dangerously dedicated physical - drives, and other drives contain - partitions, which are represented as - letters from a to h. - This letter is appended to the device name, so - da0a is the a partition on - the first da drive, which is dangerously dedicated. - ad1s3e is the fifth partition - in the third slice of the second IDE disk drive. + slice 號碼跟在裝置名稱後面,先接一個字母 + s,然後從 1 號開始編下去。 + 因此 da0s1 就是指第一個 SCSI + 硬碟的第一個 slice。 一個磁碟上只能有四個實體的 slice,但是在實體的 + slice 中您可以塞進適當類型的邏輯 slice。 這些延伸的 slice 編號從 5 + 開始,所以 ad0s5 是第一個 IDE + 硬碟上的第一個延伸 slice。 檔案系統在裝置 (device) 裡就是在一個 slice + 之中。 + + Slices、dangerously dedicated + 模式的實體磁碟機,以及其他包含分割區(partition) + 的磁碟都是以字母 ah + 的編號來表示。 編號是接在裝置名稱的後面的,因此 + da0a 是磁碟機 da 上的第一個 + dangerously dedicated模式之分割區。 + 而 ad1s3e + 則是第二顆 IDE 硬碟上第三個 slice 的第五個分割區。 - Finally, each disk on the system is identified. A disk name - starts with a code that indicates the type of disk, and then a number, - indicating which disk it is. Unlike slices, disk numbering starts at - 0. Common codes that you will see are listed in - . - - When referring to a partition FreeBSD requires that you also name - the slice and disk that contains the partition, and when referring to - a slice you should also refer to the disk name. Do this by listing - the disk name, s, the slice number, and then the - partition letter. Examples are shown in - . - - shows a conceptual - model of the disk layout that should help make things clearer. - - In order to install FreeBSD you must first configure the disk - slices, then create partitions within the slice you will use for - FreeBSD, and then create a file system (or swap space) in each - partition, and decide where that file system will be mounted. + 最後,我們就可以把系統上的每個磁碟都區分出來了。 + 一個磁碟的名稱會有一個代碼來表示這個磁碟的類型,接著是一個數字, + 表示這是哪一個磁碟。 這邊跟 slice 每個磁碟編號從 0 開始不一樣。 + 常見的代碼可以參考 + + 當要參照一個分割區的時候,FreeBSD 會要您一併輸入包含這個分割區的 + slice 及磁碟機名稱;當要參照一個 slice 的時候,也必須輸入包含這個 + slice 的磁碟名稱。 怎麼做呢?首先先列出磁碟名稱,然後 + s 加上 slice 編號,最後再輸入分割區字母代號。 + 範例可以參考 . + + + 示範了一個基本的磁碟分布模式,相信對您有些幫助。 + + 要安裝 FreeBSD,您必須先建置磁碟的 slice,接著於 slice 中建立要給 + FreeBSD 用的分割區。 最後在這些分割區中建立檔案系統 (或 swap space) + 並決定要將這些檔案系統掛載於哪裡。 - Disk Device Codes + 磁碟機代號 - Code + 代號 - Meaning + 意義 ad - ATAPI (IDE) disk + ATAPI(IDE) 磁碟機 da - SCSI direct access disk + SCSI 直接存取磁碟機 acd - ATAPI (IDE) CDROM + ATAPI(IDE) 光碟機 cd - SCSI CDROM + SCSI 光碟機 fd - Floppy disk + 軟碟機
- Sample Disk, Slice, and Partition Names + 磁碟、slice 及分割區命名範例 - Name + 名稱 - Meaning + 意義 ad0s1a - The first partition (a) on the first - slice (s1) on the first IDE disk - (ad0). + 第一個 IDE 硬碟 (ad0) 上第一個 slice + (s1)的第一個分割區(a) + 。 da1s2e - - The fifth partition (e) on the - second slice (s2) on the second SCSI disk - (da1). + 第二個 SCSI 硬碟 (da1) 上第二個 slice + (s2) 的第五個分割區 (e) + 。 - Conceptual Model of a Disk + 磁碟的概念模型 - This diagram shows FreeBSD's view of the first IDE disk attached - to the system. Assume that the disk is 4 GB in size, and contains - two 2 GB slices (&ms-dos; partitions). The first slice contains a &ms-dos; - disk, C:, and the second slice contains a - FreeBSD installation. This example FreeBSD installation has three - partitions, and a swap partition. + 此圖顯示 FreeBSD 中接到系統的第一個 IDE 磁碟機內部配置圖。 + 假設這個磁碟的容量是 4 GB,並且包含了兩個 2 GB 的 + slice (&ms-dos; 的分割區)。 第一個 slice 是 DOS 的 + C: 磁碟機,第二個則安裝了 FreeBSD。 + 本範例的 FreeBSD 有三個分割區以及一個 swap 分割區。 - The three partitions will each hold a file system. Partition - a will be used for the root file system, - e for the /var directory - hierarchy, and f for the - /usr directory hierarchy. + 這三個分割區每個都是一個檔案系統。 + a 分割是根 (root) 檔案系統;分割 + e/var;而 + f 分割是 /usr + 目錄結構。 .-----------------. --. | | | | DOS / Windows | | -: : > First slice, ad0s1 +: : > First slice, ad0s1 : : | | | | :=================: ==: --. | | | Partition a, mounted as / | -| | > referred to as ad0s2a | +| | > referred to as ad0s2a | | | | | :-----------------: ==: | | | | Partition b, used as swap | -| | > referred to as ad0s2b | +| | > referred to as ad0s2b | | | | | :-----------------: ==: | Partition c, no -| | | Partition e, used as /var > file system, all -| | > referred to as ad0s2e | of FreeBSD slice, +| | | Partition e, used as /var > file system, all +| | > referred to as ad0s2e | of FreeBSD slice, | | | | ad0s2c :-----------------: ==: | | | | | : : | Partition f, used as /usr | : : > referred to as ad0s2f | : : | | | | | | | | --' | `-----------------' --'
- Mounting and Unmounting File Systems - - The file system is best visualized as a tree, - rooted, as it were, at /. - /dev, /usr, and the - other directories in the root directory are branches, which may - have their own branches, such as - /usr/local, and so on. - - root file system - There are various reasons to house some of these - directories on separate file systems. /var - contains the directories log/, - spool/, - and various types of temporary files, and - as such, may get filled up. Filling up the root file system - is not a good idea, so splitting /var from - / is often favorable. - - Another common reason to contain certain directory trees on - other file systems is if they are to be housed on separate - physical disks, or are separate virtual disks, such as Network File System mounts, or CDROM - drives. + 掛載與卸載檔案系統 + + 檔案系統就像一顆樹。/ + 就像是樹根,而 /dev/usr + 以及其他在根目錄下的目錄就像是樹枝,而這些樹枝上面又還有分支,像是 + /usr/local 等。 + + 根檔案系統 + 因為某些原因,我們會將一些目錄分別放在不同的檔案系統上。 + 如 /var 包含了可能會滿出來的 + log/spool/ + 等目錄以及各式各樣的暫存檔。 + 把根檔案系統塞到滿出來顯然不是個好主意,所以我們往往會比較傾向把 + /var/ 中拉出來。 + + 另一個常見到把某些目錄放在不同檔案系統上的理由是: + 這些檔案在不同的實體或虛擬磁碟機上。 + 像是網路檔案系統 + (Network File System) 或是光碟機。 - The <filename>fstab</filename> File + <filename>fstab</filename> 檔 - file systems - mounted with fstab + 檔案系統 file systems + 由fstab掛載 mounted with fstab - During the boot process, - file systems listed in /etc/fstab are - automatically mounted (unless they are listed with the - option). + /etc/fstab + 裡面有設定的檔案系統會在開機 + 的過程中自動地被掛載 + (除非該檔案系統有被加上 參數)。 - The /etc/fstab file contains a list - of lines of the following format: + /etc/fstab 檔案內容的格式如下: device /mount-point fstype options dumpfreq passno device - A device name (which should exist), as explained in + 裝置名稱 (該裝置必須真的存在)。 詳情請參閱 . mount-point - A directory (which should exist), on which - to mount the file system. + 檔案系統要掛載到的目錄 (該目錄必須真的存在)。 fstype - The file system type to pass to - &man.mount.8;. The default FreeBSD file system is - ufs. + + 檔案系統類型,這是要傳給 &man.mount.8; 的參數。 + FreeBSD 預設的檔案系統是 ufs options - Either for read-write - file systems, or for read-only - file systems, followed by any other options that may be - needed. A common option is for - file systems not normally mounted during the boot sequence. - Other options are listed in the &man.mount.8; manual page. + + 可讀可寫的檔案系統用 + ,而唯讀的檔案系統則是用 + ,後面視需要還可以加其他選項。 + 常見的選項如 + 是用在不要於開機過程中自動的掛載的檔案系統。 + 其他選項可參閱 &man.mount.8; 說明。 dumpfreq - This is used by &man.dump.8; to determine which - file systems require dumping. If the field is missing, - a value of zero is assumed. - - - - - passno - - - This determines the order in which file systems should - be checked. File systems that should be skipped should have - their passno set to zero. The root - file system (which needs to be checked before everything - else) should have its passno set to - one, and other file systems' passno - should be set to values greater than one. If more than one - file systems have the same passno then - &man.fsck.8; will attempt to check file systems in parallel - if possible. + + &man.dump.8; 由此項目決定那些檔案系統需要傾印。 + 如果這格空白則以零為預設值。 + + + + + passno + + + 這個項目決定檔案系統檢查的順序。 + 對於要跳過檢查的檔案系統,它們的 passno + 值要設為零。 根檔案系統的 passno 值應設為一 + (因為需要比所有其他的還要先檢查),而其他的檔案系統的 + passno 值應該要設得比一大。 + 若有多個檔案系統具有相同的 passno 值,則 + &man.fsck.8; 會試著平行地(如果可能的話)檢查這些檔案系統。 - Consult the &man.fstab.5; manual page for more information - on the format of the /etc/fstab file and - the options it contains. + 更多關於 /etc/fstab + 檔案格式及選項的資訊請參閱 &man.fstab.5; 說明文件。 - The <command>mount</command> Command + <command>mount</command> 指令 - file systems - mounting + 檔案系統 file systems + 掛載 mounting - The &man.mount.8; command is what is ultimately used to - mount file systems. + &man.mount.8; 指令是拿來掛載檔案系統用的。 - In its most basic form, you use: + 基本的操作指令格式如下: &prompt.root; mount device mountpoint - There are plenty of options, as mentioned in the - &man.mount.8; manual page, but the most common are: + 在 &man.mount.8; + 裡面有提到一大堆的選項,不過最常用的就是這些: - Mount Options + 掛載選項 - Mount all the file systems listed in - /etc/fstab. Except those - marked as noauto, excluded by the - flag, or those that are already - mounted. + /etc/fstab + 裡面所有還沒有被掛載、沒有被標記成 noauto + 而且沒有用 排除的檔案系統掛載起來。 - Do everything except for the actual mount system call. - This option is useful in conjunction with the - flag to determine what - &man.mount.8; is actually trying to do. + 執行所有的動作,但是不真的去呼叫掛載的 system call。 + 這個選項和 搭配拿來推測 &man.mount.8; + 將要做什麼動作時很好用。 - Force the mount of an unclean file system - (dangerous), or forces the revocation of write access - when downgrading a file system's mount status from - read-write to read-only. + 強迫掛載不乾淨的檔案系統 (危險),或是用來強制取消寫入權限 + (把檔案系統的掛載狀態從可存取變成唯讀)。 - Mount the file system read-only. This is identical - to using the ( - for &os; versions older than 5.2) argument to the - option. + 用唯讀的方式掛載檔案系統。 這個選項和在 + 選項中指定 (在 &os; 5.2之前的版本是用 + ) 參數是一樣的。 fstype - Mount the given file system as the given file system - type, or mount only file systems of the given type, if - given the option. + 用指定的檔案系統型態 (fstype) + 來掛載指定的檔案系統,或是在有 + 選項時只掛載指定型態的檔案系統。 - ufs is the default file system - type. + 預設的檔案系統是 ufs - Update mount options on the file system. + 更新檔案系統的掛載選項。 - Be verbose. + 顯示較詳細資訊。 - Mount the file system read-write. + 以可存取的模式掛載檔案系統。 - The option takes a comma-separated list of - the options, including the following: - + 選項後面會接著以逗號分隔的參數,例如: - - nodev - - - Do not interpret special devices on the - file system. This is a useful security option. - - - noexec - Do not allow execution of binaries on this - file system. This is also a useful security option. + 不允許在這個檔案系統上執行二進位程式碼, + 這也是一個蠻有用的安全選項。 nosuid - Do not interpret setuid or setgid flags on the - file system. This is also a useful security option. + 不解析檔案系統上的 setuid 或 setgid 旗標, + 這也是一個蠻有用的安全選項。 - The <command>umount</command> Command + <command>umount</command> 指令 - file systems - unmounting + 檔案系統 file systems + 卸載 unmounting - The &man.umount.8; command takes, as a parameter, one of a - mountpoint, a device name, or the or - option. - - All forms take to force unmounting, - and for verbosity. Be warned that - is not generally a good idea. Forcibly - unmounting file systems might crash the computer or damage data - on the file system. + &man.umount.8; 指令的參數可以是掛載點 + (mountpoint),裝置名稱,以及 或是 + 等選項。 + + 加上 可以強制卸載,加上 + 則是會顯示詳細資訊。 要注意的是一般來說用 + 並不是個好主意,強制卸載檔案系統有可能會造成電腦當機, + 或者損壞檔案系統內的資料。 - and are used to - unmount all mounted file systems, possibly modified by the - file system types listed after . - , however, does not attempt to unmount the - root file system. + + 是用來卸載所有已掛載的檔案系統,另外還可以用 + 來指定要卸載的是哪些種類的檔案系統。 要注意的是 + 並不會試圖卸載根檔案系統。 + - Processes - - FreeBSD is a multi-tasking operating system. This means that it - seems as though more than one program is running at once. Each program - running at any one time is called a process. - Every command you run will start at least one new process, and there are - a number of system processes that run all the time, keeping the system - functional. - - Each process is uniquely identified by a number called a - process ID, or PID, and, - like files, each process also has one owner and group. The owner and - group information is used to determine what files and devices the - process can open, using the file permissions discussed earlier. Most - processes also have a parent process. The parent process is the process - that started them. For example, if you are typing commands to the shell - then the shell is a process, and any commands you run are also - processes. Each process you run in this way will have your shell as its - parent process. The exception to this is a special process called - &man.init.8;. init is always the first - process, so its PID is always 1. init is started - automatically by the kernel when FreeBSD starts. - - Two commands are particularly useful to see the processes on the - system, &man.ps.1; and &man.top.1;. The ps command is used to - show a static list of the currently running processes, and can show - their PID, how much memory they are using, the command line they were - started with, and so on. The top command displays all the - running processes, and updates the display every few seconds, so that - you can interactively see what your computer is doing. - - By default, ps only shows you the commands that are running - and are owned by you. For example: - + 程序 + + FreeBSD 是一個多工的作業系統,也就是說在同一時間內可以跑超過一個程式。 + 每一個正在花時間跑的程式就叫做 程序 (process)。 + 您下的每個指令都至少會開啟一個新的程序, + 而有些系統程序是一直在跑以維持系統正常運作的。 + + 每一個程序都有一個不重覆的數字叫做 process ID + ,或稱為 PID + ,而且就像檔案一樣,每一個程序也有擁有者及群組。 + 擁有者及群組的資訊是用來決定什麼檔案或裝置是這個程序可以開啟的 + (前面有提到過檔案權限)。 大部份的程序都有父程序。 + 父程序是開啟這個程序的程序,例如:您對 shell 輸入指令,shell + 本身就是一個程序,而您執行的指令也是程序。 + 每一個您用這種方式跑的程序的父程序都是 shell。 + 有一個特別的程序叫做 &man.init.8; 是個例外。init + 永遠是第一個程序,所以他的 PID 一直都會是 1。 在 FreeBSD 開機的時候 + init 會自動地被 kernel 開啟。 + + 要看系統執行中的程序,有兩個相當有用的指令可用: + &man.ps.1; 以及 &man.top.1;。ps + 指令是用來列出正在執行之程序,而且可以秀它們的 + PID、用了多少記憶體、執行的指令名稱及其後之參數是什麼等等。 + top 指令則是顯示所有正在執行的程序, + 並且數秒鐘更新一次。因此您可以互動式的觀看您的電腦正在做什麼。 + + 在預設的情況下,ps + 指令只會顯示您所擁有的的程序。 例如: + &prompt.user; ps PID TT STAT TIME COMMAND 298 p0 Ss 0:01.10 tcsh 7078 p0 S 2:40.88 xemacs mdoc.xsl (xemacs-21.1.14) 37393 p0 I 0:03.11 xemacs freebsd.dsl (xemacs-21.1.14) 48630 p0 S 2:50.89 /usr/local/lib/netscape-linux/navigator-linux-4.77.bi 48730 p0 IW 0:00.00 (dns helper) (navigator-linux-) 72210 p0 R+ 0:00.00 ps 390 p1 Is 0:01.14 tcsh 7059 p2 Is+ 1:36.18 /usr/local/bin/mutt -y 6688 p3 IWs 0:00.00 tcsh 10735 p4 IWs 0:00.00 tcsh 20256 p5 IWs 0:00.00 tcsh 262 v0 IWs 0:00.00 -tcsh (tcsh) 270 v0 IW+ 0:00.00 /bin/sh /usr/X11R6/bin/startx -- -bpp 16 280 v0 IW+ 0:00.00 xinit /home/nik/.xinitrc -- -bpp 16 284 v0 IW 0:00.00 /bin/sh /home/nik/.xinitrc 285 v0 S 0:38.45 /usr/X11R6/bin/sawfish - As you can see in this example, the output from &man.ps.1; is - organized into a number of columns. PID is the - process ID discussed earlier. PIDs are assigned starting from 1, go up - to 99999, and wrap around back to the beginning when you run out. - The TT column shows the tty the program is running on, and can - safely be ignored for the moment. STAT shows the - program's state, and again, can be safely ignored. - TIME is the amount of time the program has been - running on the CPU—this is usually not the elapsed time since - you started the program, as most programs spend a lot of time waiting - for things to happen before they need to spend time on the CPU. - Finally, COMMAND is the command line that was used to - run the program. - - &man.ps.1; supports a number of different options to change the - information that is displayed. One of the most useful sets is - auxww. displays information - about all the running processes, not just your own. - displays the username of the process' owner, as well as memory usage. - displays information about daemon processes, and - causes &man.ps.1; to display the full command line, - rather than truncating it once it gets too long to fit on the - screen. - - The output from &man.top.1; is similar. A sample session looks like - this: + 在這個範例裡可以看到 &man.ps.1; 的輸出分成好幾個欄位。 + PID 就是前面有提到的 process ID。 PID 的分配是從 + 1 開始一直到 99999,如果用完的話又會繞回來重頭開始分配 + (若該 PID 已經在用了,則 PID 不會重新分配)。 + TT 欄位是指這個程式在哪個 tty + 上執行,在這裡可以先忽略不管。STAT + 是程式的狀態,也可以先不要管。TIME 是這個程式在 + CPU 上執行的時間—這通常不是程式總共花的時間, + 因為當您開始執行程式後,大部份的程式在 CPU 上執行前會先花上不少時間等待 + 。 最後,COMMAND 是執行這個程式的命令列。 + + &man.ps.1; + 有幾個不同的選項組合可以用來變更顯示出來的資訊,其中一個最有用的組合是 + auxww。 + 可以顯示所有正在跑的程序的指令,不只是您自已的。 + 則是顯示程序的擁有者名稱以及記憶體使用情況。 + 可以把 daemon 程序顯示出來, + 而 可讓 &man.ps.1; 顯示出每個程序完整的內容, + 而不致因過長而被螢幕截掉了。 + + &man.top.1; 也有類似的輸出。 一般的情況看像是這樣: &prompt.user; top last pid: 72257; load averages: 0.13, 0.09, 0.03 up 0+13:38:33 22:39:10 47 processes: 1 running, 46 sleeping CPU states: 12.6% user, 0.0% nice, 7.8% system, 0.0% interrupt, 79.7% idle Mem: 36M Active, 5256K Inact, 13M Wired, 6312K Cache, 15M Buf, 408K Free Swap: 256M Total, 38M Used, 217M Free, 15% Inuse PID USERNAME PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND 72257 nik 28 0 1960K 1044K RUN 0:00 14.86% 1.42% top 7078 nik 2 0 15280K 10960K select 2:54 0.88% 0.88% xemacs-21.1.14 281 nik 2 0 18636K 7112K select 5:36 0.73% 0.73% XF86_SVGA 296 nik 2 0 3240K 1644K select 0:12 0.05% 0.05% xterm 48630 nik 2 0 29816K 9148K select 3:18 0.00% 0.00% navigator-linu 175 root 2 0 924K 252K select 1:41 0.00% 0.00% syslogd 7059 nik 2 0 7260K 4644K poll 1:38 0.00% 0.00% mutt ... - The output is split into two sections. The header (the first five - lines) shows the PID of the last process to run, the system load averages - (which are a measure of how busy the system is), the system uptime (time - since the last reboot) and the current time. The other figures in the - header relate to how many processes are running (47 in this case), how - much memory and swap space has been taken up, and how much time the - system is spending in different CPU states. - - Below that are a series of columns containing similar information - to the output from &man.ps.1;. As before you can see the PID, the - username, the amount of CPU time taken, and the command that was run. - &man.top.1; also defaults to showing you the amount of memory space - taken by the process. This is split into two columns, one for total - size, and one for resident size—total size is how much memory the - application has needed, and the resident size is how much it is actually - using at the moment. In this example you can see that &netscape; has - required almost 30 MB of RAM, but is currently only using 9 MB. - - &man.top.1; automatically updates this display every two seconds; - this can be changed with the option. + 輸出的資訊分成兩個部份。開頭 (前五行) 秀出最近一個程序的 + PID、系統平均負載 (系統有多忙錄的測試)、系統的開機時間 + (從上次重開算起) 以及現在的時間等。 + 在開頭裡面的其他數字分別是在講有多少程序正在執行 + (在本例中為47)、有多少記憶體及 swap space + 被占用了,還有就是系統分別花了多少時間在不同的 CPU 狀態上。 + + 接下來的部份是由好幾個欄位所構成,和 &man.ps.1; 輸出的資訊類似。 + 就如同前例,您可以看到 PID、使用者名稱、CPU + 花費的時間以及正在執行的指令。 &man.top.1; + 在預設的情況下還會告訴您程序用掉了多少的記憶體空間。 + 在這邊會分成兩欄,一個是總用量 (total size),另一個是實際用量 + (resident size)—總用量是指這個應用程式需要的記憶體空間, + 而實際用量則是指實際上該程式的記憶體使用量。 + 在這個例子裡面您可以看到 &netscape; + 要了幾乎到 30 MB 的 RAM,但是只有用到 9 MB。 + + &man.top.1; 每隔 2 秒鐘會自動更新顯示內容,可用 + 選項來改變間隔的時間。 + - Daemons, Signals, and Killing Processes - - When you run an editor it is easy to control the editor, tell it to - load files, and so on. You can do this because the editor provides - facilities to do so, and because the editor is attached to a - terminal. Some programs are not designed to be - run with continuous user input, and so they disconnect from the terminal - at the first opportunity. For example, a web server spends all day - responding to web requests, it normally does not need any input from - you. Programs that transport email from site to site are another - example of this class of application. - - We call these programs daemons. Daemons were - characters in Greek mythology; neither good or evil, they were little - attendant spirits that, by and large, did useful things for mankind. - Much like the web servers and mail servers of today do useful things. - This is why the BSD mascot has, for a long time, been the cheerful - looking daemon with sneakers and a pitchfork. - - There is a convention to name programs that normally run as daemons - with a trailing d. BIND is the - Berkeley Internet Name Daemon (and the actual program that executes is called - named), the Apache web - server program is called httpd, the line printer - spooling daemon is lpd and so on. This is a - convention, not a hard and fast rule; for example, the main mail daemon - for the Sendmail application is called - sendmail, and not maild, as you - might imagine. - - Sometimes you will need to communicate with a daemon process. These - communications are called signals, and you can - communicate with a daemon (or with any other running process) by sending it a - signal. There are a number of different signals that you can - send—some of them have a specific meaning, others are interpreted - by the application, and the application's documentation will tell you - how that application interprets signals. You can only send a signal to - a process that you own. If you send a signal to someone else's - process with &man.kill.1; or &man.kill.2; permission will be denied. - The exception to this is the - root user, who can send signals to everyone's - processes. - - FreeBSD will also send applications signals in some cases. If an - application is badly written, and tries to access memory that it is not - supposed to, FreeBSD sends the process the Segmentation - Violation signal (SIGSEGV). If an - application has used the &man.alarm.3; system call to be alerted after a - period of time has elapsed then it will be sent the Alarm signal - (SIGALRM), and so on. - - Two signals can be used to stop a process, - SIGTERM and SIGKILL. - SIGTERM is the polite way to kill a process; the - process can catch the signal, realize that you want - it to shut down, close any log files it may have open, and generally - finish whatever it is doing at the time before shutting down. In some - cases a process may even ignore SIGTERM if it is in - the middle of some task that can not be interrupted. - - SIGKILL can not be ignored by a process. This is - the I do not care what you are doing, stop right now - signal. If you send SIGKILL to a process then - FreeBSD will stop that process there and then - Not quite true—there are a few things that can not be - interrupted. For example, if the process is trying to read from a - file that is on another computer on the network, and the other - computer has gone away for some reason (been turned off, or the - network has a fault), then the process is said to be - uninterruptible. Eventually the process will time - out, typically after two minutes. As soon as this time out occurs - the process will be killed. - . - - The other signals you might want to use are - SIGHUP, SIGUSR1, and - SIGUSR2. These are general purpose signals, and - different applications will do different things when they are - sent. - - Suppose that you have changed your web server's configuration - file—you would like to tell the web server to re-read its - configuration. You could stop and restart httpd, but - this would result in a brief outage period on your web server, which may - be undesirable. Most daemons are written to respond to the - SIGHUP signal by re-reading their configuration - file. So instead of killing and restarting httpd you - would send it the SIGHUP signal. Because there is no - standard way to respond to these signals, different daemons will have - different behavior, so be sure and read the documentation for the - daemon in question. + Daemon、信號及終止程序 + + 當在執行文書編輯器時,您可以很容易地使用它,叫它讀取檔案或是什麼的。 + 可以這樣做是因為編輯器有提供這些功能, + 還有就是編輯器依附在一個終端機 (Terminal) 之上。 + 有些程式並不是設計成一直在接收使用者的輸入的, + 所以它們在一開始執行的時候就從終端機斷開了。 例如說, + 網頁伺服器整天都在回應網頁方面的要求,它通常不需要您輸入任何東西。 + 另外,像是把信從一個站傳送到另一個站的程式,也是這種類型的應用程式。 + + + 我們把這種程式稱作 daemon。 + Daemon (惡魔、守護神) + 是希臘神話中的角色:祂們不屬於善良陣營或邪惡陣營,是守護的小精靈。 + 大致上來說祂們就是在替人類做一些有用的事情, + 跟今天的網頁伺服器或是郵件伺服器很像。 這也就是為何 BSD + 的吉祥物,長期以來都是一隻穿著帆布鞋拿著三叉耙的快樂小惡魔的原因。 + + 通常來說 deamon 程式的名字後面都會加一個字母 d。 + BIND 是 Berkeley Internet Name Domain + 的縮寫 (但實際上執行的程式名稱是 named)、Apache + 網頁伺服器的程式名稱是 httpd、印表機服務程式是 + lpd,依此類推。 + 這是習慣用法,並沒有硬性規定,例如 Sendmail + 主要的寄信 daemon 是叫做 sendmail 而不是 + maild,跟您想像的不一樣。 + + 有些時候會需要跟某個 daemon 程序溝通, + 這些溝通是透過所謂的信號(signal)來傳遞給該 daemon + 程序(或是其他執行中的程序)。 + 藉由送出信號,您可以和一個 daemon (或是任何一個正在跑的程序) 溝通。 + 信號有很多種—有些有特定的意義,有些則是會由應用程式來解讀。 + 應用程式的說明文件會告訴您該程式是如何解讀信號的。 + 您只能送信號給您擁有的程序,送 &man.kill.1; 或 &man.kill.2; + 的信號給別人的程序是不被允許的。 不過 root + 不受此限制,他可以送信號給任何人的程序。 + + FreeBSD 本身在某些情況也會送信號給應用程式。 + 假設有個應用程式寫得很爛,然後企圖要存取它不該碰的記憶體的時候,FreeBSD + 會送一個 Segmentation Violation 信號 + (SIGSEGV) 給這個程序。 + 又如果有一個應用程式用了 &man.alarm.3; 的 system call + 要求系統在過一段時間之後叫他一下,時間到了的時候鬧鐘的信號 + (SIGALRM) 就會被送出了,其他的依此類推。 + + SIGTERM and SIGKILL + 這兩個信號可以拿來終止程序。 用 SIGTERM + 結束程序是比較有禮貌的方式,該程序會捕捉 (catch) + 這個信號而了解到您想要把他關掉。 接著下來它會把它自已開的記錄檔通通關掉, + 然後在關掉程序之前結束掉手邊的工作。 在某些情況下程序有可能會裝作沒看見 + SIGTERM,假如它正在做一些不能中斷的工作的話。 + + SIGKILL 就沒有辦法被程序忽略了。 + 這是一個我管你正在幹嘛,現在就給我停下來的信號。 + 如果您送了 SIGKILL 信號給某個程序,FreeBSD + 將會把它停掉 + 不完全正確—還是有少數東西不能被中斷。 + 例如有個程序正在從網路上的別的電腦讀一個檔案, + 而那部電腦因為某些理由連不到 (機器被關掉,或是網路爛掉了), + 那這個程序我們就說他是一個不能中斷的程序。 + 通常在經過兩分鐘左右之後這個程序會逾時。 + 當發生逾時的時候這個程序就會被結束掉了。 + + + 這些是其他您有可能會要用到的信號: + SIGHUPSIGUSR1,以及 + SIGUSR2。 + 這些是通用的信號,當送出時不同的應用程式會有不同的反應。 + + 假設您更動了您的網頁伺服器的設定檔— + 您想要叫網頁伺服器去重新讀取設定值。 您可以關閉後再重新啟動 + httpd,但是這麼做會造成網頁伺服器暫停服務一段時間, + 這樣子可能不太好。 + 大部份的 daemon 都寫成會去回應 SIGHUP。 + 當收到這個信號之後,它們會去重新讀取自已的設定檔。 + 因此您可以用送 SIGHUP 信號來取代關掉重開。 + 又因為沒有標準在規範如何回應這些信號,不同的 daemon + 可能會有不同的行為,所以有疑問的話請先確認並翻閱 deamon + 的說明文件。 + + 信號是由 &man.kill.1; 指令送出的,如範例所示: - Signals are sent using the &man.kill.1; command, as this example - shows. - - Sending a Signal to a Process + 送信號給程序 - This example shows how to send a signal to &man.inetd.8;. The - inetd configuration file is - /etc/inetd.conf, and inetd will re-read - this configuration file when it is sent - SIGHUP. + 這個範例將會示範如何送一個信號給 &man.inetd.8;。 + inetd 的設定檔是 + /etc/inetd.conf,而 inetd + 會在收到 SIGHUP 的時候重新讀取這個設定檔。 - Find the process ID of the process you want to send the signal - to. Do this using &man.ps.1; and &man.grep.1;. The &man.grep.1; - command is used to search through output, looking for the string you - specify. This command is run as a normal user, and &man.inetd.8; is - run as root, so the options - must be given to &man.ps.1;. - - &prompt.user; ps -ax | grep inetd + 找出您想要送信號的那個程序的 ID。 您會用到 &man.ps.1; 以及 + &man.grep.1; 這兩個指令。 &man.grep.1; 是用來在輸出中搜尋, + 找出您指定的字串。 這個指令是由一般使用者執行,而 &man.inetd.8; + 是由 root 執行,所以在使用 &man.ps.1; 時需要加上 + 選項。 + + &prompt.user; ps -ax | grep inetd 198 ?? IWs 0:00.00 inetd -wW - So the &man.inetd.8; PID is 198. In some cases the - grep inetd command might also occur in this - output. This is because of the way &man.ps.1; has to find the list - of running processes. + 因此可知 &man.inetd.8; 的 PID 為 198。 在某些情況下 + grep inetd 這個指令本身也會出現在輸出裡。 + 這是因為 &man.ps.1; 乃是找所有執行中的程序的方式造成的。 - Use &man.kill.1; to send the signal. Because &man.inetd.8; is - being run by root you must use &man.su.1; to - become root first. + 用 &man.kill.1; 來送信號。 又因為 &man.inetd.8; 是由 + root 執行的,您必須用 &man.su.1; 切換成 + root先。 &prompt.user; su Password: &prompt.root; /bin/kill -s HUP 198 - In common with most &unix; commands, &man.kill.1; will not print any - output if it is successful. If you send a signal to a - process that you do not own then you will see kill: - PID: Operation not - permitted. If you mistype the PID you will either - send the signal to the wrong process, which could be bad, or, if - you are lucky, you will have sent the signal to a PID that is not - currently in use, and you will see kill: - PID: No such process. + 一般情況對大多數 &unix; 指令來講,當 &man.kill.1; + 執行成功時並不會輸出任何訊息。 + 假設您送一個信號給某個不是您所擁有的程序, + 那麼您就會吃到這個錯誤訊息: kill: + PID: Operation not permitted。 + 而如果您打錯 PID 的話,那就會把信號送給錯誤的程序。 這樣可能會很糟, + 不過如果您夠幸運的話,可能剛好就只是把信號送給一個非使用中的 + PID,那您就只會看到 kill: + PID: No such process 而已。 + - Why Use <command>/bin/kill</command>? - - Many shells provide the kill command as a - built in command; that is, the shell will send the signal - directly, rather than running /bin/kill. - This can be very useful, but different shells have a different - syntax for specifying the name of the signal to send. Rather than - try to learn all of them, it can be simpler just to use the - /bin/kill ... - command directly. + 為什麼用 <command>/bin/kill</command>? + + 很多 shell 有提供內建的 kill 指令。 + 也就是說這種 shell 會直接送信號,而不是執行 + /bin/kill。 + 這樣是蠻方便的沒錯啦,但是不同的 shell + 會有不同的語法來指定信號的名稱等。 + 與其嘗試去把它們通通學會,不如就單純的直接用 /bin/kill + ... 吧。 - Sending other signals is very similar, just substitute - TERM or KILL in the command line - as necessary. - + 要送其他的信號的話也是非常類似,就視需要把指令中的 + TERMKILL + 替換掉即可。 + - Killing random process on the system can be a bad idea. In - particular, &man.init.8;, process ID 1, is very special. Running - /bin/kill -s KILL 1 is a quick way to shutdown your - system. Always double check the arguments you - run &man.kill.1; with before you press - Return. + 隨便抓一個系統中的程序然後把他砍掉並不是個好主意。 + 特別是 &man.init.8;, process ID 1,一個非常特別的程序。 + 執行 /bin/kill -s KILL 1 + 的結果就是系統立刻關機。 因此在您按下 Return + 要執行 &man.kill.1;之前, + 請一定要記得再次確認您下的參數。 Shells shells command line In FreeBSD, a lot of everyday work is done in a command line interface called a shell. A shell's main job is to take commands from the input channel and execute them. A lot of shells also have built in functions to help everyday tasks such as file management, file globbing, command line editing, command macros, and environment variables. FreeBSD comes with a set of shells, such as sh, the Bourne Shell, and tcsh, the improved C-shell. Many other shells are available from the FreeBSD Ports Collection, such as zsh and bash. Which shell do you use? It is really a matter of taste. If you are a C programmer you might feel more comfortable with a C-like shell such as tcsh. If you have come from Linux or are new to a &unix; command line interface you might try bash. The point is that each shell has unique properties that may or may not work with your preferred working environment, and that you have a choice of what shell to use. One common feature in a shell is filename completion. Given the typing of the first few letters of a command or filename, you can usually have the shell automatically complete the rest of the command or filename by hitting the Tab key on the keyboard. Here is an example. Suppose you have two files called foobar and foo.bar. You want to delete foo.bar. So what you would type on the keyboard is: rm fo[Tab].[Tab]. The shell would print out rm foo[BEEP].bar. The [BEEP] is the console bell, which is the shell telling me it was unable to totally complete the filename because there is more than one match. Both foobar and foo.bar start with fo, but it was able to complete to foo. If you type in ., then hit Tab again, the shell would be able to fill in the rest of the filename for you. environment variables Another feature of the shell is the use of environment variables. - Environment variables are a variable key pair stored in the shell's + Environment variables are a variable/key pair stored in the shell's environment space. This space can be read by any program invoked by the shell, and thus contains a lot of program configuration. Here is a list of common environment variables and what they mean: environment variables Variable Description USER Current logged in user's name. PATH - Colon separated list of directories to search for + Colon-separated list of directories to search for binaries. DISPLAY Network name of the X11 display to connect to, if available. SHELL The current shell. TERM - The name of the user's terminal. Used to determine the - capabilities of the terminal. + The name of the user's type of terminal. Used to determine + the capabilities of the terminal. TERMCAP Database entry of the terminal escape codes to perform various terminal functions. OSTYPE Type of operating system. e.g., FreeBSD. MACHTYPE The CPU architecture that the system is running on. EDITOR The user's preferred text editor. PAGER The user's preferred text pager. MANPATH - Colon separated list of directories to search for + Colon-separated list of directories to search for manual pages. Bourne shells Setting an environment variable differs somewhat from shell to shell. For example, in the C-Style shells such as tcsh and csh, you would use setenv to set environment variables. Under Bourne shells such as sh and bash, you would use export to set your current environment variables. For example, to set or modify the EDITOR environment variable, under csh or tcsh a command like this would set EDITOR to /usr/local/bin/emacs: &prompt.user; setenv EDITOR /usr/local/bin/emacs Under Bourne shells: &prompt.user; export EDITOR="/usr/local/bin/emacs" You can also make most shells expand the environment variable by placing a $ character in front of it on the command line. For example, echo $TERM would print out whatever $TERM is set to, because the shell expands $TERM and passes it on to echo. Shells treat a lot of special characters, called meta-characters as special representations of data. The most common one is the * character, which represents any number of characters in a filename. These special meta-characters can be used to do filename globbing. For example, typing in echo * is almost the same as typing in ls because the shell takes all the files that match * and puts them on the command line for echo to see. To prevent the shell from interpreting these special characters, they can be escaped from the shell by putting a backslash (\) character in front of them. echo $TERM prints whatever your terminal is set to. echo \$TERM prints $TERM as is. Changing Your Shell The easiest way to change your shell is to use the chsh command. Running chsh will place you into the editor that is in your EDITOR environment variable; if it is not set, you will be placed in vi. Change the Shell: line accordingly. You can also give chsh the option; this will set your shell for you, without requiring you to enter an editor. For example, if you wanted to change your shell to bash, the following should do the trick: &prompt.user; chsh -s /usr/local/bin/bash The shell that you wish to use must be present in the /etc/shells file. If you have installed a shell from the ports collection, then this should have been done for you already. If you installed the shell by hand, you must do this. For example, if you installed bash by hand and placed it into /usr/local/bin, you would want to: &prompt.root; echo "/usr/local/bin/bash" >> /etc/shells Then rerun chsh. - Text Editors + 文字編輯器 text editors editors A lot of configuration in FreeBSD is done by editing text files. Because of this, it would be a good idea to become familiar with a text editor. FreeBSD comes with a few as part of the base system, and many more are available in the Ports Collection. ee editors ee The easiest and simplest editor to learn is an editor called ee, which stands for easy editor. To start ee, one would type at the command line ee filename where filename is the name of the file to be edited. For example, to edit /etc/rc.conf, type in ee /etc/rc.conf. Once inside of ee, all of the commands for manipulating the editor's functions are listed at the top of the display. The caret ^ character represents the Ctrl key on the keyboard, so ^e expands to the key combination Ctrle. To leave ee, hit the Esc key, then choose leave editor. The editor will prompt you to save any changes if the file has been modified. vi editors vi emacs editors emacs FreeBSD also comes with more powerful text editors such as vi as part of the base system, while other editors, like Emacs and vim, are part of the FreeBSD Ports Collection (editors/emacs and editors/vim). These editors offer much more functionality and power at the expense of being a little more complicated to learn. However if you plan on doing a lot of text editing, learning a more powerful editor such as vim or Emacs will save you much more time in the long run. Devices and Device Nodes A device is a term used mostly for hardware-related activities in a system, including disks, printers, graphics cards, and keyboards. When FreeBSD boots, the majority of what FreeBSD displays are devices being detected. You can look through the boot messages again by viewing /var/run/dmesg.boot. For example, acd0 is the first IDE CDROM drive, while kbd0 represents the keyboard. Most of these devices in a &unix; operating system must be accessed through special files called device nodes, which are located in the /dev directory. Creating Device Nodes When adding a new device to your system, or compiling - in support for additional devices, you may need to create one or - more device nodes for the new devices. - - - MAKEDEV Script - On systems without DEVFS (this concerns all FreeBSD versions before 5.0), device nodes are created - using the &man.MAKEDEV.8; script as shown below: - - &prompt.root; cd /dev -&prompt.root; sh MAKEDEV ad1 - - - This example would make the proper device nodes - for the second IDE drive when installed. - + in support for additional devices, new device nodes must + be created. <literal>DEVFS</literal> (DEVice File System) - The device file system, or DEVFS, provides access to + The device file system, or DEVFS, provides access to kernel's device namespace in the global file system namespace. Instead of having to create and modify device nodes, DEVFS maintains this particular file system for you. See the &man.devfs.5; manual page for more information. - - DEVFS is used by default in FreeBSD 5.0 and above. Binary Formats To understand why &os; uses the &man.elf.5; format, you must first know a little about the three currently dominant executable formats for &unix;: &man.a.out.5; The oldest and classic &unix; object format. It uses a short and compact header with a magic number at the beginning that is often used to characterize the format (see &man.a.out.5; for more details). It contains three loaded segments: .text, .data, and .bss plus a symbol table and a string table. COFF The SVR3 object format. The header now comprises a section table, so you can have more than just .text, .data, and .bss sections. &man.elf.5; The successor to COFF, featuring multiple sections and 32-bit or 64-bit possible values. One major drawback: ELF was also designed with the assumption that there would be only one ABI per system architecture. That assumption is actually quite incorrect, and not even in the commercial SYSV world (which has at least three ABIs: SVR4, Solaris, SCO) does it hold true. FreeBSD tries to work around this problem somewhat by providing a utility for branding a known ELF executable with information about the ABI it is compliant with. See the manual page for &man.brandelf.1; for more information. FreeBSD comes from the classic camp and used the &man.a.out.5; format, a technology tried and proven through many generations of BSD releases, until the beginning of the 3.X branch. Though it was possible to build and run native ELF binaries (and kernels) on a FreeBSD system for some time before that, FreeBSD initially resisted the push to switch to ELF as the default format. Why? Well, when the Linux camp made their painful transition to ELF, it was not so much to flee the a.out executable format as it was their inflexible jump-table based shared library mechanism, which made the construction of shared libraries very difficult for vendors and developers alike. Since the ELF tools available offered a solution to the shared library problem and were generally seen as the way forward anyway, the migration cost was accepted as necessary and the transition made. FreeBSD's shared library mechanism is based more closely on Sun's &sunos; style shared library mechanism and, as such, is very easy to use. So, why are there so many different formats? Back in the dim, dark past, there was simple hardware. This simple hardware supported a simple, small system. a.out was completely adequate for the job of representing binaries on this simple system (a PDP-11). As people ported &unix; from this simple system, they retained the a.out format because it was sufficient for the early ports of &unix; to architectures like the Motorola 68k, VAXen, etc. Then some bright hardware engineer decided that if he could force software to do some sleazy tricks, then he would be able to shave a few gates off the design and allow his CPU core to run faster. While it was made to work with this new kind of hardware (known these days as RISC), a.out was ill-suited for this hardware, so many formats were developed to get to a better performance from this hardware than the limited, simple a.out format could offer. Things like COFF, ECOFF, and a few obscure others were invented and their limitations explored before things seemed to settle on ELF. In addition, program sizes were getting huge and disks (and physical memory) were still relatively small so the concept of a shared library was born. The VM system also became more sophisticated. While each one of these advancements was done using the a.out format, its usefulness was stretched more and more with each new feature. In addition, people wanted to dynamically load things at run time, or to junk parts of their program after the init code had run to save in core memory and swap space. Languages became more sophisticated and people wanted code called before main automatically. Lots of hacks were done to the a.out format to allow all of these things to happen, and they basically worked for a time. In time, a.out was not up to handling all these problems without an ever increasing overhead in code and complexity. While ELF solved many of these problems, it would be painful to switch from the system that basically worked. So ELF had to wait until it was more painful to remain with a.out than it was to migrate to ELF. However, as time passed, the build tools that FreeBSD derived their build tools from (the assembler and loader especially) evolved in two parallel trees. The FreeBSD tree added shared libraries and fixed some bugs. The GNU folks that originally wrote these programs rewrote them and added simpler support for building cross compilers, plugging in different formats at will, and so on. Since many people wanted to build cross compilers targeting FreeBSD, they were out of luck since the older sources that FreeBSD had for as and ld were not up to the task. The new GNU tools chain (binutils) does support cross compiling, ELF, shared libraries, C++ extensions, etc. In addition, many vendors are releasing ELF binaries, and it is a good thing for FreeBSD to run them. ELF is more expressive than a.out and allows more extensibility in the base system. The ELF tools are better maintained, and offer cross compilation support, which is important to many people. ELF may be a little slower than a.out, but trying to measure it can be difficult. There are also numerous details that are different between the two in how they map pages, handle init code, etc. None of these are very important, but they are differences. In time support for a.out will be moved out of the GENERIC kernel, and eventually removed from the kernel once the need to run legacy a.out programs is past. - For More Information + 更多資訊 Manual Pages manual pages The most comprehensive documentation on FreeBSD is in the form of manual pages. Nearly every program on the system comes with a short reference manual explaining the basic operation and various arguments. These manuals can be viewed with the man command. Use of the man command is simple: &prompt.user; man command command is the name of the command you wish to learn about. For example, to learn more about ls command type: &prompt.user; man ls The online manual is divided up into numbered sections: User commands. System calls and error numbers. Functions in the C libraries. Device drivers. File formats. Games and other diversions. Miscellaneous information. System maintenance and operation commands. Kernel developers. In some cases, the same topic may appear in more than one section of the online manual. For example, there is a chmod user command and a chmod() system call. In this case, you can tell the man command which one you want by specifying the section: &prompt.user; man 1 chmod This will display the manual page for the user command chmod. References to a particular section of the online manual are traditionally placed in parenthesis in written documentation, so &man.chmod.1; refers to the chmod user command and &man.chmod.2; refers to the system call. This is fine if you know the name of the command and simply wish to know how to use it, but what if you cannot recall the command name? You can use man to search for keywords in the command descriptions by using the switch: &prompt.user; man -k mail With this command you will be presented with a list of commands that have the keyword mail in their descriptions. This is actually functionally equivalent to using the apropos command. So, you are looking at all those fancy commands in /usr/bin but do not have the faintest idea what most of them actually do? Simply do: &prompt.user; cd /usr/bin &prompt.user; man -f * or &prompt.user; cd /usr/bin &prompt.user; whatis * which does the same thing. GNU Info Files Free Software Foundation FreeBSD includes many applications and utilities produced by the Free Software Foundation (FSF). In addition to manual pages, these programs come with more extensive hypertext documents called info files which can be viewed with the info command or, if you installed emacs, the info mode of emacs. To use the &man.info.1; command, simply type: &prompt.user; info For a brief introduction, type h. For a quick command reference, type ?.