Copyright © 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 FreeBSD 文件計畫
歡迎使用FreeBSD! 本使用手冊涵蓋範圍包括了 FreeBSD 6.4-RELEASE 和 FreeBSD 7.2-RELEASE 的安裝和日常使用。 這份使用手冊是很多人的集體創作,而且仍然『持續不斷』的進行中。 許多章節仍未完成,已完成的部份也有些需要更新。 如果您有興趣協助本計畫的話,請寄 e-mail 到 FreeBSD documentation project 郵遞論壇。 在 FreeBSD 網站 可以找到這份文件的最新版本(舊版文件可從 http://docs.FreeBSD.org/doc/ 取得),也可以從 FreeBSD FTP 伺服器 或是眾多 mirror 站臺 下載不同格式的資料。 如果比較偏好實體書面資料,那可以在 FreeBSD Mall 購買。 此外,也可以在 使用手冊 中搜尋資料。
Redistribution and use in source (SGML DocBook) and 'compiled' forms (SGML, HTML, PDF, PostScript, RTF and so forth) with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code (SGML DocBook) must retain the above copyright notice, this list of conditions and the following disclaimer as the first lines of this file unmodified.
Redistributions in compiled form (transformed to other DTDs, converted to PDF, PostScript, RTF and other formats) must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Important: THIS DOCUMENTATION IS PROVIDED BY THE FREEBSD DOCUMENTATION PROJECT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD DOCUMENTATION PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
FreeBSD 是 FreeBSD基金會的註冊商標
3Com 和 HomeConnect 是 3Com Corporation 的註冊商標。
3ware 和 Escalade 是 3ware Inc 的註冊商標。
ARM 是 ARM Limited. 的註冊商標。
Adaptec 是 Adaptec, Inc. 的註冊商標。
Adobe, Acrobat, Acrobat Reader, 以及 PostScript 是 Adobe Systems Incorporated 在美國和/或其他國家的商標或註冊商標。
Apple, AirPort, FireWire, Mac, Macintosh, Mac OS, Quicktime, 以及 TrueType 是 Apple Computer, Inc. 在美國以及其他國家的註冊商標。
Corel 和 WordPerfect 是 Corel Corporation 和/或其子公司在加拿大、美國和/或其他國家的註冊商標。
Sound Blaster 是 Creative Technology Ltd. 在美國和/或其他國家的註冊商標。
CVSup 是 John D. Polstra 的註冊商標。
Heidelberg, Helvetica, Palatino, 和 Times Roman 是 Heidelberger Druckmaschinen AG 在美國以及其他國家的商標或註冊商標。
IBM, AIX, EtherJet, Netfinity, OS/2, PowerPC, PS/2, S/390, 和 ThinkPad 是 國際商用機器公司在美國和其他國家的註冊商標或商標。
IEEE, POSIX, 和 802 是 Institute of Electrical and Electronics Engineers, Inc. 在美國的註冊商標。
Intel, Celeron, EtherExpress, i386, i486, Itanium, Pentium, 和 Xeon 是 Intel Corporation 及其分支機構在美國和其他國家的商標或註冊商標。
Intuit 和 Quicken 是 Intuit Inc., 或其子公司在美國和其他國家的商標或註冊商標。
Linux 是 Linus Torvalds 的註冊商標。
LSI Logic, AcceleRAID, eXtremeRAID, MegaRAID 和 Mylex 是 LSI Logic Corp 的商標或註冊商標。
M-Systems 和 DiskOnChip 是 M-Systems Flash Disk Pioneers, Ltd. 的商標或註冊商標。
Macromedia, Flash, 以及 Shockwave Macromedia, Inc. 在美國和/或其他國家的商標或註冊商標。
Microsoft, IntelliMouse, MS-DOS, Outlook, Windows, Windows Media, 和 Windows NT 是 Microsoft Corporation 在美國和/或其他國家的商標或註冊商標。
Netscape 以及 Netscape Navigator 是 Netscape Communications Corporation 在美國和其他國家的註冊商標。
GateD 和 NextHop 是 NextHop 在美國和其他國家的商標或註冊商標。
Motif, OSF/1, 和 UNIX 是 The Open Group 在美國和其他國家的註冊商標; IT DialTone 和 The Open Group 是其商標。
Oracle 是 Oracle Corporation 的註冊商標。
PowerQuest 和 PartitionMagic 是 PowerQuest Corporation 在美國和/或其他國家的註冊商標。
RealNetworks, RealPlayer, 和 RealAudio 是 RealNetworks, Inc. 的註冊商標。
Red Hat, RPM, 是 Red Hat, Inc. 在美國和其他國家的註冊商標。
SAP, R/3, 和 mySAP 是 SAP AG 在德國以及許多其他國家的商標或註冊商標。
Sun, Sun Microsystems, Java, Java Virtual Machine, JavaServer Pages, JDK, JSP, JVM, Netra, Solaris, StarOffice, Sun Blade, Sun Enterprise, Sun Fire, SunOS, 和 Ultra 是 Sun Microsystems, Inc. 在美國和其他國家的商標或註冊商標。
Symantec 和 Ghost 是 Symantec Corporation 在美國和其他國家的註冊商標。
MATLAB 是 The MathWorks, Inc. 的註冊商標。
SpeedTouch 是 Thomson 的商標。
U.S. Robotics 和 Sportster 是 U.S. Robotics Corporation 的註冊商標。
VMware 是 VMware, Inc. 的商標
Waterloo Maple 和 Maple 是 Waterloo Maple Inc 的商標或註冊商標
Mathematica 是 Wolfram Research, Inc 的註冊商標。
XFree86 是 The XFree86 Project, Inc 的商標。.
Ogg Vorbis 和 Xiph.Org 是 Xiph.Org 的商標。
許多製造商和經銷商使用一些稱為商標的圖案或文字設計來彰顯自己的產品。 本文中出現的眾多商標,以及 FreeBSD Project 本身廣所人知的商標,後面將以 '™' 或 '®' 符號來標註。
若您是第一次接觸 FreeBSD 的新手,可以在本書第一部分找到 FreeBSD 的安裝方法,同時會逐步介紹 UNIX® 的基礎概念與一些常用、共通的東西。而閱讀這部分並不難,只需要您有探索的精神和接受新概念。
讀完這些之後,手冊中的第二部分花很長篇幅介紹的各種廣泛主題,相當值得系統管理者去注意。 在閱讀這些章節的內容時所需要的背景知識,都註釋在該章的大綱裡面,若不熟的話,可在閱讀前先預習一番。
延伸閱讀方面,可參閱 Appendix B。
您目前看到的這本手冊第三版是 FreeBSD 文件計劃的成員歷時兩年完成的心血之作。 新版的主要修訂部分,如下:
Chapter 11, 設定與效能調校(Tuning),該章節針對新內容作更新,比如: ACPI 電源管理、cron、以及其他更多的 kernel tuning 選項說明內容。
Chapter 14, 系統安全篇,該章節增加了虛擬私人網路(VPN)、檔案系統的存取控制(ACL),以及安全公告(Security Advisories)的內容。
Chapter 16, 集權式存取控制(MAC)是本版所增加的章節。本章介紹:什麼是 MAC 機制?以及如何運用它來使您的 FreeBSD 系統更安全。
Chapter 18, 儲存設備篇,新增了像是:USB 隨身碟、檔案系統快照(snapshot)、檔案系統配額(quota) 、檔案及網路的備援檔案系統、以及如何對硬碟分割區作加密等詳解。
Chapter 20Vinum是本版所新增的章節。本章介紹:如何運用 Vinum 這種邏輯磁碟(device-independent) ,以及軟體 RAID-0, RAID-1 和 RAID-5 。
Chapter 25PPP 及 SLIP 一章中增加了故障排除的說明。
Chapter 26電子郵件一章中新增有關如何使用其它的 MTA 程式、SMTP 認証、UUCP、fecthmail、procmail 的運用以及其它進階專題。
Chapter 27, 網路伺服器篇,是新版中全新的一章。這一章介紹了如何架設 Apache HTTP 伺服器、FTPd,以及用於支援 Microsoft Windows client 的 Samba 伺服器。其中有些段落來自原先的Chapter 29進階網路應用一章。
Chapter 29進階網路應用一章新增有關在 FreeBSD 中使用藍芽設備、安裝無線網路以及使用 ATM(Asynchronous Transfer Mode) 網路的介紹。
增加了一份詞彙表(Glossary),用以說明全書中出現的術語。
重新美編書中所列的圖表。
本手冊的第二版是 FreeBSD 文件計劃的成員歷時兩年完成的心血之作。第二版包含了如下的主要變動︰
增加完整的目錄索引。
所有的 ASCII 圖表均改成圖檔格式的圖表。
每個章節均加入概述,以便快速的瀏覽該章節內容摘要、讀者所欲了解的部分。
內容架構重新組織成三大部分: “開始使用 FreeBSD”, “系統管理”, and “附錄”。
Chapter 2 (“安裝 FreeBSD”) 已經重新改寫,並加入許多說明圖片, 讓第一次接觸 FreeBSD 的人,直接看圖就很清楚明瞭重點(一圖抵千字的效果)。
Chapter 3(“UNIX 基礎概念篇”)新增了 processes, daemons 和 signals 的介紹。
Chapter 4 (“軟體套件管理篇”)新增了介紹如何管理 binary package 套件的資訊。
Chapter 5 (“X Window 視窗系統篇”) 經過全面改寫,著重於在 XFree86™ 4.X 上的流行 x11-wm,像是: KDE 和 GNOME 。
Chapter 12 (“FreeBSD 開機流程篇”)更新相關內容。
Chapter 18 (“儲存設備篇(Storage)”) 分別以兩個章節 “Disks” 與 “Backups” 來撰寫。我們認為這樣子會比單一章節來得容易瞭解。還有關於 RAID(包含硬體、軟體RAID) 的段落也新增上去了。
Chapter 24(“Serial 通訊篇”)架構重新改寫,並更新至 FreeBSD 4.X/5.X 的內容。
Chapter 25 (“PPP 及 SLIP”)有相當程度的更新。
Chapter 29(“進階網路應用篇”)加入許多新內容。
Chapter 26 (“電子郵件篇”)大量新增了設定 sendmail 的介紹。
Chapter 10 (“Linux® 相容篇”) 增加許多有關安裝 Oracle® 及 SAP® R/3® 的介紹。
此外,第二版還新加章節,以介紹下列專題:
Chapter 11, 設定與效能調校(Tuning)。
Chapter 7, 多媒體影音娛樂(Multimedia)。
本書主要分為五大部分,第一部份『開始使用』:介紹 FreeBSD 的安裝、基本操作。 讀者可根據自己的程度,循序或者跳過一些熟悉的主題來閱讀; 第二部分『常用操作』:介紹 FreeBSD 常用功能,這部分可以不按順序來讀。 每章前面都會有概述,概述會描述本章節涵蓋的內容和讀者應該已知的, 這主要是讓讀者可以挑喜歡的章節閱讀; 第三部分『系統管理』:介紹 FreeBSD 老手所感興趣的各種專題部分; 第四部分『網路通訊』:則包括網路和各式 Server 專題;而第五部分『附錄』:是各種有關 FreeBSD 的資源。
向新手介紹 FreeBSD。該篇說明了 FreeBSD 計劃的歷史、目標和開發模式。
介紹安裝程序。其中還有介紹一些進階的安裝主題,包括像是如何透過 serial console 來安裝。
Covers the basic commands and functionality of the FreeBSD operating system. If you are familiar with Linux or another flavor of UNIX then you can probably skip this chapter.
Covers the installation of third-party software with both FreeBSD's innovative “Ports Collection” and standard binary packages.
Describes the X Window System in general and using X11 on FreeBSD in particular. Also describes common desktop environments such as KDE and GNOME.
Lists some common desktop applications, such as web browsers and productivity suites, and describes how to install them on FreeBSD.
Shows how to set up sound and video playback support for your system. Also describes some sample audio and video applications.
Explains why you might need to configure a new kernel and provides detailed instructions for configuring, building, and installing a custom kernel.
Describes managing printers on FreeBSD, including information about banner pages, printer accounting, and initial setup.
Describes the Linux compatibility features of FreeBSD. Also provides detailed installation instructions for many popular Linux applications such as Oracle, SAP R/3, and Mathematica®.
Describes the parameters available for system administrators to tune a FreeBSD system for optimum performance. Also describes the various configuration files used in FreeBSD and where to find them.
Describes the FreeBSD boot process and explains how to control this process with configuration options.
Describes the creation and manipulation of user accounts. Also discusses resource limitations that can be set on users and other account management tasks.
Describes many different tools available to help keep your FreeBSD system secure, including Kerberos, IPsec and OpenSSH.
Explains what Mandatory Access Control (MAC) is and how this mechanism can be used to secure a FreeBSD system.
Describes how to manage storage media and filesystems with FreeBSD. This includes physical disks, RAID arrays, optical and tape media, memory-backed disks, and network filesystems.
Describes what the GEOM framework in FreeBSD is and how to configure various supported RAID levels.
Describes how to use Vinum, a logical volume manager which provides device-independent logical disks, and software RAID-0, RAID-1 and RAID-5.
Describes how to use FreeBSD in languages other than English. Covers both system and application level localization.
Explains the differences between FreeBSD-STABLE, FreeBSD-CURRENT, and FreeBSD releases. Describes which users would benefit from tracking a development system and outlines that process.
Explains how to connect terminals and modems to your FreeBSD system for both dial in and dial out connections.
Describes how to use PPP, SLIP, or PPP over Ethernet to connect to remote systems with FreeBSD.
Explains the different components of an email server and dives into simple configuration topics for the most popular mail server software: sendmail.
Provides detailed instructions and example configuration files to set up your FreeBSD machine as a network filesystem server, domain name server, network information system server, or time synchronization server.
Explains the philosophy behind software-based firewalls and provides detailed information about the configuration of the different firewalls available for FreeBSD.
Describes many networking topics, including sharing an Internet connection with other computers on your LAN, advanced routing topics, wireless networking, bluetooth, ATM, IPv6, and much more.
Lists different sources for obtaining FreeBSD media on CDROM or DVD as well as different sites on the Internet that allow you to download and install FreeBSD.
This book touches on many different subjects that may leave you hungry for a more detailed explanation. The bibliography lists many excellent books that are referenced in the text.
Describes the many forums available for FreeBSD users to post questions and engage in technical conversations about FreeBSD.
Lists the PGP fingerprints of several FreeBSD Developers.
為方便閱讀本書,以下是一些本書所遵循的編排體裁:
斜體字型(Italic) 用於:檔名、目錄、網址(URL)、 強調語氣、以及第一次提及的技術詞彙。
定寬字(Monospace) 用於: 錯誤訊息、指令、環境變數、port 名稱、主機名稱(hostname)、帳號、群組、設備(device)名稱、變數、 程式碼等。
以粗體字表示:應用程式、命令、按鍵。
鍵盤輸入以 粗體字(Bold) 表示,以便與一般文字做區隔。 組合鍵是指同時按下一些按鍵,我們以 `+' 來表示連接,像是:
Ctrl+Alt+Del
也就是說,一起按 Ctrl 鍵、 Alt 鍵,以及 Del 鍵。
若要逐一按鍵,那麼會以逗號(,)來表示,像是:
Ctrl+X, Ctrl+S
也就是說:先同時按下 Ctrl 與 X 鍵, 然後放開後再同時按 Ctrl 與 S 鍵。
下面例子以 E:\> 為開頭的代表 MS-DOS® 指令部分。 若沒有特殊情況的話,這些指令應該是在 Microsoft® Windows® 環境的 “命令提示字元(Command Prompt)” 內執行。
E:\> tools\fdimage floppies\kern.flp A:
例子若是先以 # 為開頭再接指令的話,就是指在 FreeBSD 中以 root 權限來下命令。 你可以先以 root登入系統並下指令,或是以你自己的帳號登入,並使用 su(1) 來取得 root 權限。
# dd if=kern.flp of=/dev/fd0
例子若是先以 % 為開頭再接指令的話,就是指在 FreeBSD 中以一般帳號來下命令即可。 除非有提到其他用法,否則都是預設為 C-shell(csh/tcsh) 語法,用來設定環境變數以及下其他指令的意思。
% top
您所看到的這本書是經過數百個分散在世界各地的人所努力而來的結果。 無論他們只是糾正一些錯誤或提交完整的章節,所有的點滴貢獻都是非常寶貴有用的。
也有一些公司透過提供資金讓作者專注於撰稿、提供出版資金等模式來支持文件的寫作。 其中,BSDi (之後併入 Wind River Systems) 資助 FreeBSD 文件計劃成員來專職改善這本書直到 2000 年 3 月第一版的出版。(ISBN 1-57176-241-8) Wind River Systems 同時資助其他作者來對輸出架構做很多改進,以及給文章增加一些附加章節。這項工作結束於 2001 年 11 月第二版。(ISBN 1-57176-303-1) 在 2003-2004 兩年中,FreeBSD Mall 把報酬支付給改進這本手冊以使第三版印刷版本能夠出版的志工。
這部份是提供給初次使用 FreeBSD 的使用者和系統管理者。 這些章節包括:
介紹 FreeBSD 給您。
在安裝過程給您指引。
教您 UNIX 的基礎及原理。
展示給您看如何安裝豐富的 FreeBSD 的應用軟體
向您介紹 X, UNIX 的視窗系統以及詳細的桌面環境設定,讓您更有生產力。
我們試著儘可能的讓這段文字的參考連結數目降到最低,讓您在讀使用手冊的這部份時可以不太需要常常前後翻頁。
非常感謝您對 FreeBSD 感興趣!以下章節涵蓋 FreeBSD 計劃的各方面:比如它的歷史、目標、開發模式等等。
讀完這章,您將了解︰
FreeBSD 與其他 OS 之間的關係;
FreeBSD 計劃的歷史源流;
FreeBSD 計劃的目標;
FreeBSD open-source 開發模式的基礎概念;
當然囉,還有 “FreeBSD” 這名字的由來。
FreeBSD 是一個從 4.4BSD-Lite 衍生出而能在以 Intel (x86 and Itanium®), AMD64, Alpha™, Sun UltraSPARC® 為基礎的電腦上執行的作業系統。同時,移植到其他平台的工作也在進行中。 對於本計劃歷史的介紹,請看 FreeBSD 歷史源流, 對於 FreeBSD 的最新版本介紹,請看 current release 。若打算對於 FreeBSD 計劃有所貢獻的話(像是程式碼硬體設備、基金), 請看 如何對 FreeBSD 有貢獻。
FreeBSD 提供給你許多先進功能。這些功能包括:
動態優先權調整的『先佔式多工』能夠確保,即使在系統負擔很重的情況下, 程式執行平順並且應用程式與使用者公平地共享資源。
『多人共用(multi-user)』代表著許多人可以同時使用一個 FreeBSD 系統來處理各自的事務。 系統的硬體周邊(如印表機及磁帶機)也可以讓所有的使用者適當地分享。 也可以針對各別使用者或一群使用者的系統資源,予以設限, 以保護系統不致被過度使用。
好用的『TCP/IP 網路功能』可支援許多業界標準,比如: SCTP、DHCP、NFS、NIS、PPP、SLIP、IPSec、IPv6 的支援,也就是說 FreeBSD 可以容易地跟其他作業系統透過網路共同運作,或是當作企業的伺服器用途 ,例如提供遠端檔案共享(NFS)及電子郵件(email)等服務, 或是讓您的企業連上網際網路(Internet)並提供 WWW、FTP、 路由(routing)、及防火牆(firewall、security) 等必備服務。
『記憶體保護(Memory protection)』能確保程式(或是使用者)不會互相干擾, 即使任何程式有不正常的運作,都不會影響其他程式的執行。
FreeBSD 是『32位元(32-bit)』的作業系統 (在 Alpha、Itanium、 AMD64 及 UltraSPARC 上則是『64位元(64-bit)』) — 打從一開始便是這樣設計的。
業界標準的『X Window 系統』(X11R7)可以在常見的便宜 VGA 顯示卡/螢幕, 提供了圖形化的使用者介面(GUI),並且包括了完整的原始程式碼。
能『直接執行』許多其他作業系統(比如: Linux、SCO、SVR4、BSDI 和 NetBSD) 的可執行檔。
數以萬計的立即可以執行的應用程式,這些都可透過 FreeBSD 的『ports』及『packages』軟體管理機制來取得。 不再需要費心到網路上到處搜尋所需要的軟體。
此外,網路上尚有可非常容易移植的數以萬計應用程式。 FreeBSD 的原始程式碼與許多常見的商業版 UNIX 系統都相容, 所以大部分的程式都只需要很少的修改(或根本不用修改) ,就可以編譯執行。
需要時才置換(demand paged) virtual memory 及 “merged VM/buffer cache” 的設計, 這點在系統中有用去大量記憶體的程式執行時,仍然有不錯的效率表現。
支援 CPU 的對稱多工處理(SMP):可以支援多 CPU 的電腦系統。
完全相容的 C、C++ 以及 Fortran 的環境和其他開發工具。 以及其他許多可供進階研發的程式語言也收集在 ports 和 packages。
整個系統都有『原始程式碼』, 這讓你對作業環境擁有最完全的掌握度。 既然能擁有完全開放的系統,何苦被特定封閉軟體所約束,任廠商擺佈呢?
廣泛且豐富的『線上文件』。
當然囉,還不止如此!
FreeBSD 系統乃是基於美國加州大學柏克萊分校的電腦系統研究群 (Computer Systems Research Group 也就是 CSRG) 所發行的 4.4BSD-Lite,以及基於 BSD 系統開發的優良傳統。 除了由 CSRG 所提供的高品質的成果, 為了提供可處理真正具負荷的工作, FreeBSD 計劃也投入了數千小時以上的細部調整, 以能獲得最好的執行效率以及系統的穩定度。 正當許多商業上的巨人正努力地希望能提供效能及穩定時, FreeBSD 已經具備這樣的特質 -- 就是現在!
FreeBSD 的運用範圍無限,其實完全限制在你的想像力上。 從軟體的開發到工廠自動化,或是人造衛星上面的天線的方位角度的遠端控制; 這些功能若可以用商用的 Unix 產品來達成, 那麼極有可能使用 FreeBSD 也能辦到! FreeBSD 也受益於來自於全球各研究中心及大學所開發的數千個高品質的軟體 ,這些通常只需要花費很少的費用或根本就是免費的。 當然也有商業軟體,而且出現的數目是與日俱增。
由於每個人都可以取得 FreeBSD 的原始程式碼, 這個系統可以被調整而能執行任何原本完全無法想像的功能或計劃, 而對於從各廠商取得的作業系統通常沒有辦法這樣地被修改。 以下提供一些人們使用 FreeBSD 的例子:
網路服務: FreeBSD 內建強勁的網路功能使它成為網路服務(如下例)的理想平台:
檔案伺服器(FTP servers)
全球資訊網伺服器(WWW servers) (標準的或更安全的 [SSL] 連線)
IPv4 及 IPv6 routing
防火牆以及 NAT (“IP masquerading”) gateways。
電子郵件伺服器(Electronic Mail servers)
網路新聞伺服器(USENET News) 或是電子佈告欄系統(BBS)
還有更多...
有了 FreeBSD,您可以容易地先用便宜的 386 PC, 再逐步升級您的機器到四個 CPU 的 Xeon 並使用磁碟陣列(RAID)來滿足您企業運用上的需求。
教育: 若您是資工相關領域的學生,再也沒有比使用 FreeBSD 能學到更多作業系統、計算機結構、及網路的方法了。 另外如果你想利用電腦來處理一些其他的 工作,還有一些如 CAD、 數學運算以及圖形處理軟體等可以免費地取得使用。
研究:有了完整的原始程式碼,FreeBSD 是研究作業系統及電腦科學的極佳環境。 具有免費且自由取得特性的 FreeBSD 也使得一個分置兩地的合作計劃,不必擔心版權及系統開放性的問題, 而能自在的交流。
網路: 你如果需要 router、Name Server (DNS) 或安全的防火牆(Firewall), FreeBSD 可以輕易的將你沒有用到的 386 或 486 PC 變身成為絕佳的伺服器,甚至具有過濾封包(packet-filter) 的功能。
X 視窗工作站: FreeBSD 是 X 終端機的良策,你可以使用免費的 X11 Server。 FreeBSD 不但可以充當遠端 X 程式終端機, 也可以執行本地的 X 程式而減輕大型工作站的負荷。 如果有一台中央伺服器的話,FreeBSD 甚至可以經由網路開機 (不需硬碟,也就是“diskless”) ,而變成更便宜且易於管理的工作站。
軟體開發: 基本安裝的 FreeBSD 就包含了完整的程式開發工具,如 GNU C/C++ 編譯器及除錯器。
你可以經由燒錄 CD-ROM、DVD 或是從 FTP 站上抓回 FreeBSD -- 包括立即可執行的系統以及系統的完整程式碼。 詳情請參閱 Appendix A 取得 FreeBSD。
接下來講的是 FreeBSD 計劃的背景,包含歷史源流的簡介、計劃的目標,以及開發的模式。
FreeBSD 計畫的想法是在 1993 年初所形成的, 那是源自於維護一組 『非官方 386BSD 的 patchkit(修正工具)』計劃的三個協調維護人 Nate Williams,Rod Grimes 和我(Jordan Hubbard)。
我們最初的目標是做出一份 386BSD 綜合修正的 snapshot 版,以便修正當時一堆 patchkit 都不容易解決的問題。有些人可能還記得早期的計劃名稱叫做 “386BSD 0.5” 或 “386BSD Interim” 就是這個原因。
386BSD 是 Bill Jolitz 的作業系統,在當時就已有約一年的分裂討論。 當該修正工具 (patchkit) 日漸龐雜得令人不舒服,我們無異議地同意要作一些事了, 並決定提供一份臨時性的 “淨化版(cleanup)” 來幫助 Bill。 然而,由於 Bill Jolitz 忽然決定取消其對該計劃的認可,且沒有明確指出未來的打算, 所以該計劃便突然面臨斷炊危機。
不久我們便決定在即使沒有 Bill 的支持下,讓該計劃仍然繼續下去, 最後我們採用 David Greenman 丟銅板決定的名字,也就是『FreeBSD』。 在詢問了當時的一些使用者意見之後,就開始決定了最初的目標, 當該計劃開始實施一切就要成真時,一切就變得更清楚了。 我跟 Walnut Creek CD-ROM 討論發行 CD-ROM 這樣子不便上網的人就可以用比較簡單的方式取得 FreeBSD。 Walnut Creek CD-ROM 不只贊成以 CD-ROM 來發行 FreeBSD 的想法,同時提供了一台機器以及快速的網際網路的頻寬。 如果不是 Walnut Creek CD-ROM 幾乎是空前的信任這個剛開始還是完全默默無聞的計劃, 那麼很可能 FreeBSD 不會如此快速的成長到今日這樣的規模。
第一張以 CD-ROM (及網路)發行的 FreeBSD 1.0 是在 1993 年十二月。 該版本是基於由 U.C. Berkeley 以磁帶方式發行的 4.3BSD-Lite (“Net/2”)以及許多來自於 386BSD 和自由軟體基金會的軟體。對於第一次發行而言還算成功, 我們又接著於 1994 年 5 月發行了相當成功的 FreeBSD 1.1。
然而此後不久,另一個意外的風暴在 Novell 和 U.C. Berkeley 關於 Berkeley Net/2 磁帶之法律地位的訴訟確定之後形成。 U.C. Berkeley 接受大部份的 Net/2 的程式碼都是『侵佔來的』且是屬於 Novell 的財產 -- 事實上是當時不久前從 AT&T 取得的。 Berkeley 得到的是 Novell 對於 4.4BSD-Lite 的『祝福』,最後當 4.4BSD-Lite 終於發行之後,便不再是侵佔行為。 而所有現有 Net/2 使用者都被強烈建議更換新版本,這包括了 FreeBSD。 於是,我們被要求於 1994 年 6 月底前停止散佈基於 Net/2 的產品。在此前提之下,本計劃被允許在期限以前作最後一次發行,也就是 FreeBSD 1.1.5.1。
FreeBSD 便開始了這宛如『重新發明輪子』的艱鉅工作 -- 從全新的且不完整的 4.4BSD-Lite 重新整合。 這個 “Lite” 版本是不完整的,因為 Berkeley 的 CSRG 已經刪除了大量在建立一個可以開機執行的系統所需要的程式碼 (基於若干法律上的要求),且該版本在 Intel 平台的移植是非常不完整的。 直到 1994 年 11 月本計劃才完成了這個轉移, 同時在該年 12 月底以 CD-ROM 以及網路的形式發行了 FreeBSD 2.0。 雖然該份版本在當時有點匆促粗糙,但仍是富有意義的成功。 隨之於 1995 年 6 月又發行了更容易安裝,更好的 FreeBSD 2.0.5。
我們在 1996 年 8 月發行了 FreeBSD 2.1.5,在 ISP 和商業團體中非常流行。 隨後, 2.1-STABLE 分支的另一個版本應運而生,它就是在 1997 年 2 月發行 FreeBSD 2.1.7.1 ,同時也是 2.1-STABLE 分支的最後版。之後此分支便進入維護狀態, 僅僅提供安全性的加強和其他嚴重錯誤修補的維護(RELENG_2_1_0)。
1996 年 11 月 FreeBSD 2.2 從開發主軸分支 (“-CURRENT”) 出來成為 RELENG_2_2 分支。它的第一個完整版(2.2.1)於 1997 年 4 月發行。 2.2 分支的延續版本在 97 年夏秋之間發行的,其最後版是在 1998 年 11 月發行的 2.2.8 版。 第一個正式的 3.0 版本在 1998 年 10 月發行,亦即宣告 2.2 分支的落幕。
1999/01/20 日再度分支,這產生了 4.0-CURRENT 以及 3.X-STABLE 兩個分支。 3.X-STABLE 方面,3.1 發行於 1999/02/15,3.2 發行於1999/05/15,3.3 發行於 1999/09/16, 3.4 發行於 1999/12/20,3.5 發行於 2000/06/24 ,接下來幾天後發佈了一些的修補檔(對 Kerberos 安全性方面的修正),就升級至 3.5.1 ,這是 3.X 分支最後一個發行版本。
在 2000/03/13 又有了一個新的分支, 也就是 4.X-STABLE 。這個分支之後發佈了許多的發行版本︰ 4.0-RELEASE 在 2000 年 3 月發行, 而最後的 4.11-RELEASE 則在 2005 年 1 月發行。4-STABLE 分支的支援會持續到 2007/01/31 ,但主要焦點在於安全方面的漏洞、臭蟲及其他嚴重問題的修補。
期待已久的 5.0-RELEASE 在 2003/01/19 正式發行。這是將近開發三年的巔峰之作,同時 也開始加強多顆CPU(SMPng)的支援、kernel thread(KSE) 的支援、檔案系統採用 UFS2 以及支援 snapshot 等, 並支援 UltraSPARC 和 ia64 平台、支援藍芽、32 bit 的 PCMCIA 等。之後於 2003 年 6 月發行了 5.1。 而 -CURRENT 這個發展主軸分支的最後 5.X 版本是在 2004 年 2 月正式發行的 5.2.1-RELEASE,在 5.X 系列進入 -STABLE (RELENG_5分支)之後,-CURRENT 就轉移為 6.X 系列。
RELENG_5 分支於 2004 年 8 月正式開跑,之後是 5.3-RELEASE ,它是 5-STABLE 分支的第一個發行版本。 最後的 5.5-RELEASE 是在 2006 年 5 月發行的,在此之後 RELENG_5 分支不再繼續。
RELENG_6 分支於 2005 年 7 月開跑,而 6.X 分支的第一個 release(6.0-RELEASE) 是在 2005 年 11 月出的。 最新的 6.4-RELEASE 是在 Nov 2008 發行。 當然囉,RELENG_6 分支還將有後續的發行版。
RELENG_7 分支於 2007 年 10 月開跑,最新的 7.2-RELEASE 是在 May 2009 發行。 RELENG_7 分支還將有後續的發行版。
目前,長期的開發計畫繼續在 8.X-CURRENT (trunk) 分支中進行,而 8.X 的 CD-ROM (當然,也可以用網路抓) snapshot 版本可以在 FreeBSD snapshot server 取得。
FreeBSD 計劃的目標在於提供可作任意用途的軟體而不附帶任何限制條文。 我們之中許多人對程式碼 (以及計畫本身) 都有非常大的投入, 因此,當然不介意偶爾有一些資金上的補償,但我們並沒打算堅決地要求得到這類資助。 我們認為我們的首要『使命(mission)』是為任何人提供程式碼, 不管他們打算用這些程式碼做什麼, 因為這樣程式碼將能夠被更廣泛地使用,從而發揮其價值。 我認為這是自由軟體最基本的,同時也是我們所倡導的一個目標。
我們程式碼樹中,有若干是以 GNU GPL 或者 LGPL 發佈的那些程式碼帶有少許的附加限制,還好只是強制性的要求開放程式碼而不是別的。 由於使用 GPL 的軟體在商業用途上會增加若干複雜性,因此,如果可以選擇的話, 我們會比較喜歡使用限制相對更寬鬆的 BSD 版權來發佈軟體。
FreeBSD 的開發是一個非常開放且具彈性的過程,就像從 貢獻者名單 所看到的,是由全世界成千上萬的貢獻者發展起來的。 FreeBSD 的開發基礎架構允許數以百計的開發者透過網際網路協同工作。 我們也經常關注著那些對我們的計畫感興趣的新開發者和新的創意, 那些有興趣更進一步參與計劃的人只需要在 FreeBSD technical discussions 郵遞論壇 連繫我們。 FreeBSD announcements 郵遞論壇 對那些希望了解我們進度的人也是相當有用的。
無論是單獨開發者或者封閉式的團隊合作,多瞭解 FreeBSD 計劃和它的開發過程會是不錯的︰
過去數年來 FreeBSD 的中央 source tree 一直是以 CVS (Concurrent Versions System) 來維護的, 它是個自由軟體,可用來做為版本控制,一裝完 FreeBSD 內就有附了。 然而在 2008 年 6 月起, FreeBSD 版本控制系統改用 SVN(Subversion)。 這切換動作我們認為是有必要,因為 CVS 先天的技術限制,導致 source tree 以及歷史版本數量不斷快速擴張。 因此,主要的 repository 目前是採用 SVN ,而 client 端的工具像是 CVSup、 csup 都是以舊式的 CVS 架構為基礎,仍可以繼續正常運作 —— 此乃因 SVN repository 有 backport 回 CVS 才可以繼續讓 client 端相容。 目前,就只有中央 source tree 是採 SVN 版本控制方式。 而文件、網頁、 Ports 這些 repository 仍持續使用 CVS 版本控制方式。 而主要的 CVS repository 是位於美國加州 Santa Clara 的某台機器上, 然後再 mirror 到世界上其他的許多機器上。 SVN tree 內有兩個主分支: -CURRENT 以及 -STABLE ,這些都可輕鬆複製到自己機器上。 詳情請參閱 更新你的 source tree 一節。
所謂的 committers 指的是對 CVS tree 有 write 權限, 並依不同授權部分,而有不同權限可修改 FreeBSD source。 (“committer” 這詞源自 cvs(1) 中的 commit 指令,該指令是用來把新的修改提交給 CVS repository。) 而提交修改給 committer 們檢查的最好方式,就是用 send-pr(1) 指令。 若提交 PR 的流程系統上有壅塞現象的話, 也可以改用寄信方式,寄信到 FreeBSD committer's 郵遞論壇 即可。
如果把 FreeBSD 看成是一家公司的話, FreeBSD core team 就相當於『董事會(board of directors)』。 core team 的主要職責在於確保此計劃有良好的架構,以朝著正確的方向發展。 此外,邀請熱血且負責的軟體開發者加入 committers 行列, 以在若干成員離去時得以補充新血。 目前的 core team 是在 2008 年 7 月 committers 候選人中選出來的,每兩年會舉辦一次選舉。
有些 core team 成員還負責某些特定範圍, 也就是說他們必須盡量確保一些子系統的穩定、效能。 關於 FreeBSD 開發者們以及各自責任範圍,請參閱 貢獻者名單 。
Note: core team 大部分成員加入 FreeBSD 開發都是志工性質而已, 並未從本計劃中獲得任何薪酬,所以不該把 “commitment” 誤解為 “guaranteed support” 才對。 剛前面所講的『董事會』可能是不恰當的類推,或許我們應該說: 他們是一群自願放棄原本的優渥生活、個人其他領域成就, 而選擇投入 FreeBSD 開發的熱血有為者才對!
最後一點,但這點絕非最不重要的, 最大的開發者團隊就是持續為我們提供回饋以及錯誤修正的使用者自己。 與 FreeBSD 非核心開發者互動的主要方式,便是透過訂閱 FreeBSD technical discussions 郵遞論壇 來進行溝通,這方面可參考,請參閱 Appendix C 以瞭解各式不同的 FreeBSD 郵遞論壇(mailing lists)。
FreeBSD 貢獻者名單 相當長且不斷成長中, 只要有貢獻就會被列入其中, 要不要立即考慮貢獻 FreeBSD 一些回饋呢?
然而,提供原始碼並非為這個計劃做貢獻的唯一方式; 還需要大家投入的完整工作列表、說明,請參閱 FreeBSD 官網。
簡單的說,我們的開發模式就像是一組沒有拘束的同心圓。 這種集中開發模式是以 給使用者方便 為主, 同時讓他們能很容易地共同維護軟體,而不會把潛在的貢獻者排除在外! 我們的目標是提供含有大量一致性的 應用軟體(ports/packages) ,以便讓使用者輕鬆安裝、使用的作業系統 —— 而這開發模式相當符合此一目標。
我們對於那些想要加入 FreeBSD 開發者的期待是: 請保持如同前人一樣的投入,以確保繼續成功!
FreeBSD 是免費使用且帶有完整原始程式碼的以 4.4BSD-Lite 為基礎的系統,可以在 Intel i386™, i486™, Pentium®, Pentium Pro, Celeron®, Pentium II, Pentium III, Pentium 4 (或者相容型號), Xeon™, DEC Alpha 和 Sun UltraSPARC 為基礎的電腦上執行的作業系統。 它主要以加州大學巴爾克利分校 的 CSRG 研究小組的軟體為基礎,並加入了 NetBSD、OpenBSD、386BSD 以及自由軟體基金會的一些東西。
自從 1994 年末,我們發佈了 FreeBSD 2.0 之後,系統的執行效率、 功能、穩定性都有了令人注目的提升。 最大的改變就是我們將記憶體與檔案系統的 cache 機制結合在一起。 這不只使得系統的表現變得更好, 並且使得 FreeBSD 系統最少的記憶體需求減少到 5 MB。 其它的改進包括完整的 NIS cilent and server 功能支援, 支援 transaction TCP、PPP 撥接連線、整合的 DHCP 支援、 SCSI 子系統的改進、ISDN 的支援,ATM、FDDI 以及乙太網路 (Ethernet、包括 100 Mbit 和 Gigabit) 的支援,提升了最新的 Adaptec 控制卡驅動程式的改善,以及數以千計的 bug 修正。
除了最基本的系統軟體,FreeBSD 還提供了廣受歡迎的套件軟體管理機制: Ports Collection。 到本書付印時,已有超過 20,000 個 ports,這範疇涵蓋從 http(WWW) 伺服器到遊戲、程式語言、編輯器以及您能想到的幾乎所有的東西。 完整的 Ports Collection 需要約 417 MB 的硬碟空間,除了 port 基本架構檔案外,都只儲存與該 port 軟體的原始碼有『須要變更』的部份。 如此一來,我們可以更容易更新這些 ports,也大量的減少如舊的 1.0 版 Ports Collection 對於硬碟空間的需求。 要安裝一個 port 的話,只需要進入該 port 的目錄,輸入 make install,這樣子系統就會幫你裝好了。 您要編譯的每個程式的完整原始程式, 都可從 FTP 或 CD-ROM 中獲得,所以您只需準備足夠的硬碟空間來編譯你要的 port 軟體。 幾乎每一個 port 都有已事先編譯好的 “package”以方便安裝, 如果不想從編譯 port 的人,只要用個簡單指令 (pkg_add)就可以安裝。 有關 packages 和 ports 的細節,可以參閱 Chapter 4。
FreeBSD 主機的 /usr/share/doc 目錄下找到許多有用的文件, 來幫助您安裝、使用 FreeBSD。 也可以使用下面的網址,以瀏覽器來翻閱本機上安裝的手冊︰
此外,可在下列網址找到最新版 (也是更新最頻繁的版本):http://www.FreeBSD.org/。
FreeBSD 提供一個簡單好用的文字介面安裝程式,叫做 sysinstall。 這是 FreeBSD 預設使用的安裝程式 。協力廠商若有意願的話,也可以改用自己的安裝程式。 本章將說明如何使用 sysinstall 來安裝 FreeBSD。
讀完這章,您將了解︰
如何製作 FreeBSD 安裝片
FreeBSD 對硬碟的使用及配置。
如何啟動 sysinstall 程式。
在執行 sysinstall 時會問的相關問題有哪些、這些問題的意思為何、以及該如何回答。
在開始閱讀這章之前,您需要︰
閱讀要安裝的 FreeBSD 版本所附之硬體支援表, 以確定您的硬體有沒有被支援。
Note: 一般來說,此安裝說明是針對 i386 (相容的 PC 機種) 架構的電腦。 如果有其他架構(比如 Alpha)的安裝說明,我們會一併列出。 雖然本文件會常常更新,但有可能與您安裝版本上所附的說明文件有些許出入。 在此,我們建議您把本說明文章當作一般的安裝參考原則就好。
安裝 FreeBSD 的硬體方面最低需求,依各 FreeBSD 版本與硬體架構差別而有所不同。
關於安裝所需的最低需求,可在 FreeBSD 網站的 Release Information 找相關的 Installation Notes 說明。 接下來的章節會有相關說明整理。 根據安裝 FreeBSD 的方式不同,可能會需要軟碟機或光碟機, 或某些情況則是要網路卡。 這些部份會在 Section 2.3.7 有介紹。
FreeBSD/i386 及 FreeBSD/pc98 兩種版本均須 486 或更好的處理器, 以及至少 24 MB 的 RAM、至少 150 MB 的硬碟空間, 才能進行最小安裝。
Note: 對老舊硬體而言,在大部份情況裝更多的 RAM 與更大的硬碟空間,會比使用更快的 CPU 更有用。
若要裝 FreeBSD/alpha,則需確認該機型是否有支援 (請參閱 Section 2.2.2) 且必須整顆硬碟皆給 FreeBSD 使用。 目前無法同時與其他作業系統共存。 這硬碟須接到 SRM 韌體有支援的 SCSI controller 上,或者 IDE 硬碟 (該機型的 SRM 有支援可從 IDE 硬碟開機)。
此外,還需該機型的 SRM console firmware。 有些機型可以選擇 AlphaBIOS (or ARC) firmware 或 SRM 來用。 若沒有的話,則需從硬體廠商的網站去下載新的韌體。
Note: 從 FreeBSD 7.0 就不再支援 Alpha。 FreeBSD 6.X 系列則是此架構的最後支援 。
有兩種 CPU 能跑 FreeBSD/amd64。 第一種是包括 AMD Athlon™64 、AMD Athlon64-FX、AMD Opteron™ 或更好的 CPU。
第二種則是 Intel® EM64T 架構的 CPU,這些也可以用 FreeBSD/amd64。 這些 CPU 包括了 Intel Core™ 2 Duo 、Quad、Extreme 系列以及 Intel Xeon 3000、5000、7000 相關系列的 CPU。
若主機板晶片組為 nVidia nForce3 Pro-150,則 必須 調整 BIOS 設定,將 IO APIC 停用才行。 若找不到這選項,那可能就是找 ACPI 停用。 因為 Pro-150 晶片組有個 bug,目前我們尚無找到堪解之道。
若要裝 FreeBSD/sparc64,則需確認該機型是否有支援 (請參閱 Section 2.2.2)。
FreeBSD/sparc64 必須使用整顆硬碟, 因為無法同時與其他作業系統共存。
FreeBSD 每次 release 時都會有附上 FreeBSD Hardware Notes 來說明有支援的硬體列表。 通常這份文件可在光碟或 FTP 的最上層目錄找到,也就是名為 HARDWARE.TXT 的檔案。 此外,在 sysinstall 的 documentation 選項內也可以看到。 每次 FreeBSD release 時該列表會依各不同架構, 而列出相關已知有支援的硬體。 在 FreeBSD 網站的 Release Information 頁可以找到各不同 release 版本與各架構上的硬體支援列表。
在安裝 FreeBSD 之前,您應該試著將您電腦中的硬體清單列出來。 FreeBSD 安裝程式會將這些硬體(硬碟、網路卡、光碟機等等) 以型號及製造廠商列出來。 FreeBSD 也會嘗試為這些硬體找出最適當的 IRQ 及 IO port 的設定。 但是因為 PC 的硬體種類實在太過複雜,這個步驟不一定保證絕對成功。 這時,您就可能需要手動更改有問題的設定值哩。
如果您已裝了其它的作業系統,如: Windows 或 Linux,那麼可先由這些系統所提供的工具, 來查看這些硬體設定值是怎麼設定的。 若真的沒辦法確定某些卡用什麼設定值, 那麼可以檢查看看卡上面所標示的東西,說不定它的設定已有標示在卡上。 常用的 IRQ 號碼為 3、5 以及 7;而 IO 埠的值通常以 16 進位表示, 例如 0x330。
建議您在安裝 FreeBSD 之前,把這些資料列印或抄錄下來做成表格, 也許會較有用喔,例如:
Table 2-1. 硬體清單(舉例)
| 硬體名稱 | IRQ | IO port(s) | 備註 |
|---|---|---|---|
| 第一顆 IDE 硬碟 | N/A | N/A | 40 GB,Seagate 製造,接在第一條 IDE 排線的 master |
| CDROM | N/A | N/A | 接在第一條 IDE 排線的 slave |
| 第二顆硬碟 | N/A | N/A | 20 GB,IBM 製造,接在第二條 IDE 排線的 master |
| 第一個 IDE controller | 14 | 0x1f0 | |
| 網路卡 | N/A | N/A | Intel 10/100 |
| 數據機 | N/A | N/A | 3Com® 56K faxmodem,接在 COM1 |
| ... |
硬體清單完成之後,就需針對你所要裝的 FreeBSD 版本之硬體需求, 來檢查是否有支援。
如果要裝的電腦上面存有重要資料,那麼在安裝 FreeBSD 前, 請確定您已經將這些資料備份了,並且先測試過這些備份檔是否沒有問題。 FreeBSD 安裝程式在要寫入任何資料到您的硬碟前,都會先提醒您確認, 一旦您確定要寫入,那麼之後就再也沒有反悔的機會囉。
如果您想讓 FreeBSD 直接使用整顆硬碟,那麼請直接跳到下一節。
然而,如果您想要 FreeBSD 跟既有的系統並存,那麼, 您必須對硬碟的資料分佈方式有深入的了解,以及其所造成的影響。
PC 上的硬碟可以被細分為許多分散區(chunk)。這些區域叫做 分割區(Partitions)。 由於 FreeBSD 內部也有 partition,名稱可能很容易造成混淆, 因此通常在 FreeBSD 這邊會稱呼這些磁碟分散區為 disk slices 或簡稱 slices。 舉例來說,FreeBSD 的 fdisk 的對象是針對 PC 硬碟的 slice 而非 partition。 因為 PC 本身先天設計,每個硬碟最多可以有 4 個分割區,而這些分割叫做 主要分割區(Primary Partitions)。 為了突破這個限制,以便能使用更多的分割區,就有了新的分割區類型,叫作: 延伸分割區(Extended Partition)。 每個硬碟就只能有一個延伸分割區。 然而,在延伸分割區裡面可以建立許多個特殊分割區,叫作 邏輯分割區(Logical Partitions)。
每種分割區都有其 分割區代號(Partition ID) 用以區別每種分割區的資料類型。 而 FreeBSD 分割區代號是 165。
一般來講,每種作業系統都會有自己獨特的方式來區別分割區。 舉例: DOS 及其之後的作業系統,比如 Windows 會分配給每個主要分割區及邏輯分割區 1 個 磁碟代號(drive letter),從 C: 開始。
FreeBSD 必須安裝在主要分割區。 FreeBSD 可以在這個分割區上面存放資料或是您建立的任何檔案。 然而,如果您有很多顆硬碟,也可以在這些(或部份)硬碟建立 FreeBSD 分割區。 安裝 FreeBSD 的時候,必須至少要有 1 個分割區給 FreeBSD 使用, 這個分割區可以是尚未使用的分割區,或是現存的分割區 (但上面的資料不打算繼續使用)。
如果已經用完了磁碟上所有的分割區, 那麼您必須使用其他作業系統所提供的工具 (像是 DOS or Windows 上的 fdisk) 來騰出一個分割區給 FreeBSD 用。
如果有多餘的分割區,也可以使用它。 但使用前,您可能需要先整理一下這些分割區。
FreeBSD最小安裝需要約 100 MB 的空間,但是這只是『最小安裝』, 幾乎沒剩下多少空間來存放您自己的檔案。 較理想的(不含圖形介面)最小安裝是約 250 MB,或者是 350 MB 左右(包含圖形介面)。 還需要安裝其他的套件軟體,那麼將需要更多的硬碟空間。
您可以使用商業軟體像是 PartitionMagic® 或免費自由工具像是 GParted 來重新調整分割區空間, 來給 FreeBSD 用的空間。FreeBSD 光碟、FTP 上面的 tools 目錄包含兩個免費的工具, 也可以達成這個工作,叫作:FIPS 及 PResizer。 這些工具的說明文件可以在同個目錄內找到。 FIPS、 PResizer 和 PartitionMagic 可以重新調整在 MS-DOS 到 Windows ME 所使用的 FAT16 及 FAT32 分割區大小。 目前已知可更改 NTFS 分割區的有 PartitionMagic 及 GParted 這兩種工具程式。 GParted在許多 Linux distributions 的 Live CD 都有提供,像是 SystemRescueCD。
目前已知 Microsoft Vista 分割區的重新調整大小會有問題。 在做上述類似動作時,請記得手邊要有 Vista 安裝光碟以免萬一。 此外,強烈建議先做磁碟維護,以及現有資料備份。
Warning: 不當的使用這些工具,可能會刪除所有硬碟上的資料。 在使用這些工具前,請確定您已有先備份好資料。
在 Alpha 上,您必須使用一整顆硬碟給 FreeBSD, 沒有辦法在同顆硬碟上跟其他作業系統共存。 依不同型號的 Alpha 機器,您的硬碟可以是 SCSI 或 IDE 硬碟, 只要您的機器可以從這些硬碟開機就可以。
按照 Digital / Compaq 使用手冊的編排風格, 所有 SRM 輸入的部分都用大寫表示。 注意:SRM 大小寫有別。
要得知您磁碟的名稱以及型號,可以在 SRM console 提示下使用 SHOW DEVICE 命令:
>>>SHOW DEVICE dka0.0.0.4.0 DKA0 TOSHIBA CD-ROM XM-57 3476 dkc0.0.0.1009.0 DKC0 RZ1BB-BS 0658 dkc100.1.0.1009.0 DKC100 SEAGATE ST34501W 0015 dva0.0.0.0.1 DVA0 ewa0.0.0.3.0 EWA0 00-00-F8-75-6D-01 pkc0.7.0.1009.0 PKC0 SCSI Bus ID 7 5.27 pqa0.0.0.4.0 PQA0 PCI EIDE pqb0.0.1.4.0 PQB0 PCI EIDE
例子中機器為 Digital Personal Workstation 433au, 並且顯示出此機器有連接三個磁碟機。 第一個是 CDROM,叫做 DKA0 ;另外兩個是磁碟機, 分別叫做: DKC0 及 DKC100。
磁碟機的名稱中有 DKx 字樣的是 SCSI 硬碟。例如: DKA100 表示是 SCSI 硬碟,其 SCSI ID 為 1, 位在第一個 SCSI 匯流排(A); 而 DKC300 表示是 SCSI 硬碟, 其 SCSI ID 為 3,位於第三個 SCSI 匯流排(C)。 裝置名稱 PKx 則為 SCSI 控制卡。 由上述 SHOW DEVICE 的結果看來, SCSI 光碟機也被視為是 SCSI 硬碟的一種。
若為 IDE 硬碟的話,名稱會有 DQx 字樣, 而 PQx 則表示相對應的 IDE 磁碟控制器。
如果想透過網路( FTP 站或 NFS)安裝 FreeBSD, 那麼就必須知道您的網路設定。 在安裝 FreeBSD 的過程中將會提示您輸入這些資訊,以順利完成安裝過程。
若使用乙太網路,或是要透過 Cable/DSL 數據機上網, 那麼您必須準備下面的資訊:
IP 位址
預設 Gateway(閘道) 的 IP 位址
Hostname(機器名稱)
DNS 伺服器的 IP 位址
Subnet Mask
若不知道這些資訊,您可以詢問系統管理者或是您的 ISP 業者。 他們可能會說這些資訊會由 DHCP 自動指派; 如果是這樣的話,請記住這一點就可以了。
若由一般的數據機撥接上網,您仍然可以安裝 FreeBSD, 只是會需要很長的時間。
您必須知道:
撥接到 ISP 的電話號碼。
您的數據機是連到哪個 COM 埠。
您撥接到 ISP 所用的帳號跟密碼。
雖然我們盡力使得每個 FreeBSD 發行版本都很穩定, 但是過程中仍然不免有時會發生錯誤。 在某些很罕見的情形下,這些錯誤會影響到安裝的過程。 當發現這些錯誤且修正後,會將它們列在 FreeBSD 勘誤表(Errata) 中。 在您安裝 FreeBSD 前,應該先看看勘誤表中有沒有什麼問題會影響到您的安裝。
關於所有發行版本的資訊(包括勘誤表),可以在 FreeBSD 網站 的 發行情報(release information) 找到。
FreeBSD 可以透過下面任何一種安裝來源進行安裝︰
Local Media
CDROM 或 DVD
現有的 DOS 分割區
SCSI 或 QIC 磁帶。
軟碟磁片
Network
FTP 站、支援 Passvie 模式的 FTP 站(若您機器在 NAT 內) 、甚至 HTTP proxy 都可以。
NFS 伺服器
專用(dedicated)的 parallel 或 serial 連線
若已經有 FreeBSD 的 CD 或 DVD,但機器不支援從光碟開機的話, 那麼請直接進下一節 (Section 2.3.7)。
若沒有 FreeBSD 安裝片的話,那麼請先看 Section 2.13 這裡會介紹如何準備所需要的安裝片, 照該節步驟弄好後,就可以繼續下一步 Section 2.4。
FreeBSD 安裝流程是要從電腦開機後,進入 FreeBSD 安裝畫面 —— 而不是在其他作業系統上執行程式。 一般來講,電腦都是用裝在硬碟上的作業系統來開機, 也可以用開機磁片來開機; 此外,現在大多數電腦都可以從光碟開機。
Tip: 如果您有 FreeBSD 的 CDROM 或 DVD(無論是用買現成的或是自己燒錄的), 且您的電腦可支援由光碟開機,(通常在 BIOS 中會有 “Boot Order” 或類似選項),那麼您就可以跳過此小節。 因為 FreeBSD CDROM 或 DVD 都可以用來開機。
請按照下面步驟,以製作開機片:
取得開機片的映像檔(images)
開機磁片用的映像檔(images)通常會放在光碟片上的 floppies/ 目錄內, 另外也可以從像是下面 FTP 站的 floppies 目錄下載: ftp://ftp.FreeBSD.org/pub/FreeBSD/releases/<arch>/<version>-RELEASE/floppies/ 。請將『arch』、『version』替換為打算安裝的電腦架構、OS 版本。 例如:想裝的是 FreeBSD/i386 7.2-RELEASE ,那麼可以到 下載。
映像檔(images)的附檔名都是 .flp。而 floppies/ 目錄內包含一些不同用途的映像檔 (images),這取決於您要裝的 FreeBSD 版本、需求、硬體配備為何。 通常要 4 個映像檔,也就是: boot.flp、 kern1.flp、kern2.flp、 kern3.flp。 若有疑問的話,請翻閱同一目錄下的 README.TXT 文件檔,以瞭解相關最新注意事項。
Important: 在使用 FTP 下載時,必須使用 binary 模式 進行傳輸。 有些瀏覽器預設是以 text (或 ASCII) 模式來傳輸資料, 所以這些錯誤傳輸模式下載的映像檔所做成的磁片,會無法使用。
準備開機磁片
每個映像檔都需要一張磁片,並且請避免使用到壞的磁片。 最簡單的檢測方式就是自己先把這些磁片再重新格式化(format) 而不要相信所謂的已格式化的磁片,Windows 內的 format 在格式化時,並不會告訴你是否有壞軌, 而只會直接將它們標示壞軌而不使用壞軌部分而已。 此外,建議採用全新的磁片來製作安裝片比較保險。
Important: 若在安裝 FreeBSD 的過程中發生當機、 畫面凍結或是其他怪異的現象,首先要懷疑的就是開機磁片是否壞掉。 請用其他的磁片製作映像檔再試試看。
將映像檔(images)寫入到磁片內
.flp 檔並非一般檔案, 不能直接把它複製到磁片上。 事實上它是包含整張磁片所有內容的映像檔(image)。 也就是說,不能純粹複製檔案到磁片上, 而必須使用特別的工具程式,來將映像檔直接寫到磁片上。
若要用 MS-DOS/Windows 來作安裝片的話,那麼可以用 fdimage 工具程式來將映像檔,寫到磁片上。
若您用的是 FreeBSD 光碟的話(假設光碟機代號為 E: ,那麼請執行類似下面的指令:
E:\> tools\fdimage floppies\boot.flp A:
請針對每個需要用到的 .flp 映像檔, 重複上述的指令(記得更改相關檔名),每次的映像檔完成後, 都需要換另外一片來裝新的映像檔; 請記得: 在作好的磁片上註明是使用哪個映像檔作的。 若 .flp 映像檔放在不同地方, 請自行修改上述指令。若沒有 FreeBSD 光碟的話, 可以到 FTP 上面的 tools 目錄 下載 fdimage 使用。
如果要用 UNIX 系統(比如其他台 FreeBSD 機器) 來製作開機片的話,可以用 dd(1) 指令來把映像檔直接寫入到磁片上。 在 FreeBSD上的話,可以打類似下面的指令:
# dd if=boot.flp of=/dev/fd0
在 FreeBSD 中,/dev/fd0 就是指第一台軟碟機(即一般 MS-DOS/Windows 上的 A: 磁碟機); 而 /dev/fd1 指 B: 磁碟機,其餘的依此類推。 不過其他的 UNIX 系統可能會用不同的名稱,這時就要查閱該系統的說明文件了。
現在起,我們可以開始安裝 FreeBSD 囉!
Important: 預設的情況下,安裝過程並不會改變您磁碟機中的任何資料, 除非您看到下面的訊息:
Last Chance: Are you SURE you want continue the installation? If you're running this on a disk with data you wish to save then WE STRONGLY ENCOURAGE YOU TO MAKE PROPER BACKUPS before proceeding! We can take no responsibility for lost disk contents!在看到這最後的警告訊息前, 您都可以隨時離開安裝程式而不會變更您的硬碟。 如果您發現有任何設定錯誤, 這時您可以直接將電源關掉而不會造成任何傷害。
在一開始,電腦電源開關是關閉的。
打開電腦電源開關。剛開始的時候, 它應該會顯示進入系統設定選單或 BIOS 要按哪個鍵, 常見的有: F2, F10, Del 或 Alt+S。(按鍵請依據實際情況決定) 不論是要按哪個鍵, 請按它進入 BIOS 設定畫面。 有時您的電腦可能會顯示一個圖形畫面, 通常做法是按 Esc 鍵將離開這個圖形畫面, 以使您能夠看到必要的設定訊息。
找出可以設定『開機順序(Boot Order)』的選項, 通常該選項會列出一些設備讓您選擇,例如︰ Floppy, CDROM, First Hard Disk 等等。
如果要用軟碟安裝,請確定 floppy disk 要列為開機順序的第一個; 若要用光碟安裝,記得 CDROM 要列為開機順序的第一個。 為了避免不必要的疑惑,請參考機器、主機板說明手冊。
儲存設定並離開,系統應該會重新啟動。
若要用磁片安裝,請把在 Section 2.3.7一節中製作好的 boot.flp 那張安裝磁片放到第一台軟碟機中。
如果是從光碟安裝,那麼開機後請將 FreeBSD 光碟放入光碟機中。
如果,開機後如往常一樣而沒有從軟碟或光碟開機,請檢查︰
是不是磁片或光碟太晚放入而錯失開機時間。 如果是,請將它們放入,然後重新開機。
BIOS 設定不對或忘了儲存設定,請重新檢查 BIOS 的設定。
您的電腦 BIOS 不支援從光碟開機。
此時,FreeBSD 就開始啟動了。 如果是從光碟開機,會見到類似下面的畫面(版本部分省略):
Booting from CD-Rom... CD Loader 1.2 Building the boot loader arguments Looking up /BOOT/LOADER... Found Relocating the loader and the BTX Starting the BTX loader BTX loader 1.00 BTX version is 1.01 Console: internal video/keyboard BIOS CD is cd0 BIOS drive C: is disk0 BIOS drive D: is disk1 BIOS 639kB/261120kB available memory FreeBSD/i386 bootstrap loader, Revision 1.1 Loading /boot/defaults/loader.conf /boot/kernel/kernel text=0x64daa0 data=0xa4e80+0xa9e40 syms=[0x4+0x6cac0+0x4+0x88e9d] \
如果您從軟碟開機,會看到類似下面的畫面(版本部分省略):
Booting from Floppy... Uncompressing ... done BTX loader 1.00 BTX version is 1.01 Console: internal video/keyboard BIOS drive A: is disk0 BIOS drive C: is disk1 BIOS 639kB/261120kB available memory FreeBSD/i386 bootstrap loader, Revision 1.1 Loading /boot/defaults/loader.conf /kernel text=0x277391 data=0x3268c+0x332a8 | Insert disk labelled "Kernel floppy 1" and press any key...
請根據提示將 boot.flp 磁片取出, 並放入 kern1.flp 這張磁片, 然後按 Enter 鍵。 總之,您只需從第一張磁片啟動,然後根據提示,再放入相關磁片即可。
無論從軟碟或光碟開機,接下來會進入 FreeBSD boot loader 選單畫面:
您可以等待 10 秒,或是按 Enter 鍵。
在一開始,電腦電源開關是關閉的。
打開電腦電源開關,然後等開機畫面出現。
若要用磁片安裝,請把在 Section 2.3.7一節中製作好的 boot.flp 那張安裝磁片放到第一台軟碟機中。 然後,打下列指令來從磁片開機 (請把下列軟碟機代號改為你電腦的軟碟機代號):
>>>BOOT DVA0 -FLAGS '' -FILE ''
若要用光碟安裝,請把做好的安裝片放入光碟機, 然後打下列指令來從光碟開機 (請把下列光碟機代號改為你電腦的光碟機代號):
>>>BOOT DKA0 -FLAGS '' -FILE ''
接著 FreeBSD 開機片就會開始了。若是由軟碟開機的話, 這時會看到以下訊息:
Insert disk labelled "Kernel floppy 1" and press any key...
請照指示,拿走 boot.flp 片,改放 kern1.flp 片, 然後按 Enter。
無論從軟碟或光碟開機,您都會看到下面這段訊息:
Hit [Enter] to boot immediately, or any other key for command prompt. Booting [kernel] in 9 seconds... _
您可以等待 10 秒,或是按 Enter 鍵。 接下來就會進入kernel configuration 選單。
大多數的 Sparc64® 機器預設會自動從硬碟開機。 因此要裝 FreeBSD 的話,則需要進入 PROM(OpenFirmware) 設定由網路或光碟開機才可。
請先重開機,然後等待直到開機訊息出現。 這部分可能會隨機器型號不同 ,而有所差異,但大概會出現像下列這樣:
Sun Blade 100 (UltraSPARC-IIe), Keyboard Present Copyright 1998-2001 Sun Microsystems, Inc. All rights reserved. OpenBoot 4.2, 128 MB memory installed, Serial #51090132. Ethernet address 0:3:ba:b:92:d4, Host ID: 830b92d4.
若您機器此時會先由硬碟開機,那麼需要按 L1+A 或 Stop+A 或者是透過 serial console (用法請參閱 tip(1) 或 cu(1) 內有關 ~# 的說明) 送出 BREAK 指令來進入 PROM prompt。 大概會像下面:
okok {0}
![]()
此時請把安裝光碟放入光碟機內,然後在 PROM prompt 打 boot cdrom 即可。
先前在螢幕上所顯示的最後幾百行字,會存在暫存區(buffer) 以便您翻閱。
若要翻閱暫存區,請按 Scroll Lock 鍵, 這會開啟捲動畫面功能。 然後就可以使用方向鍵,或是 PageUp、 PageDown 鍵來上下翻閱。 再按一次 Scroll Lock 鍵,就會停止畫面捲動。
現在就請試試看,翻閱一下偵測硬體的畫面吧, 你應該會看到類似 Figure 2-2 的畫面, 真正畫面會依你的電腦設備而有所不同。
Figure 2-2. 偵測硬體的例子
avail memory = 253050880 (247120K bytes) Preloaded elf kernel "kernel" at 0xc0817000. Preloaded mfs_root "/mfsroot" at 0xc0817084. md0: Preloaded image </mfsroot> 4423680 bytes at 0xc03ddcd4 md1: Malloc disk Using $PIR table, 4 entries at 0xc00fde60 npx0: <math processor> on motherboard npx0: INT 16 interface pcib0: <Host to PCI bridge> on motherboard pci0: <PCI bus> on pcib0 pcib1:<VIA 82C598MVP (Apollo MVP3) PCI-PCI (AGP) bridge> at device 1.0 on pci0 pci1: <PCI bus> on pcib1 pci1: <Matrox MGA G200 AGP graphics accelerator> at 0.0 irq 11 isab0: <VIA 82C586 PCI-ISA bridge> at device 7.0 on pci0 isa0: <iSA bus> on isab0 atapci0: <VIA 82C586 ATA33 controller> port 0xe000-0xe00f at device 7.1 on pci0 ata0: at 0x1f0 irq 14 on atapci0 ata1: at 0x170 irq 15 on atapci0 uhci0 <VIA 83C572 USB controller> port 0xe400-0xe41f irq 10 at device 7.2 on pci 0 usb0: <VIA 83572 USB controller> on uhci0 usb0: USB revision 1.0 uhub0: VIA UHCI root hub, class 9/0, rev 1.00/1.00, addr1 uhub0: 2 ports with 2 removable, self powered pci0: <unknown card> (vendor=0x1106, dev=0x3040) at 7.3 dc0: <ADMtek AN985 10/100BaseTX> port 0xe800-0xe8ff mem 0xdb000000-0xeb0003ff ir q 11 at device 8.0 on pci0 dc0: Ethernet address: 00:04:5a:74:6b:b5 miibus0: <MII bus> on dc0 ukphy0: <Generic IEEE 802.3u media interface> on miibus0 ukphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto ed0: <NE2000 PCI Ethernet (RealTek 8029)> port 0xec00-0xec1f irq 9 at device 10. 0 on pci0 ed0 address 52:54:05:de:73:1b, type NE2000 (16 bit) isa0: too many dependant configs (8) isa0: unexpected small tag 14 orm0: <Option ROM> at iomem 0xc0000-0xc7fff on isa0 fdc0: <NEC 72065B or clone> at port 0x3f0-0x3f5,0x3f7 irq 6 drq2 on isa0 fdc0: FIFO enabled, 8 bytes threshold fd0: <1440-KB 3.5" drive> on fdc0 drive 0 atkbdc0: <Keyboard controller (i8042)> at port 0x60,0x64 on isa0 atkbd0: <AT Keyboard> flags 0x1 irq1 on atkbdc0 kbd0 at atkbd0 psm0: <PS/2 Mouse> irq 12 on atkbdc0 psm0: model Generic PS/@ mouse, device ID 0 vga0: <Generic ISA VGA> at port 0x3c0-0x3df iomem 0xa0000-0xbffff on isa0 sc0: <System console> at flags 0x100 on isa0 sc0: VGA <16 virtual consoles, flags=0x300> sio0 at port 0x3f8-0x3ff irq 4 flags 0x10 on isa0 sio0: type 16550A sio1 at port 0x2f8-0x2ff irq 3 on isa0 sio1: type 16550A ppc0: <Parallel port> at port 0x378-0x37f irq 7 on isa0 pppc0: SMC-like chipset (ECP/EPP/PS2/NIBBLE) in COMPATIBLE mode ppc0: FIFO with 16/16/15 bytes threshold plip0: <PLIP network interface> on ppbus0 ad0: 8063MB <IBM-DHEA-38451> [16383/16/63] at ata0-master UDMA33 acd0: CD-RW <LITE-ON LTR-1210B> at ata1-slave PIO4 Mounting root from ufs:/dev/md0c /stand/sysinstall running as init on vty0
請仔細檢查每項檢測結果,以確定 FreeBSD 有正確偵測到每項硬體。 若沒偵測到硬體的話,那畫面就不會列出來了。 自訂 kernel 可以讓您加上原本預設的 GENERIC kernel 所不支援的硬體,像是音效卡之類。
而 FreeBSD 6.2 起的版本,在偵測硬體後會看到 Figure 2-3,請用方向鍵選擇你的國別、地區或群組。 然後按 Enter 鍵就會幫你設定相關國別、鍵盤對應。 此外,要離開、重啟 sysinstall 程式,也很簡單。
在主畫面選擇 Exit Install, 接下來應該會出現以下訊息:
User Confirmation Requested
Are you sure you wish to exit? The system will reboot
(be sure to remove any floppies/CDs/DVDs from the drives).
[ Yes ] No
若按下 [ Yes ] 之後,卻忘了把光碟退出來的話, 那麼等下重開機後又會再次啟動安裝程式了。
若你是用磁片開機的話,那麼重開機之前,請記得先退出 boot.flp 片吧。
sysinstall 是 FreeBSD 計劃所提供的安裝程式。 它是以文字模式操作方式為主,分為幾層選單、畫面,以讓您進行安裝。
sysinstall 選單主要由方向鍵、 Enter、Tab、Space 以及其他按鍵來進行操作, 在 sysinstall 主畫面的 Usage 內有這些鍵盤操作上的說明。
要查閱這些說明,請將游標移到 Usage,然後選 [Select] ,這時你畫面應該會長像 Figure 2-5,接著請按 Enter 鍵。
接下來,會出現安裝的使用說明,閱讀完畢請按 Enter 以跳回主畫面。
在主畫面用方向鍵選擇 Doc,然後按 Enter 鍵。
這時會出現說明文件的選單。
閱讀這些說明文件很重要。
要閱讀文件的話,請用方向鍵選取要閱讀的文件然後按 Enter 鍵。讀完後,再按一次 Enter 鍵就會回到說明文件畫面了。
若要回到主畫面,用方向鍵選擇 Exit 然後按下 Enter 鍵即可。
如果要改變鍵盤按鍵的對應模式,請在主選單選取 Keymap 然後按 Enter 鍵即可。 一般情況下是不用去改, 除非你用的鍵盤不是一般標準或非美式鍵盤。
您可以使用上下鍵移動到您想使用的鍵盤對應方式,然後按下 Space 鍵以選取它;再按一下 Space 鍵可以取消選取。當您完成後,請選擇 [ OK ] 然後按 Enter 鍵即可。
在這個畫面顯示的只是其中一小部分; 若只要用預設鍵盤對應方式就好的話,可以用 Tab 來選 [ Cancel ] 這樣就會返回主畫面。
請選 Options 然後按 Enter 鍵。
通常,使用者大多用預設值就可以了,而不用修改它們。 而 Release Name 的地方則依你所安裝的版本而有所不同。
而目前所選的的項目,會在畫面下方以藍底白字顯示說明。 注意:其中右邊最後的選項是 Use Defaults(使用預設值) ,您可以藉由此選項將所有的設定還原為預設值。
另外,可以按 F1 鍵來閱讀各選項的說明。
而按 Q 鍵則是可以回到主畫面。
您的第一個任務就是要決定分配給 FreeBSD 用的磁碟空間、label, 以便 sysinstall 幫你做相關準備動作。 因此,你必須先對 FreeBSD 是如何確認磁碟的流程有個概念。
在安裝、設定 FreeBSD 之前,有很重要的一點必須注意, 尤其當您有許多顆硬碟的時候。
在 PC 架構,當您跑像 MS-DOS 或 Microsoft Windows 這種跟 BIOS 設定相關的作業系統, BIOS 那邊可以調整正常的磁碟機順序,然後這些作業系統會跟著 BIOS 做改變。 這讓使用者不一定非得要由所謂的 “primary master” 硬碟開機。 有人發現最簡單、便宜的備份系統方式,就是再去買一顆一模一樣的硬碟, 然後定期使用 Ghost® 或 XCOPY 以將資料從第一顆硬碟複製到第二顆硬碟上面去。 所以,當第一顆硬碟掛了(可能是病毒或壞軌造成的), 就可以輕鬆透過調整 BIOS 中的開機順序, 而直接用第二顆硬碟開機。 這跟將機殼拆開,把第二顆硬碟跟第一顆對調(要調 jumper)有同樣的效果, 差別就是:不用拆機殼。
此外,若裝有比較貴的 SCSI 卡系統,通常本身也有 BIOS 的功能來讓 SCSI 設備(最多可到 7 個)達到類似改變順序的功能。
習慣上述方式的使用者很可能會感到驚訝,因為在 FreeBSD 中並非如此, FreeBSD 不會參考 BIOS 設定值,而且也不能偵測 “logical BIOS drive mapping” 設定。 這會讓人感覺很疑惑,明明就是一樣的硬碟, 而且資料也完全從另一顆複製過來,結果卻沒辦法像以前那樣用。
使用 FreeBSD 的時候,請將 BIOS 中的硬碟開機順序調回原本正常的順序, 並且以後不要再改這設定。如果您需要切換硬碟順序的話,那請用硬體方式, 直接打開機殼,調 jumper 及排線即可。
Note: 在這時候您所做的變更都還不會真正寫入硬碟中。 如果你發現弄錯了,想要重來一遍的話, 可以用選單來離開 sysinstall, 或是按 U 鍵來 Undo(回復) 所有設定。 如果你弄亂了而且不知道怎麼離開,你可以直接將電腦電源關掉再重來。
在 sysinstall 主畫面選擇使用標準安裝後, 應該會看到下面的訊息:
Message
In the next menu, you will need to set up a DOS-style ("fdisk")
partitioning scheme for your hard disk. If you simply wish to devote
all disk space to FreeBSD (overwriting anything else that might be on
the disk(s) selected) then use the (A)ll command to select the default
partitioning scheme followed by a (Q)uit. If you wish to allocate only
free space to FreeBSD, move to a partition marked "unused" and use the
(C)reate command.
[ OK ]
[ Press enter or space ]
這時請依畫面說明,按 Enter 鍵。 然後會看到一個列表,上面會列出所有在偵測硬體時所找到的硬碟。 Figure 2-13 範例顯示的是有找到兩個 IDE 磁碟機的情形,這兩個磁碟機分別為: ad0 與 ad2。
你可能會好奇,為何 ad1 沒列在這裡。 為什麼會不見了呢?
試想,如果您有兩顆 IDE 硬碟,一個是 primary master,一個是 secondary master,這樣會發生什麼事呢? 如果 FreeBSD 依照找到的順序來為他們命名, 比如首先是 ad0 再來是 ad1 那麼就不會出現困擾。
但是,現在問題來了。如果您現在想在 primary slave 加裝第三顆硬碟, 那麼這顆硬碟的名稱就會是 ad1,之前原本的 ad1 就會變成 ad2。 這樣會造成什麼問題呢? 因為硬體設備的名稱(像是 ad1s1a)是用來尋找檔案系統的, 因此您可能會突然發現,有些檔案系統從此無法正常顯示, 必須修改 FreeBSD 設定(/etc/fstab)才可以正確顯示。
為了解決這個問題,在設定 kernel 時可以採用 IDE 硬碟所在的位置來命名,而非根據找到的順序。 使用這種方式的話, 在 secondary master 的 IDE 硬碟就永遠會是 ad2, 即使系統中並沒有 ad0 或 ad1 也不受影響。
由於此為 FreeBSD kernel 預設設定,也就是為何上述畫面只顯示 ad0 及 ad2 之故。 畫面上這台機器的兩顆硬碟是分別裝在 primary 以及 secondary 排線上的 master,這兩顆都沒有裝在 slave 上。
請選好想安裝 FreeBSD 的硬碟,然後按下 [ OK ]。 接著就會開始 FDisk,然後會看到類似 Figure 2-14 的畫面。
FDisk 的顯示畫面分為三個部分。
第一部份是畫面最上方的前兩行,這裡會顯示目前所選的硬碟資訊, 包括它在 FreeBSD 的名稱、硬碟 geometry、硬碟總容量。
第二部分會顯示目前所選的硬碟上有哪些 slice 以及各 slice 的起末位置、 所佔容量、FreeBSD 名稱、描述說明、子類別(sub-type)。 例子中顯示出有 2 個小的並且尚未使用的 slice,這是受到 PC 的硬碟本身架構影響之故。 此外, 還有一個大的 FAT slice(通常是 MS-DOS / Windows 中的 C:),以及一個延伸磁碟分割區 (在 MS-DOS / Windows 內的其他磁碟代號)。
第三部分則顯示 FDisk 可用的指令。
接下來要做的事,跟您要怎麼分割硬碟有關。
若要讓 FreeBSD 使用整顆硬碟(稍後的安裝會再要您確認以 sysinstall 來繼續安裝, 就會清除該硬碟內上的資料),那麼就可以按 A 鍵( Use Entire Disk),以刪除所有既存的 slice, 取而代之的是一個小的並標示為 unused(同樣的,這也是 PC 硬碟架構所造成)的 slice,以及一個大的 FreeBSD slice。 之後, 請用方向鍵把光棒移至該 FreeBSD slice,然後按 S 鍵以便將此 slice 標為開機 slice。 此時的畫面應該類似 Figure 2-15。 請注意: 在 Flags 欄位的 A 值表示該 slice 屬於 active,也會由此 slice 來開機。
若要刪除現有 slice 以挪出空間給 FreeBSD 使用,可以把光棒移到要刪除的 slice 後按 D 鍵,然後再按 C 鍵, 此時會出現對話框,請輸入要新增的 slice 大小為何,輸入合適大小之後按 Enter 鍵即可。 該預設值為可分配空間的最大值, 可以是最大的或尚未分配的整顆硬碟大小。
若已建立完畢給 FreeBSD 的空間(透過類似 PartitionMagic 之類的工具),那麼可以按 C 鍵以新增 slice。同樣也會有對話框出現,來問想要新增的 slice 大小為何。
完畢後請按 Q 鍵。 這些更改會暫存給 sysinstall 使用,但還不會真正寫入到硬碟 。
現在可以選擇是否要裝 boot manager。 一般而言, 遇到下列情況才會需要裝 boot manager:
有一個以上的硬碟,而 FreeBSD 並非裝在第一個硬碟上。
同一顆硬碟上除了有裝 FreeBSD 之外,還有裝其他作業系統, 所以需要在開機時選擇要進入哪個作業系統。
若只裝 FreeBSD,並且是裝在第一顆硬碟,那麼選 Standard 即可。 若已經有使用其他的 boot manager 可開機進入 FreeBSD 那麼請選 None 即可。
請依自身需求與情況做抉擇,然後按 Enter 鍵。
按 F1 會有不同作業系統共存時, 有可能遇到的相關問題說明。
若有一個以上的硬碟,那麼在選完 boot manager 之後會再回到選擇硬碟的畫面。 若要把 FreeBSD 裝在多個硬碟上, 那麼可以在此選擇其他硬碟,並重複使用 FDisk 來建立 slice 。
Important: 若第一顆硬碟不是裝 FreeBSD 的話,那麼每一顆就要都裝 FreeBSD boot manager 才可以。
Tab 鍵可以在最後選擇的硬碟以及 [ OK ]、 [ Cancel ] 之間進行切換。
先按一次 Tab 會先移到 [ OK ],然後再按 Enter 鍵以繼續安裝。
現在必須在剛建立好的 slice 規劃一些分割區。 請注意: 每個分割區的代號是從 a 到 h, 此外 b、c、d 通常是特殊用途,不該隨意變動。
有些程式可以透過特殊的分割方式而達到更好的效果, 尤其是分割區是分散在不同硬碟上的時候。 但是,現在是您第一次裝 FreeBSD, 所以請不要去煩惱該如何分割硬碟才好。 最重要的是,裝好 FreeBSD 然後學習如何善用之。 當對 FreeBSD 有一定程度的熟悉之後,可以隨時重裝 FreeBSD,並改變分割的方式。
下面例子有四個分割區 —— 其中一個是 swap 空間,i 其他三個是檔案系統。
Table 2-2. 第一顆硬碟的分割區(Partition)配置
| 分割區 | 檔案系統 | 大小 | 介紹 |
|---|---|---|---|
| a | / | 128 MB | 此為根目錄檔案系統(root filesystem)。 其他的檔案系統都會掛載在根目錄之下。 128 MB 對於此檔案系統來說是相當合理的大小, 因為通常這裡並不會放太多資料,而在 FreeBSD 裝完後會用到約 40 MB 的根目錄空間。 剩下的空間是放臨時資料用的, 此外也應該要預留一些空間,因為日後的 FreeBSD 版本可能會需要更多的 /(根目錄) 空間 。 |
| b | N/A | RAM 的 2~3 倍 |
系統的 swap 空間是放在 b 分割區。 如何選擇適合的 swap 空間大小可是一門學問。 一般來說, swap 空間應該是記憶體(RAM)大小的 2 或 3 倍。 此外,swap 至少需要 64 MB,因此若 RAM 小於 32 MB 的話,請把 swap 大小設為 64 MB。 若有一個以上的硬碟,則可以在每個硬碟都配置 swap 空間。 FreeBSD 會善用每個硬碟上的 swap 空間,如此一來便能有效提高 swap 的性能。 若您屬這類情況,請先算出總共需要的 swap 總大小 (比如:128 MB),然後除以全部的硬碟數量(比如:兩顆硬碟), 這樣算出來的結果就是每個硬碟上所需配置的 swap 大小, 在這個例子中,則每個硬碟所需之 swap 空間為 64 MB 。 |
| e | /var | 256 MB | /var 目錄會放的檔案有很多種,像是 log 檔案以及其他的系統管理檔案。 這些檔案大部分都是 FreeBSD 每日運作所會讀、寫。 把這些檔案另外放到專門的檔案系統(即 /var) 則可以最佳化這些檔案的存取, 而不致於影響其他目錄的存取。 |
| f | /usr | 剩餘的硬碟空間 | 所有其他檔案通常會存在 /usr 及其子目錄內。 |
若要把 FreeBSD 裝在多個硬碟上,那麼必須在您所配置的其他 slice 上新增分割區。 最簡單的方式,就是在每個硬碟上建立分割區,一個給 swap 空間,另一個則是檔案系統。
Table 2-3. 其他硬碟的分割區(Partition)配置
| 分割區 | 檔案系統 | 大小 | 介紹 |
|---|---|---|---|
| b | N/A | 請參閱右側的介紹 | 前面有提過,swap 空間是可以跨各硬碟。 即使沒有使用 a 分割區,但習慣上還是會把 swap 空間設為 b 分割區。 |
| e | /diskn | 剩餘的硬碟空間 | 剩下的空間是一個大的分割區,最簡單的做法是將之規劃為 a 分割區,而不是 e 分割區。 然而,習慣上 a 分割區是保留給 根目錄(/)所使用的。 當然, 您不一定要遵循此習慣,但 sysinstall 本身會,所以照它既有的方式會讓你安裝更加清爽、潔淨。 你可以把這些檔案系統掛載在任何地方,本範例是建議把它們掛載於 /diskn 目錄, 其中的 n 的數字, 則依各硬碟的順序而有所變化。 但若您高興, 也可以把它們掛載於其他地方。 |
完成分割區配置之後,就可以用 sysinstall 來建立之。 您會看到如下訊息:
Message
Now, you need to create BSD partitions inside of the fdisk
partition(s) just created. If you have a reasonable amount of disk
space (200MB or more) and don't have any special requirements, simply
use the (A)uto command to allocate space automatically. If you have
more specific needs or just don't care for the layout chosen by
(A)uto, press F1 for more information on manual layout.
[ OK ]
[ Press enter or space ]
請按 Enter 鍵以進入 FreeBSD 分割區編輯器,叫做 Disklabel。
Figure 2-18 顯示第一次執行 Disklabel 的畫面, 這畫面可區分為三個區塊。
前幾行顯示的是正在編輯的硬碟,以及目前正在建立的 slice 位於哪個 分割區上。(在此處,Disklabel 是使用 Partition name(分割區名稱),而非 slice 名稱)。 此畫面也會顯示目前 slice 還有多少空間可供使用, 換句話說就是尚未指定分割區的多餘空間。
在畫面中間,則顯示已建立的分割區、每個分割區的檔案系統名稱、 所佔大小,以及一些參數。
在畫面下方,則顯示 Disklabel 可用的按鍵。
Disklabel 可自動分配分割區, 並賦予預設值大小,按 A 即可自動完成。 您會看到類似 Figure 2-19 的畫面。 不過, 由於所用的硬碟大小不一,所以自動分配所設定的大小不一定合用,不要緊, 您不一定得使用預設大小才可以。
Note: 預設會給 /tmp 目錄作為獨立分割區, 而非附屬於 / 之下。 如此一來, 可避免 / 會被一堆臨時檔案塞爆。
如果您不想用自動分配分割區而希望自行設定, 請用方向鍵選擇第一個分割區,並按下 D 刪除之。 重複此動作直到刪除所有分割區。
建立第一個分割區(a,掛載為 / —— 根目錄), 請在畫面最上方選擇正確的磁碟分割磁區(slice)並按下 C。 接下來將出現對話框, 會要求輸入新的分割區大小(如 Figure 2-20 所示) 。 這邊可以直接輸入以 block 為單位, 或者是以 M(MB)為單位、 或以 G(GB)為單位, 或者以 C(磁柱,cylinders) 為單位。
Note: 自 FreeBSD 5.X 起,則可使用 Custom Newfs 選項來用 UFS2 (從 FreeBSD 5.1 起,此即為預設值)。 若是使用 Auto Defaults 自動預設的情況下,則可以再用 Custom Newfs 選項,或者在建立檔案系統時指定
-O 2參數亦可。 若用 Custom Newfs 選項的話,則別忘了要加上-U來啟用 SoftUpdates 功能!
此處預設顯示的大小,會是整個 slice 的所有空間。 若要採用先前例子所介紹的劃分大小,則按 Backspace 鍵來消除這些數字,並輸入例子中的 128M,如 Figure 2-21 所示。 接著按下 [ OK ]。
在輸入之後會問所要建立的是檔案系統(file system)或者是 swap 空間, 如 Figure 2-22 所示。 第一個選項為檔案系統,所以選擇 FS 後按下Enter。
最後,因為要新增的是檔案系統,所以必須告訴 Disklabel 要將其掛載至何處。 如 Figure 2-23 所示。 根目錄檔案系統 的掛載點為 /,所以請輸入 / ,然後按下 Enter。
剛所建立的分割區會顯示在畫面上,可以用上述類似動作來建立其他分割區。 然而在建立 swap 分割區時,系統並不會問要掛載於哪邊,因為 swap 空間是不必額外掛載的。 此外在建立最後分割區 /usr 時,可以直接採用預設大小,也就是該 slice 剩餘的所有空間。
最後 FreeBSD 上的 DiskLabel 編輯器畫面會類似 Figure 2-24,實際數字則依安裝選擇而有所不同。 請按下 Q 即可完成分割區規劃。
要裝哪些套件,主要取決於該系統的用途為何及磁碟空間而定。 預置的套件,從最小安裝到完整安裝都有。 若是 UNIX 或 FreeBSD 新手,通常直接選其中之一即可。 而自訂套件比較適合有經驗的人來用。
若要瞭解各套件的選項細節資訊,請按 F1 鍵。 看完之後按 Enter 即會回到剛才的套件選擇畫面。
若需要 GUI 介面,那必需加選 X 開頭的相關套件。 至於 X server 的設定及要用哪一類的桌面管理,必須在 FreeBSD 裝好之後才能進行。 X server 設定細節部分請參閱 Chapter 5。
預設安裝的 X11 版本為 Xorg。
若需要自訂 kernel,那麼需加選有含 source code 的選項。 至於為何需自訂 kernel 及相關細節,請參閱 Chapter 8。
很明顯地,全部都裝就不用困擾需要裝什麼了。 若硬碟夠大,請以方向鍵選 Figure 2-25 圖下的 All 選項,並按下 Enter 即可。 若硬碟空間不夠,請依自身需求選擇安裝。 當然在安裝完畢後, 還是可以依需求再加裝其他套件。
在裝完套件集之後,接著會問是否要裝 FreeBSD Ports 套件。 Ports 套件可以讓您輕鬆安裝各種常見的軟體,它本身並不含那些軟體的原始碼, 而是一個包含如何自動下載、編譯、安裝 third-party 軟體的檔案集合。 Chapter 4 會介紹如何使用 ports。
安裝程式並不會檢查是否有足夠空間來放 ports tree, 所以請先確認有足夠空間。 目前 FreeBSD 7.2 的 FreeBSD Ports Collection 大約需要 417 MB 的空間。 因此, 可以推估更新版的 FreeBSD 會需要更多的空間來裝。
User Confirmation Requested
Would you like to install the FreeBSD ports collection?
This will give you ready access to over 20,000 ported software packages,
at a cost of around 417 MB of disk space when "clean" and possibly much
more than that if a lot of the distribution tarballs are loaded
(unless you have the extra CDs from a FreeBSD CD/DVD distribution
available and can mount it on /cdrom, in which case this is far less
of a problem).
The Ports Collection is a very valuable resource and well worth having
on your /usr partition, so it is advisable to say Yes to this option.
For more information on the Ports Collection & the latest ports,
visit:
http://www.FreeBSD.org/ports
[ Yes ] No
用方向鍵選 [ Yes ] 就會裝 Ports Collection,否則就選 [ No ] 以略過。 選好後按 Enter 繼續, 然後會再次回到選擇套件集的畫面。
若要勾選的項目都確認沒問題的話,就以方向鍵選 Exit 退出並確認 [ OK ] 有選到,然後按I Enter 繼續。
若要從 CDROM 或 DVD 安裝,用方向鍵將游標移到 Install from a FreeBSD CD/DVD,並確定 選 [ OK ] 後按下 Enter 就會開始裝了。
若是要用其他的方式安裝的話,請選擇適當的安裝來源, 然後遵照螢幕指示進行安裝即可。
按 F1 可以顯示針對此部分(安裝來源)的線上說明。 按一下 Enter 就會回到『選擇安裝來源』的畫面了。
FTP 安裝模式: 使用 FTP 安裝的話,有分三種模式︰主動式(active)FTP、 被動式(passive)FTP 或是透過 HTTP proxy server。
- 主動式 FTP:從 FTP server 安裝
該選項會透過 “Active” 模式作 FTP 傳輸動作。 這會無法穿過防火牆,但可用在那些較古早、不支援被動模式的 FTP 站。 若 FTP 連線會卡住(預設為被動模式), 那請改換主動模式看看!
- 被動式 FTP:透過防火牆,從 FTP server 安裝
該選項會讓 sysinstall 全程使用 “Passive(被動式)” 來進行 FTP 連線, 就可以穿過只允許使用固定 TCP port 連入的防火牆。
- 透過 HTTP proxy 的 FTP:透過 http proxy 來從 FTP 站安裝
該選項會讓 sysinstall 的 FTP 連線, 先透過 HTTP 協定(就像網頁瀏覽器一樣)連到 proxy server,而 proxy server 會解譯送過來的的請求,然後轉送給 FTP server。 這可以穿透只允許 HTTP 連線但不允許 FTP 連線的防火牆。 但記得要用之時,必須指定 proxy server 的位址。
對 proxy FTP server 而言,通常要在登入用的帳號名稱後面, 加上 “@” 符號再加上要登入的 server 名稱。 然後, proxy server 就會 “fakes(偽裝)” 為真的 server 樣子。 舉個例子,若要到 ftp.FreeBSD.org 來裝, 但中間透過 proxy FTP server 也就是 foo.example.com 並且使用 port 1234。
在此情況下,可以到 options 選單,將 FTP username 設為 ftp@ftp.FreeBSD.org,密碼則設為自己的 email 信箱。 安裝來源部分,則使用 FTP (或 proxy 有支援的話,就用 passive FTP), 而 URL 則用 ftp://foo.example.com:1234/pub/FreeBSD。
因為 ftp.FreeBSD.org 的 /pub/FreeBSD 會被 porxy 到 foo.example.com,所以就可以從 foo.example.com 這台 機器(這台會從 ftp.FreeBSD.org 抓檔回來給您) 安裝。
到此為止,可以開始進行安裝了, 這也是您避免更動到硬碟的最後機會。
User Confirmation Requested
Last Chance! Are you SURE you want to continue the installation?
If you're running this on a disk with data you wish to save then WE
STRONGLY ENCOURAGE YOU TO MAKE PROPER BACKUPS before proceeding!
We can take no responsibility for lost disk contents!
[ Yes ] No
選擇 [ Yes ] 並按下 Enter以確認真的要開始安裝
安裝所需時間會依據所選擇安裝的套件集(distribution) 、安裝來源以及電腦速度而有所不同。 在安裝的過程中,會有一些訊息顯示目前的安裝進度。
當您看到下面的訊息表示已經安裝完成了︰
Message
Congratulations! You now have FreeBSD installed on your system.
We will now move on to the final configuration questions.
For any option you do not wish to configure, simply select No.
If you wish to re-enter this utility after the system is up, you may
do so by typing: /usr/sbin/sysinstall.
[ OK ]
[ Press enter or space ]
請按 Enter 鍵來進行相關的後續設定。
如果剛選的是 [ No ] 並按下 Enter 鍵,那麼會中斷安裝(就不會動到你的原有系統)。 接著,會出現以下訊息:
Message
Installation complete with some errors. You may wish to scroll
through the debugging messages on VTY1 with the scroll-lock feature.
You can also choose "No" at the next prompt and go back into the
installation menus to retry whichever operations have failed.
[ OK ]
這段訊息乃是因為都沒裝任何東西之故,請按 Enter 以跳回主畫面。
安裝系統成功之後,可以在新裝好的 FreeBSD 重開機之前,或者是事後再透過 sysinstall (FreeBSD 5.2 之前版本則是 /stand/sysinstall) 然後選擇 Configure 選項以進行後續設定。
如果您之前有設定用 PPP 連線透過 FTP 安裝,那麼這個畫面將不會出現; 正如上面剛所說的,您可以稍後再做更改。
有關 LAN 或把 FreeBSD 設定為 gateway 或 router 請參閱使用手冊中有關 網路進階運用 的章節。
User Confirmation Requested
Would you like to configure any Ethernet or SLIP/PPP network devices?
[ Yes ] No
如果要設定網路卡,請選擇 [ Yes ] 然後按 Enter。 否則請選 [ No ] 以繼續。
用方向鍵選擇您要設定的網路卡,然後按 Enter。
User Confirmation Requested
Do you want to try IPv6 configuration of the interface?
Yes [ No ]
在私人區域網路的情況,由於目前的 Internet 協定 (IPv4)還算夠用, 所以請選 [ No ] 不設定 IPv6,然後按 Enter。
若是透過 RA server 連到既有的 IPv6 環境,那麼就選 [ Yes ] 並按 Enter,之後系統會花幾秒鐘去搜尋 RA server。
User Confirmation Requested
Do you want to try DHCP configuration of the interface?
Yes [ No ]
接下來,若不需要 DHCP (Dynamic Host Configuration Protocol)請選 [ No ] 並按Enter。
選擇 [ Yes ] 的話,則會執行 dhclient,若成功要到 IP, 則其會自動填上相關的環境設定,細節請參閱 Section 27.5。
下面的網路設定圖顯示如何在區域網路(LAN)中, 將該機器設定為 gateway 的方式:
可用 Tab 鍵在各欄位間作切換, 並填上適合的資料:
完整的機器名稱,例如本例中的 k6-2.example.com。
機器所屬的網域名稱,例如本例中的 example.com。
這裡請輸入 Gateway 的 IP 位址,其可負責將封包轉遞到遠端網路。 只有在該 gateway 屬於該網路其中節點之一時,才要輸入。 若這機器本身要做為該區域網路的 gateway 的話, 請保持本欄為空白。 此外, 通常 IPv4 Gateway 也會被認為是 default gateway 或 default route。
該網路所用的 DNS server 之 IP。 本例假設該機器所在的網路沒有 DNS,故填上的是該 ISP 所提供的 DNS server (208.163.10.2)。
The IP address to be used for this interface was 192.168.0.1
The address block being used for this local area network is a Class C block (192.168.0.0 - 192.168.0.255). The default netmask is for a Class C network (255.255.255.0).
Any interface-specific options to ifconfig you would like to add. There were none in this case.
Use Tab to select [ OK ] when finished and press Enter.
User Confirmation Requested
Would you like to Bring Up the ed0 interface right now?
[ Yes ] No
Choosing [ Yes ] and pressing Enter will bring the machine up on the network and be ready for use. However, this does not accomplish much during installation, since the machine still needs to be rebooted.
User Confirmation Requested
Do you want this machine to function as a network gateway?
[ Yes ] No
If the machine will be acting as the gateway for a local area network and forwarding packets between other machines then select [ Yes ] and press Enter. If the machine is a node on a network then select [ No ] and press Enter to continue.
User Confirmation Requested
Do you want to configure inetd and the network services that it provides?
Yes [ No ]
If [ No ] is selected, various services such telnetd will not be enabled. This means that remote users will not be able to telnet into this machine. Local users will still be able to access remote machines with telnet.
These services can be enabled after installation by editing /etc/inetd.conf with your favorite text editor. See Section 27.2.1 for more information.
Select [ Yes ] if you wish to configure these services during install. An additional confirmation will display:
User Confirmation Requested
The Internet Super Server (inetd) allows a number of simple Internet
services to be enabled, including finger, ftp and telnetd. Enabling
these services may increase risk of security problems by increasing
the exposure of your system.
With this in mind, do you wish to enable inetd?
[ Yes ] No
Select [ Yes ] to continue.
User Confirmation Requested
inetd(8) relies on its configuration file, /etc/inetd.conf, to determine
which of its Internet services will be available. The default FreeBSD
inetd.conf(5) leaves all services disabled by default, so they must be
specifically enabled in the configuration file before they will
function, even once inetd(8) is enabled. Note that services for
IPv6 must be separately enabled from IPv4 services.
Select [Yes] now to invoke an editor on /etc/inetd.conf, or [No] to
use the current settings.
[ Yes ] No
Selecting [ Yes ] will allow adding services by deleting the # at the beginning of a line.
After adding the desired services, pressing Esc will display a menu which will allow exiting and saving the changes.
User Confirmation Requested
Would you like to enable SSH login?
Yes [ No ]
選擇 [ Yes ] 就會啟用 sshd(8),也就是 OpenSSH 的 daemon 程式。 這會允許該機器可從遠端安全登入。 關於 OpenSSH 請參閱 Section 14.11 部分的說明。
User Confirmation Requested
Do you want to have anonymous FTP access to this machine?
Yes [ No ]
Selecting the default [ No ] and pressing Enter will still allow users who have accounts with passwords to use FTP to access the machine.
Anyone can access your machine if you elect to allow anonymous FTP connections. The security implications should be considered before enabling this option. For more information about security see Chapter 14.
To allow anonymous FTP, use the arrow keys to select [ Yes ] and press Enter. The following screen (or similar) will display:
Pressing F1 will display the help:
This screen allows you to configure the anonymous FTP user.
The following configuration values are editable:
UID: The user ID you wish to assign to the anonymous FTP user.
All files uploaded will be owned by this ID.
Group: Which group you wish the anonymous FTP user to be in.
Comment: String describing this user in /etc/passwd
FTP Root Directory:
Where files available for anonymous FTP will be kept.
Upload subdirectory:
Where files uploaded by anonymous FTP users will go.
The ftp root directory will be put in /var by default. If you do not have enough room there for the anticipated FTP needs, the /usr directory could be used by setting the FTP Root Directory to /usr/ftp.
When you are satisfied with the values, press Enter to continue.
User Confirmation Requested
Create a welcome message file for anonymous FTP users?
[ Yes ] No
If you select [ Yes ] and press Enter, an editor will automatically start allowing you to edit the message.
This is a text editor called ee. Use the instructions to change the message or change the message later using a text editor of your choice. Note the file name/location at the bottom of the editor screen.
Press Esc and a pop-up menu will default to a) leave editor. Press Enter to exit and continue. Press Enter again to save changes if you made any.
Network File System (NFS) allows sharing of files across a network. A machine can be configured as a server, a client, or both. Refer to Section 27.3 for a more information.
User Confirmation Requested
Do you want to configure this machine as an NFS server?
Yes [ No ]
If there is no need for a Network File System server, select [ No ] and press Enter.
If [ Yes ] is chosen, a message will pop-up indicating that the exports file must be created.
Message
Operating as an NFS server means that you must first configure an
/etc/exports file to indicate which hosts are allowed certain kinds of
access to your local filesystems.
Press [Enter] now to invoke an editor on /etc/exports
[ OK ]
Press Enter to continue. A text editor will start allowing the exports file to be created and edited.
Use the instructions to add the actual exported filesystems now or later using a text editor of your choice. Note the file name/location at the bottom of the editor screen.
Press Esc and a pop-up menu will default to a) leave editor. Press Enter to exit and continue.
The NFS client allows your machine to access NFS servers.
User Confirmation Requested
Do you want to configure this machine as an NFS client?
Yes [ No ]
With the arrow keys, select [ Yes ] or [ No ] as appropriate and press Enter.
There are several options available to customize the system console.
User Confirmation Requested
Would you like to customize your system console settings?
[ Yes ] No
To view and configure the options, select [ Yes ] and press Enter.
A commonly used option is the screen saver. Use the arrow keys to select Saver and then press Enter.
Select the desired screen saver using the arrow keys and then press Enter. The System Console Configuration menu will redisplay.
The default time interval is 300 seconds. To change the time interval, select Saver again. At the Screen Saver Options menu, select Timeout using the arrow keys and press Enter. A pop-up menu will appear:
The value can be changed, then select [ OK ] and press Enter to return to the System Console Configuration menu.
Selecting Exit and pressing Enter will continue with the post-installation configurations.
Setting the time zone for your machine will allow it to automatically correct for any regional time changes and perform other time zone related functions properly.
The example shown is for a machine located in the Eastern time zone of the United States. Your selections will vary according to your geographical location.
User Confirmation Requested
Would you like to set this machine's time zone now?
[ Yes ] No
Select [ Yes ] and press Enter to set the time zone.
User Confirmation Requested
Is this machine's CMOS clock set to UTC? If it is set to local time
or you don't know, please choose NO here!
Yes [ No ]
Select [ Yes ] or [ No ] according to how the machine's clock is configured and press Enter.
The appropriate region is selected using the arrow keys and then pressing Enter.
Select the appropriate country using the arrow keys and press Enter.
The appropriate time zone is selected using the arrow keys and pressing Enter.
Confirmation
Does the abbreviation 'EDT' look reasonable?
[ Yes ] No
Confirm the abbreviation for the time zone is correct. If it looks okay, press Enter to continue with the post-installation configuration.
User Confirmation Requested
Would you like to enable Linux binary compatibility?
[ Yes ] No
Selecting [ Yes ] and pressing Enter will allow running Linux software on FreeBSD. The install will add the appropriate packages for Linux compatibility.
If installing by FTP, the machine will need to be connected to the Internet. Sometimes a remote ftp site will not have all the distributions like the Linux binary compatibility. This can be installed later if necessary.
This option will allow you to cut and paste text in the console and user programs with a 3-button mouse. If using a 2-button mouse, refer to manual page, moused(8), after installation for details on emulating the 3-button style. This example depicts a non-USB mouse configuration (such as a PS/2 or COM port mouse):
User Confirmation Requested
Does this system have a PS/2, serial, or bus mouse?
[ Yes ] No
Select [ Yes ] for a PS/2, serial, or bus mouse, or [ No ] for a USB mouse and press Enter.
Use the arrow keys to select Type and press Enter.
The mouse used in this example is a PS/2 type, so the default Auto was appropriate. To change protocol, use the arrow keys to select another option. Ensure that [ OK ] is highlighted and press Enter to exit this menu.
Use the arrow keys to select Port and press Enter.
This system had a PS/2 mouse, so the default PS/2 was appropriate. To change the port, use the arrow keys and then press Enter.
Last, use the arrow keys to select Enable, and press Enter to enable and test the mouse daemon.
Move the mouse around the screen and verify the cursor shown responds properly. If it does, select [ Yes ] and press Enter. If not, the mouse has not been configured correctly —— select [ No ] and try using different configuration options.
Select Exit with the arrow keys and press Enter to return to continue with the post-installation configuration.
Packages are pre-compiled binaries and are a convenient way to install software.
Installation of one package is shown for purposes of illustration. Additional packages can also be added at this time if desired. After installation sysinstall can be used to add additional packages.
User Confirmation Requested
The FreeBSD package collection is a collection of hundreds of
ready-to-run applications, from text editors to games to WEB servers
and more. Would you like to browse the collection now?
[ Yes ] No
Selecting [ Yes ] and pressing Enter will be followed by the Package Selection screens:
Only packages on the current installation media are available for installation at any given time.
All packages available will be displayed if All is selected or you can select a particular category. Highlight your selection with the arrow keys and press Enter.
A menu will display showing all the packages available for the selection made:
The bash shell is shown selected. Select as many as desired by highlighting the package and pressing the Space key. A short description of each package will appear in the lower left corner of the screen.
Pressing the Tab key will toggle between the last selected package, [ OK ], and [ Cancel ].
When you have finished marking the packages for installation, press Tab once to toggle to the [ OK ] and press Enter to return to the Package Selection menu.
The left and right arrow keys will also toggle between [ OK ] and [ Cancel ]. This method can also be used to select [ OK ] and press Enter to return to the Package Selection menu.
Use the Tab and arrow keys to select [ Install ] and press Enter. You will then need to confirm that you want to install the packages:
Selecting [ OK ] and pressing Enter will start the package installation. Installing messages will appear until completed. Make note if there are any error messages.
The final configuration continues after packages are installed. If you end up not selecting any packages, and wish to return to the final configuration, select Install anyways.
You should add at least one user during the installation so that you can use the system without being logged in as root. The root partition is generally small and running applications as root can quickly fill it. A bigger danger is noted below:
User Confirmation Requested
Would you like to add any initial user accounts to the system? Adding
at least one account for yourself at this stage is suggested since
working as the "root" user is dangerous (it is easy to do things which
adversely affect the entire system).
[ Yes ] No
Select [ Yes ] and press Enter to continue with adding a user.
Select User with the arrow keys and press Enter.
The following descriptions will appear in the lower part of the screen as the items are selected with Tab to assist with entering the required information:
The login name of the new user (mandatory).
The numerical ID for this user (leave blank for automatic choice).
The login group name for this user (leave blank for automatic choice).
The password for this user (enter this field with care!).
The user's full name (comment).
The groups this user belongs to (i.e. gets access rights for).
The user's home directory (leave blank for default).
The user's login shell (leave blank for default, e.g. /bin/sh).
The login shell was changed from /bin/sh to /usr/local/bin/bash to use the bash shell that was previously installed as a package. Do not try to use a shell that does not exist or you will not be able to login. The most common shell used in the BSD-world is the C shell, which can be indicated as /bin/tcsh.
The user was also added to the wheel group to be able to become a superuser with root privileges.
When you are satisfied, press [ OK ] and the User and Group Management menu will redisplay:
Groups can also be added at this time if specific needs are known. Otherwise, this may be accessed through using sysinstall (/stand/sysinstall in FreeBSD versions older than 5.2) after installation is completed.
When you are finished adding users, select Exit with the arrow keys and press Enter to continue the installation.
Message
Now you must set the system manager's password.
This is the password you'll use to log in as "root".
[ OK ]
[ Press enter or space ]
Press Enter to set the root password.
The password will need to be typed in twice correctly. Needless to say, make sure you have a way of finding the password if you forget. Notice that the password you type in is not echoed, nor are asterisks displayed.
New password : Retype new password :
The installation will continue after the password is successfully entered.
If you need to configure additional network devices or any other configuration, you can do it at this point or after installation with sysinstall (/stand/sysinstall in FreeBSD versions older than 5.2).
User Confirmation Requested
Visit the general configuration menu for a chance to set any last
options?
Yes [ No ]
Select [ No ] with the arrow keys and press Enter to return to the Main Installation Menu.
Select [X Exit Install] with the arrow keys and press Enter. You will be asked to confirm exiting the installation:
User Confirmation Requested
Are you sure you wish to exit? The system will reboot (be sure to
remove any floppies/CDs/DVDs from the drives).
[ Yes ] No
Select [ Yes ] and remove the floppy if booting from the floppy. The CDROM drive is locked until the machine starts to reboot. The CDROM drive is then unlocked and the disk can be removed from drive (quickly).
The system will reboot so watch for any error messages that may appear, see Section 2.10.16 details.
Configuring network services can be a daunting task for new users if they lack previous knowledge in this area. Networking, including the Internet, is critical to all modern operating systems including FreeBSD; as a result, it is very useful to have some understanding FreeBSD's extensive networking capabilities. Doing this during the installation will ensure users have some understanding of the various services available to them.
Network services are programs that accept input from anywhere on the network. Every effort is made to make sure these programs will not do anything “harmful”. Unfortunately, programmers are not perfect and through time there have been cases where bugs in network services have been exploited by attackers to do bad things. It is important that you only enable the network services you know that you need. If in doubt it is best if you do not enable a network service until you find out that you do need it. You can always enable it later by re-running sysinstall or by using the features provided by the /etc/rc.conf file.
Selecting the Networking option will display a menu similar to the one below:
The first option, Interfaces, was previously covered during the Section 2.10.1, thus this option can safely be ignored.
Selecting the AMD option adds support for the BSD automatic mount utility. This is usually used in conjunction with the NFS protocol (see below) for automatically mounting remote file systems. No special configuration is required here.
Next in line is the AMD Flags option. When selected, a menu will pop up for you to enter specific AMD flags. The menu already contains a set of default options:
-a /.amd_mnt -l syslog /host /etc/amd.map /net /etc/amd.map
The -a option sets the default mount location which is
specified here as /.amd_mnt. The -l
option specifies the default log file; however, when syslogd is used all log activity will be sent to the system log
daemon. The /host directory is used to mount an exported file
system from a remote host, while /net directory is used to
mount an exported file system from an IP
address. The /etc/amd.map file defines the default options for
AMD exports.
The Anon FTP option permits anonymous FTP connections. Select this option to make this machine an anonymous FTP server. Be aware of the security risks involved with this option. Another menu will be displayed to explain the security risks and configuration in depth.
The Gateway configuration menu will set the machine up to be a gateway as explained previously. This can be used to unset the Gateway option if you accidentally selected it during the installation process.
The Inetd option can be used to configure or completely disable the inetd(8) daemon as discussed above.
The Mail option is used to configure the system's default MTA or Mail Transfer Agent. Selecting this option will bring up the following menu:
Here you are offered a choice as to which MTA to install and set as the default. An MTA is nothing more than a mail server which delivers email to users on the system or the Internet.
Selecting Sendmail will install the popular sendmail server which is the FreeBSD default. The Sendmail local option will set sendmail to be the default MTA, but disable its ability to receive incoming email from the Internet. The other options here, Postfix and Exim act similar to Sendmail. They both deliver email; however, some users prefer these alternatives to the sendmail MTA.
After selecting an MTA, or choosing not to select an MTA, the network configuration menu will appear with the next option being NFS client.
The NFS client option will configure the system to communicate with a server via NFS. An NFS server makes file systems available to other machines on the network via the NFS protocol. If this is a stand-alone machine, this option can remain unselected. The system may require more configuration later; see Section 27.3 for more information about client and server configuration.
Below that option is the NFS server option, permitting you to set the system up as an NFS server. This adds the required information to start up the RPC remote procedure call services. RPC is used to coordinate connections between hosts and programs.
Next in line is the Ntpdate option, which deals with time synchronization. When selected, a menu like the one below shows up:
From this menu, select the server which is the closest to your location. Selecting a close one will make the time synchronization more accurate as a server further from your location may have more connection latency.
The next option is the PCNFSD selection. This option will install the net/pcnfsd package from the Ports Collection. This is a useful utility which provides NFS authentication services for systems which are unable to provide their own, such as Microsoft's MS-DOS operating system.
Now you must scroll down a bit to see the other options:
The rpcbind(8), rpc.statd(8), and rpc.lockd(8) utilities are all used for Remote Procedure Calls (RPC). The rpcbind utility manages communication between NFS servers and clients, and is required for NFS servers to operate correctly. The rpc.statd daemon interacts with the rpc.statd daemon on other hosts to provide status monitoring. The reported status is usually held in the /var/db/statd.status file. The next option listed here is the rpc.lockd option, which, when selected, will provide file locking services. This is usually used with rpc.statd to monitor what hosts are requesting locks and how frequently they request them. While these last two options are marvelous for debugging, they are not required for NFS servers and clients to operate correctly.
As you progress down the list the next item here is Routed, which is the routing daemon. The routed(8) utility
manages network routing tables, discovers multicast routers, and supplies a copy of the
routing tables to any physically connected host on the network upon request. This is
mainly used for machines which act as a gateway for the local network. When selected, a
menu will be presented requesting the default location of the utility. The default
location is already defined for you and can be selected with the Enter key. You will then be presented with yet another menu, this time
asking for the flags you wish to pass on to routed. The
default is -q and it should already appear on the screen.
Next in line is the Rwhod option which, when selected, will start the rwhod(8) daemon during system initialization. The rwhod utility broadcasts system messages across the network periodically, or collects them when in “consumer” mode. More information can be found in the ruptime(1) and rwho(1) manual pages.
The next to the last option in the list is for the sshd(8) daemon. This is the secure shell server for OpenSSH and it is highly recommended over the standard telnet and FTP servers. The sshd server is used to create a secure connection from one host to another by using encrypted connections.
Finally there is the TCP Extensions option. This enables the TCP Extensions defined in RFC 1323 and RFC 1644. While on many hosts this can speed up connections, it can also cause some connections to be dropped. It is not recommended for servers, but may be beneficial for stand alone machines.
Now that you have configured the network services, you can scroll up to the very top item which is X Exit and continue on to the next configuration item or simply exit sysinstall in selecting X Exit twice then [X Exit Install].
If everything went well, you will see messages scroll off the screen and you will arrive at a login prompt. You can view the content of the messages by pressing Scroll-Lock and using PgUp and PgDn. Pressing Scroll-Lock again will return to the prompt.
The entire message may not display (buffer limitation) but it can be viewed from the command line after logging in by typing dmesg at the prompt.
Login using the username/password you set during installation (rpratt, in this example). Avoid logging in as root except when necessary.
Typical boot messages (version information omitted):
Copyright (c) 1992-2002 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
The Regents of the University of California. All rights reserved.
Timecounter "i8254" frequency 1193182 Hz
CPU: AMD-K6(tm) 3D processor (300.68-MHz 586-class CPU)
Origin = "AuthenticAMD" Id = 0x580 Stepping = 0
Features=0x8001bf<FPU,VME,DE,PSE,TSC,MSR,MCE,CX8,MMX>
AMD Features=0x80000800<SYSCALL,3DNow!>
real memory = 268435456 (262144K bytes)
config> di sn0
config> di lnc0
config> di le0
config> di ie0
config> di fe0
config> di cs0
config> di bt0
config> di aic0
config> di aha0
config> di adv0
config> q
avail memory = 256311296 (250304K bytes)
Preloaded elf kernel "kernel" at 0xc0491000.
Preloaded userconfig_script "/boot/kernel.conf" at 0xc049109c.
md0: Malloc disk
Using $PIR table, 4 entries at 0xc00fde60
npx0: <math processor> on motherboard
npx0: INT 16 interface
pcib0: <Host to PCI bridge> on motherboard
pci0: <PCI bus> on pcib0
pcib1: <VIA 82C598MVP (Apollo MVP3) PCI-PCI (AGP) bridge> at device 1.0 on pci0
pci1: <PCI bus> on pcib1
pci1: <Matrox MGA G200 AGP graphics accelerator> at 0.0 irq 11
isab0: <VIA 82C586 PCI-ISA bridge> at device 7.0 on pci0
isa0: <ISA bus> on isab0
atapci0: <VIA 82C586 ATA33 controller> port 0xe000-0xe00f at device 7.1 on pci0
ata0: at 0x1f0 irq 14 on atapci0
ata1: at 0x170 irq 15 on atapci0
uhci0: <VIA 83C572 USB controller> port 0xe400-0xe41f irq 10 at device 7.2 on pci0
usb0: <VIA 83C572 USB controller> on uhci0
usb0: USB revision 1.0
uhub0: VIA UHCI root hub, class 9/0, rev 1.00/1.00, addr 1
uhub0: 2 ports with 2 removable, self powered
chip1: <VIA 82C586B ACPI interface> at device 7.3 on pci0
ed0: <NE2000 PCI Ethernet (RealTek 8029)> port 0xe800-0xe81f irq 9 at
device 10.0 on pci0
ed0: address 52:54:05:de:73:1b, type NE2000 (16 bit)
isa0: too many dependant configs (8)
isa0: unexpected small tag 14
fdc0: <NEC 72065B or clone> at port 0x3f0-0x3f5,0x3f7 irq 6 drq 2 on isa0
fdc0: FIFO enabled, 8 bytes threshold
fd0: <1440-KB 3.5" drive> on fdc0 drive 0
atkbdc0: <keyboard controller (i8042)> at port 0x60-0x64 on isa0
atkbd0: <AT Keyboard> flags 0x1 irq 1 on atkbdc0
kbd0 at atkbd0
psm0: <PS/2 Mouse> irq 12 on atkbdc0
psm0: model Generic PS/2 mouse, device ID 0
vga0: <Generic ISA VGA> at port 0x3c0-0x3df iomem 0xa0000-0xbffff on isa0
sc0: <System console> at flags 0x1 on isa0
sc0: VGA <16 virtual consoles, flags=0x300>
sio0 at port 0x3f8-0x3ff irq 4 flags 0x10 on isa0
sio0: type 16550A
sio1 at port 0x2f8-0x2ff irq 3 on isa0
sio1: type 16550A
ppc0: <Parallel port> at port 0x378-0x37f irq 7 on isa0
ppc0: SMC-like chipset (ECP/EPP/PS2/NIBBLE) in COMPATIBLE mode
ppc0: FIFO with 16/16/15 bytes threshold
ppbus0: IEEE1284 device found /NIBBLE
Probing for PnP devices on ppbus0:
plip0: <PLIP network interface> on ppbus0
lpt0: <Printer> on ppbus0
lpt0: Interrupt-driven port
ppi0: <Parallel I/O> on ppbus0
ad0: 8063MB <IBM-DHEA-38451> [16383/16/63] at ata0-master using UDMA33
ad2: 8063MB <IBM-DHEA-38451> [16383/16/63] at ata1-master using UDMA33
acd0: CDROM <DELTA OTC-H101/ST3 F/W by OIPD> at ata0-slave using PIO4
Mounting root from ufs:/dev/ad0s1a
swapon: adding /dev/ad0s1b as swap device
Automatic boot in progress...
/dev/ad0s1a: FILESYSTEM CLEAN; SKIPPING CHECKS
/dev/ad0s1a: clean, 48752 free (552 frags, 6025 blocks, 0.9% fragmentation)
/dev/ad0s1f: FILESYSTEM CLEAN; SKIPPING CHECKS
/dev/ad0s1f: clean, 128997 free (21 frags, 16122 blocks, 0.0% fragmentation)
/dev/ad0s1g: FILESYSTEM CLEAN; SKIPPING CHECKS
/dev/ad0s1g: clean, 3036299 free (43175 frags, 374073 blocks, 1.3% fragmentation)
/dev/ad0s1e: filesystem CLEAN; SKIPPING CHECKS
/dev/ad0s1e: clean, 128193 free (17 frags, 16022 blocks, 0.0% fragmentation)
Doing initial network setup: hostname.
ed0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet 192.168.0.1 netmask 0xffffff00 broadcast 192.168.0.255
inet6 fe80::5054::5ff::fede:731b%ed0 prefixlen 64 tentative scopeid 0x1
ether 52:54:05:de:73:1b
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x8
inet6 ::1 prefixlen 128
inet 127.0.0.1 netmask 0xff000000
Additional routing options: IP gateway=YES TCP keepalive=YES
routing daemons:.
additional daemons: syslogd.
Doing additional network setup:.
Starting final network daemons: creating ssh RSA host key
Generating public/private rsa1 key pair.
Your identification has been saved in /etc/ssh/ssh_host_key.
Your public key has been saved in /etc/ssh/ssh_host_key.pub.
The key fingerprint is:
cd:76:89:16:69:0e:d0:6e:f8:66:d0:07:26:3c:7e:2d root@k6-2.example.com
creating ssh DSA host key
Generating public/private dsa key pair.
Your identification has been saved in /etc/ssh/ssh_host_dsa_key.
Your public key has been saved in /etc/ssh/ssh_host_dsa_key.pub.
The key fingerprint is:
f9:a1:a9:47:c4:ad:f9:8d:52:b8:b8:ff:8c:ad:2d:e6 root@k6-2.example.com.
setting ELF ldconfig path: /usr/lib /usr/lib/compat /usr/X11R6/lib
/usr/local/lib
a.out ldconfig path: /usr/lib/aout /usr/lib/compat/aout /usr/X11R6/lib/aout
starting standard daemons: inetd cron sshd usbd sendmail.
Initial rc.i386 initialization:.
rc.i386 configuring syscons: blank_time screensaver moused.
Additional ABI support: linux.
Local package initialization:.
Additional TCP options:.
FreeBSD/i386 (k6-2.example.com) (ttyv0)
login: rpratt
Password:
Generating the RSA and DSA keys may take some time on slower machines. This happens only on the initial boot-up of a new installation. Subsequent boots will be faster.
If the X server has been configured and a Default Desktop chosen, it can be started by typing startx at the command line.
Once the install procedure has finished, you will be able to start FreeBSD by typing something like this to the SRM prompt:
>>>BOOT DKC0
This instructs the firmware to boot the specified disk. To make FreeBSD boot automatically in the future, use these commands:
>>> SET BOOT_OSFLAGS A >>> SET BOOT_FILE '' >>> SET BOOTDEF_DEV DKC0 >>> SET AUTO_ACTION BOOT
The boot messages will be similar (but not identical) to those produced by FreeBSD booting on the i386.
It is important to properly shutdown the operating system. Do not just turn off power. First, become a superuser by typing su at the command line and entering the root password. This will work only if the user is a member of the wheel group. Otherwise, login as root and use shutdown -h now.
The operating system has halted. Please press any key to reboot.
It is safe to turn off the power after the shutdown command has been issued and the message “Please press any key to reboot” appears. If any key is pressed instead of turning off the power switch, the system will reboot.
You could also use the Ctrl+Alt+Del key combination to reboot the system, however this is not recommended during normal operation.
The following section covers basic installation troubleshooting, such as common problems people have reported. There are also a few questions and answers for people wishing to dual-boot FreeBSD with MS-DOS or Windows.
Due to various limitations of the PC architecture, it is impossible for probing to be 100% reliable, however, there are a few things you can do if it fails.
Check the Hardware Notes document for your version of FreeBSD to make sure your hardware is supported.
若硬體有在支援清單內,但使用 GENERIC kernel 仍有問題,那麼就可能需要 自訂 kernel,以加入有支援的硬體。 The kernel on the boot disks is configured assuming that most hardware devices are in their factory default configuration in terms of IRQs, IO addresses, and DMA channels. If your hardware has been reconfigured, you will most likely need to edit the kernel configuration and recompile to tell FreeBSD where to find things.
It is also possible that a probe for a device not present will cause a later probe for another device that is present to fail. In that case, the probes for the conflicting driver(s) should be disabled.
Note: Some installation problems can be avoided or alleviated by updating the firmware on various hardware components, most notably the motherboard. The motherboard firmware may also be referred to as BIOS and most of the motherboard or computer manufactures have a website where the upgrades and upgrade information may be located.
Most manufacturers strongly advise against upgrading the motherboard BIOS unless there is a good reason for doing so, which could possibly be a critical update of sorts. The upgrade process can go wrong, causing permanent damage to the BIOS chip.
At this time, FreeBSD does not support file systems compressed with the Double Space™ application. Therefore the file system will need to be uncompressed before FreeBSD can access the data. This can be done by running the Compression Agent located in the Start> Programs > System Tools menu.
FreeBSD can support MS-DOS based file systems(FAT16 and FAT32). This requires you use the mount_msdosfs(8) command with the required parameters. The utility most common usage is:
# mount -t msdosfs /dev/ad0s1 /mnt
In this example, the MS-DOS file system is located on the first partition of the primary hard disk. Your situation may be different, check the output from the dmesg, and mount commands. They should produce enough information to give an idea of the partition layout.
Note: Extended MS-DOS file systems are usually mapped after the FreeBSD partitions. In other words, the slice number may be higher than the ones FreeBSD is using. For instance, the first MS-DOS partition may be /dev/ad0s1, the FreeBSD partition may be /dev/ad0s2, with the extended MS-DOS partition being located on /dev/ad0s3. To some, this can be confusing at first.
NTFS partitions can also be mounted in a similar manner using the mount_ntfs(8) command.
2.11.3.1. My system hangs while probing hardware during boot, or it behaves strangely during install, or the floppy drive isn't probed.
FreeBSD 5.0 and above makes extensive use of the system ACPI service on the i386, amd64 and ia64 platforms to aid in system configuration if it's detected during boot. Unfortunately, some bugs still exist in both the ACPI driver and within system motherboards and BIOS. The use of ACPI can be disabled by setting the hint.acpi.0.disabled hint in the third stage boot loader:
set hint.acpi.0.disabled="1"
This is reset each time the system is booted, so it is necessary to add hint.acpi.0.disabled="1" to the file /boot/loader.conf. More information about the boot loader can be found in Section 12.1.
2.11.3.2. I go to boot from the hard disk for the first time after installing FreeBSD, the kernel loads and probes my hardware, but stops with messages like:
changing root device to ad1s1a panic: cannot mount root
What is wrong? What can I do?
What is this bios_drive:interface(unit,partition)kernel_name thing that is displayed with the boot help?
There is a longstanding problem in the case where the boot disk is not the first disk in the system. The BIOS uses a different numbering scheme to FreeBSD, and working out which numbers correspond to which is difficult to get right.
In the case where the boot disk is not the first disk in the system, FreeBSD can need some help finding it. There are two common situations here, and in both of these cases, you need to tell FreeBSD where the root filesystem is. You do this by specifying the BIOS disk number, the disk type and the FreeBSD disk number for that type.
The first situation is where you have two IDE disks, each configured as the master on their respective IDE busses, and wish to boot FreeBSD from the second disk. The BIOS sees these as disk 0 and disk 1, while FreeBSD sees them as ad0 and ad2.
FreeBSD is on BIOS disk 1, of type ad and the FreeBSD disk number is 2, so you would say:
1:ad(2,a)kernel
Note that if you have a slave on the primary bus, the above is not necessary (and is effectively wrong).
The second situation involves booting from a SCSI disk when you have one or more IDE disks in the system. In this case, the FreeBSD disk number is lower than the BIOS disk number. If you have two IDE disks as well as the SCSI disk, the SCSI disk is BIOS disk 2, type da and FreeBSD disk number 0, so you would say:
2:da(0,a)kernel
To tell FreeBSD that you want to boot from BIOS disk 2, which is the first SCSI disk in the system. If you only had one IDE disk, you would use '1:' instead.
Once you have determined the correct values to use, you can put the command exactly as you would have typed it in the /boot.config file using a standard text editor. Unless instructed otherwise, FreeBSD will use the contents of this file as the default response to the boot: prompt.
2.11.3.3. I go to boot from the hard disk for the first time after installing FreeBSD, but the Boot Manager prompt just prints F? at the boot menu each time but the boot won't go any further.
The hard disk geometry was set incorrectly in the Partition editor when you installed FreeBSD. Go back into the partition editor and specify the actual geometry of your hard disk. You must reinstall FreeBSD again from the beginning with the correct geometry.
If you are failing entirely in figuring out the correct geometry for your machine, here's a tip: Install a small DOS partition at the beginning of the disk and install FreeBSD after that. The install program will see the DOS partition and try to infer the correct geometry from it, which usually works.
The following tip is no longer recommended, but is left here for reference:
If you are setting up a truly dedicated FreeBSD server or workstation where you don't care for (future) compatibility with DOS, Linux or another operating system, you've also got the option to use the entire disk (`A' in the partition editor), selecting the non-standard option where FreeBSD occupies the entire disk from the very first to the very last sector. This will leave all geometry considerations aside, but is somewhat limiting unless you're never going to run anything other than FreeBSD on a disk.
Your card is probably on a different IRQ from what is specified in the /boot/device.hints file. The ed driver does not use the `soft' configuration by default (values entered using EZSETUP in DOS), but it will use the software configuration if you specify -1 in the hints for the interface.
Either move the jumper on the card to a hard configuration setting (altering the kernel settings if necessary), or specify the IRQ as -1 by setting the hint “hint.ed.0.irq="-1"” This will tell the kernel to use the soft configuration.
Another possibility is that your card is at IRQ 9, which is shared by IRQ 2 and frequently a cause of problems (especially when you have a VGA card using IRQ 2!). You should not use IRQ 2 or 9 if at all possible.
This section describes how to install FreeBSD in exceptional cases.
This type of installation is called a “headless install”, because the machine that you are trying to install FreeBSD on either does not have a monitor attached to it, or does not even have a VGA output. How is this possible you ask? Using a serial console. A serial console is basically using another machine to act as the main display and keyboard for a system. To do this, just follow the steps to create installation floppies, explained in Section 2.3.7.
To modify these floppies to boot into a serial console, follow these steps:
Enabling the Boot Floppies to Boot into a Serial Console
If you were to boot into the floppies that you just made, FreeBSD would boot into its normal install mode. We want FreeBSD to boot into a serial console for our install. To do this, you have to mount the boot.flp floppy onto your FreeBSD system using the mount(8) command.
# mount /dev/fd0 /mnt
Now that you have the floppy mounted, you must change into the /mnt directory:
# cd /mnt
Here is where you must set the floppy to boot into a serial console. You have to make a file called boot.config containing /boot/loader -h. All this does is pass a flag to the bootloader to boot into a serial console.
# echo "/boot/loader -h" > boot.config
Now that you have your floppy configured correctly, you must unmount the floppy using the umount(8) command:
# cd / # umount /mnt
Now you can remove the floppy from the floppy drive.
Connecting Your Null-modem Cable
You now need to connect a null-modem cable between the two machines. Just connect the cable to the serial ports of the 2 machines. A normal serial cable will not work here, you need a null-modem cable because it has some of the wires inside crossed over.
Booting Up for the Install
It is now time to go ahead and start the install. Put the boot.flp floppy in the floppy drive of the machine you are doing the headless install on, and power on the machine.
Connecting to Your Headless Machine
Now you have to connect to that machine with cu(1):
# cu -l /dev/cuad0
在 FreeBSD 5.X,請改用 /dev/cuaa0 而非 /dev/cuad0。
That's it! You should now be able to control the headless machine through your cu session. It will ask you to put in the kern1.flp, and then it will come up with a selection of what kind of terminal to use. Select the FreeBSD color console and proceed with your install!
Note: 為避免重覆說明,在文中所提到的「FreeBSD 光碟」, 在這裡指的是您所購買或自行燒錄的 FreeBSD CDROM 或 DVD。
There may be some situations in which you need to create your own FreeBSD installation media and/or source. This might be physical media, such as a tape, or a source that sysinstall can use to retrieve the files, such as a local FTP site, or an MS-DOS partition.
For example:
You have many machines connected to your local network, and one FreeBSD disc. You want to create a local FTP site using the contents of the FreeBSD disc, and then have your machines use this local FTP site instead of needing to connect to the Internet.
You have a FreeBSD disc, and FreeBSD does not recognize your CD/DVD drive, but MS-DOS/Windows does. You want to copy the FreeBSD installation files to a DOS partition on the same computer, and then install FreeBSD using those files.
The computer you want to install on does not have a CD/DVD drive or a network card, but you can connect a “Laplink-style” serial or parallel cable to a computer that does.
You want to create a tape that can be used to install FreeBSD.
As part of each release, the FreeBSD project makes available at least two CDROM images (“ISO images”) per supported architecture. These images can be written (“burned”) to CDs if you have a CD writer, and then used to install FreeBSD. If you have a CD writer, and bandwidth is cheap, then this is the easiest way to install FreeBSD.
Download the Correct ISO Images
The ISO images for each release can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/ISO-IMAGES-arch/version or the closest mirror. Substitute arch and version as appropriate.
That directory will normally contain the following images:
Table 2-4. FreeBSD 5.X and 6.X ISO Image Names and Meanings
| 檔名 | 內容 |
|---|---|
| 版本-RELEASE-架構-bootonly.iso | Everything you need to boot into a FreeBSD kernel and start the installation interface. The installable files have to be pulled over FTP or some other supported source. |
| 版本-RELEASE-架構-disc1.iso | Everything you need to install FreeBSD and a “live filesystem”, which is used in conjunction with the “Repair” facility in sysinstall. |
| 版本-RELEASE-架構-disc2.iso | FreeBSD 文件(FreeBSD 6.2 之前的),以及許多 third-party packages。 |
| 版本-RELEASE-架構-docs.iso | FreeBSD 文件(FreeBSD 6.2 及之後)。 |
You must download one of either the bootonly ISO image (if available), or the image of disc one. Do not download both of them, since the disc one image contains everything that the bootonly ISO image contains.
Use the bootonly ISO if Internet access is cheap for you. It will let you install FreeBSD, and you can then install third-party packages by downloading them using the ports/packages system (see Chapter 4) as necessary.
Use the image of disc one if you want to install a FreeBSD release and want a reasonable selection of third-party packages on the disc as well.
The additional disc images are useful, but not essential, especially if you have high-speed access to the Internet.
Write the CDs
You must then write the CD images to disc. If you will be doing this on another FreeBSD system then see Section 18.6 for more information (in particular, Section 18.6.3 and Section 18.6.4).
If you will be doing this on another platform then you will need to use whatever utilities exist to control your CD writer on that platform. The images provided are in the standard ISO format, which many CD writing applications support.
Note: If you are interested in building a customized release of FreeBSD, please see the Release Engineering Article.
FreeBSD discs are laid out in the same way as the FTP site. This makes it very easy for you to create a local FTP site that can be used by other machines on your network when installing FreeBSD.
On the FreeBSD computer that will host the FTP site, ensure that the CDROM is in the drive, and mounted on /cdrom.
# mount /cdrom
Create an account for anonymous FTP in /etc/passwd. Do this by editing /etc/passwd using vipw(8) and adding this line:
ftp:*:99:99::0:0:FTP:/cdrom:/nonexistent
Ensure that the FTP service is enabled in /etc/inetd.conf.
Anyone with network connectivity to your machine can now chose a media type of FTP and type in ftp://your machine after picking “Other” in the FTP sites menu during the install.
Note: If the boot media (floppy disks, usually) for your FTP clients is not precisely the same version as that provided by the local FTP site, then sysinstall will not let you complete the installation. If the versions are not similar and you want to override this, you must go into the Options menu and change distribution name to any.
Warning: This approach is OK for a machine that is on your local network, and that is protected by your firewall. Offering up FTP services to other machines over the Internet (and not your local network) exposes your computer to the attention of crackers and other undesirables. We strongly recommend that you follow good security practices if you do this.
若您必須從磁片安裝(雖然我們不建議這樣做), 不論是因為硬體不支援或是您堅持要用這麼刻苦的方式, 您都必須先準備一些磁片以供安裝。
磁片至少得是 1.44 MB At a minimum, you will need as many 1.44 MB floppies as it takes to hold all the files in the base (base distribution) directory. If you are preparing the floppies from DOS, then they must be formatted using the MS-DOS FORMAT command. If you are using Windows, use Explorer to format the disks (right-click on the A: drive, and select “Format”).
Do not trust factory pre-formatted floppies. Format them again yourself, just to be sure. Many problems reported by our users in the past have resulted from the use of improperly formatted media, which is why we are making a point of it now.
If you are creating the floppies on another FreeBSD machine, a format is still not a bad idea, though you do not need to put a DOS filesystem on each floppy. You can use the disklabel and newfs commands to put a UFS filesystem on them instead, as the following sequence of commands (for a 3.5" 1.44 MB floppy) illustrates:
# fdformat -f 1440 fd0.1440 # bsdlabel -w fd0.1440 floppy3 # newfs -t 2 -u 18 -l 1 -i 65536 /dev/fd0
Then you can mount and write to them like any other filesystem.
After you have formatted the floppies, you will need to copy the files to them. The distribution files are split into chunks conveniently sized so that five of them will fit on a conventional 1.44 MB floppy. Go through all your floppies, packing as many files as will fit on each one, until you have all of the distributions you want packed up in this fashion. Each distribution should go into a subdirectory on the floppy, e.g.: a:\base\base.aa, a:\base\base.ab, and so on.
Important: The base.inf file also needs to go on the first floppy of the base set since it is read by the installation program in order to figure out how many additional pieces to look for when fetching and concatenating the distribution.
Once you come to the Media screen during the install process, select Floppy and you will be prompted for the rest.
若準備要從 MS-DOS 分割區進行安裝, 請把所有安裝檔都複製到該分割區根目錄內的 freebsd 目錄。 比如:c:\freebsd。 此目錄結構必須與光碟或 FTP 內的目錄結構一致, 因此若是要從光碟複製檔案,建議使用 DOS 的 xcopy 指令。 例如,要複製 FreeBSD 最小安裝所需的檔案:
C:\> md c:\freebsd C:\> xcopy e:\bin c:\freebsd\bin\ /s C:\> xcopy e:\manpages c:\freebsd\manpages\ /s
假設 C: 槽有多餘空間,可以放 FreeBSD 安裝檔;E:則是光碟機代號。
若沒有光碟機,可以到 ftp.FreeBSD.org 去下載安裝檔。 每個安裝套件都有其相對應的目錄;比如 base 是放在 7.2/base/ 目錄內。
請將您要安裝的套件(當然空間要夠)放到 MS-DOS 分割區的 c:\freebsd 裡 —— 因為這個 BIN 安裝套件僅供最精簡安裝而已。
從磁帶上安裝也許是最簡單的方式,比用 FTP 或光碟安裝還快。 安裝程式假設所有檔案都會壓縮放在磁帶上。 在取得所有要裝的安裝檔之後 ,可以用下列指令把它們壓縮放在磁帶上:
# cd /freebsd/distdir # tar cvf /dev/rwt0 dist1 ... dist2
當要安裝時,必須先確認磁帶還有足夠空間, 以便讓安裝過程暫存空間(可以自行選擇要放在哪個目錄), 可以容納磁帶安裝時的全部檔案。 由於磁帶本身並不能隨機存取,因此用磁帶安裝會需要很大的暫存空間。
Note: 在使用安裝磁片開機之前, 磁帶一定要先放入磁帶機內,否則在偵測硬體時可能會無法偵測到磁帶機。
有三種網路安裝方式: Ethernet (標準 Ethernet 晶片)、Serial port(SLIP 或 PPP)、 Parallel port (PLIP (laplink cable))。
透過網路安裝的最快方式,就是使用 Ethernet 網路卡! FreeBSD 支援大多數常見的 Ethernet 網路卡; 所有支援的網路卡(及其所需的設定)都有在各版本的 FreeBSD 內的 Hardware Note 說明文件內列出。 若您所用的是有支援的 PCMCIA 網路卡, 請務必在開機之前,先把該網路卡插上。 因為 FreeBSD 的安裝過程,目前並不支援 PCMCIA 卡的熱插拔。
此外,還需要知道該用的 IP 位址以及相對應的 netmask 為何, 以及機器名稱。 若所用的是 PPP 連線,而且沒有固定 IP,別擔心, 因為您的 ISP 會自動分配 IP 給您。 關於這些網路的細部設定, 可以洽詢您網路環境的系統管理者。 若要能以機器名稱就能連到相對應的機器,而非直接使用 IP位址去連, 那麼您還需要 DNS 以及 gateway 的位址(若用的是 PPP 連線, gateway 位址就是 ISP 所分配給你的 IP 位址)。 若想透過 HTTP proxy 來使用 FTP 安裝,那麼必須知道 proxy 的網址為何。 若您對上述所需資訊不甚了解,那麼請在安裝之前, 先詢問系統管理者或 ISP。
SLIP 的支援相當原始,並且主要受限於電腦之間的實體線路(hard-wired) ,比如筆記型電腦與其他電腦之間的 serial 線。 之所以得以電腦間以直接線路連結,乃是由於 SLIP 安裝目前並不支援撥接功能。 PPP 才有提供撥接功能, 所以請儘可能優先採用 PPP 而非 SLIP。
若要透過數據機(modem)來安裝,那 PPP 幾乎是您唯一選擇。 請先準備好 ISP 所提供的相關資料,因為在安裝之初就會用到。
若使用 PAP 或 CHAP 來連到 ISP(換句話說,若在 Windows 可以不透過 script 就可以連線到 ISP),那麼您僅需在 ppp 提示符號下輸入 dial 指令即可撥號。 否則,您必須知道如何以該數據機所採用的 “AT 指令集”來連到 ISP,因為 PPP 撥號程式僅提供非常陽春的 終端模擬器(terminal emulator)而起。 請參閱 Handbook 中 user-ppp 章節以及 FAQ 中的相關項目。 若有操作上的疑問,可以打 set log local ... 指令,以便在螢幕上顯示相關記錄。
若可直接以 hard-wired 方式連到另外的 FreeBSD(2.0-R 及之後) 機器, 那麼可以考慮透過 “laplink” 平行電纜來安裝。 平行埠的傳輸速率比序列埠高很多(最高可達每秒 50 kbytes/sec), 所以安裝速度會更快一些。
NFS 安裝方式相當簡便,只需將 FreeBSD 安裝檔案都放到某台 NFS server 上,然後再指定使用這台 NFS 作為安裝來源即可。
若該 server 只允許 “privileged port”(通常這是 Sun 工作站的預設值),那麼在安裝之前,必須先到 Options 選單去指定 NFS Secure 設定值。
若網路卡的連線品質不佳,那可能需要調整一下 NFS Slow 設定。
為了讓 NFS 安裝能順利完成,NFS 主機必須要可以支援子目錄的掛載 (mount),例如:FreeBSD 7.2 安裝目錄是在: ziggy:/usr/archive/stuff/FreeBSD,那麼 ziggy 必須允許直接掛載在 /usr/archive/stuff/FreeBSD,而非僅 /usr 或是 /usr/archive/stuff。
在 FreeBSD 的 /etc/exports 檔,上述功能是由 -alldirs 選項所設定。 其他的 NFS server 可能會有不同的設定方式。
若看到 “permission denied” 錯誤訊息,
則表示可能由於沒有啟用這選項所造成的。
接下來的這一章將涵蓋 FreeBSD 作業系統的基本指令及功能。 大部份的內容在 UNIX-like 作業系統中都是相通的。 如果您對這些內容熟悉的話,可以放心的跳過。 如果您剛接觸 FreeBSD,那您一定要仔細的讀完這章。
讀完這章,您將了解:
如何使用 FreeBSD 的“virtual consoles”。
UNIX 檔案權限運作的方式以及 FreeBSD 中檔案的 flags。
預設的 FreeBSD 檔案系統配置。
FreeBSD 的磁碟結構。
如何掛載(mount)、卸載(umount)檔案系統
什麼是processes、daemons 以及 signals 。
什麼是 shell ,以及如何變更您預設的登入環境。
如何使用基本的文字編輯器。
什麼是 devices 和 device nodes 。
FreeBSD 下使用的 binary 格式。
如何閱讀 manual pages 以獲得更多的資訊。
有很多方法可以操作 FreeBSD ,其中一種就是在文字終端機上打字。 如此使用 FreeBSD 即可輕易的體會到 UNIX 作業系統的威力和彈性。 這一節描述什麼是“終端機”和 “console” ,以及可以如何在 FreeBSD 中運用它們。
如果您沒有將 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[1]。 這台機器的名字(每台 UNIX 機器都有一個名字)是 pc3.example.org,而您現在看到的是它的系統 console—— ttyv0終端機。
最後的一行應該都會是:
login:
這是您應該要輸入您的“帳號名稱”的地方。 下一小節將告訴您如何登入 FreeBSD。
FreeBSD 是一個 multiuser、multiprocessing 的系統。 這是一個正式的名稱,指的是在單一機器上可以同時被不同人使用, 但同時可以執行很多程式的系統。
每一種多使用者系統都需要可以分辨不同“使用者”的方法。 在 FreeBSD (以及所有的 UNIX-like 作業系統) 中,所有的使用者在執行程式之前必須先“登入”系統。 每個使用者都有一組獨特的帳號名稱 (“username”)及密碼(“password”)。 FreeBSD 在允許使用者執行程式前將會先問這兩個問題。
在 FreeBSD 開機並跑完啟動的 script 之後[2],它將會印出提示字元要求您輸入正確的帳號名稱:
login:
在這個範例裡,我們假設您的帳號是john。 在提示字元處輸入 john 並按下 Enter 。 接著您應該會看到另一個提示字元要您輸入“密碼”:
login: john Password:
輸入 john 的密碼,再按下 Enter。 輸入的密碼 不會顯示在螢幕上。 您不需要為此擔心,這樣做是為了安全上的問題。
如果您輸入了正確的密碼,您應該已經登入 FreeBSD。 現在就可以嘗試所有可用的指令了。
您應該會看到MOTD (即今日訊息、Messages Of The Day),後面接著命令提示字元 (一個 #,$, 或是 % 字元)。 這就表示您已經成功登入 FreeBSD 了。
在一個 Console 下執行 UNIX 當然是沒有問題,然而 FreeBSD 是可以同時執行很多程式的。 像 FreeBSD 這樣可以同時執行一大堆程式的作業系統,只有一個 console 可以輸入指令實在是有點浪費。 因此 “virtual consoles” 就顯得相當好用。
可以設定讓 FreeBSD 同時有很多 virtual console, 用幾個按鍵的組合就可以從一個 virtual console 跳到別的 virtual console 。 每一個 console 都有自已不同的輸出頻道,當從某一個 virtual console 切換到下一個的時候,FreeBSD 會自動處理鍵盤輸入及螢幕輸出。
FreeBSD 保留了特別的按鍵組合來切換 console [3]。 您可以用 Alt-F1、 Alt-F2、到 Alt-F8 來切換 FreeBSD 的不同 console。
當您從一個 console 切換到下一個的時候,FreeBSD 會處理螢幕輸出的儲存及回復。 這就“好像”有很多“虛擬”的螢幕和鍵盤, 可以讓您輸入指令到 FreeBSD 執行。 在某一個 console 上執行的程式並不會因為切到別的 console 而停止執行,切換到另一個 console 時,它們仍會繼續執行。
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
有關各欄位的設定以及其他選項,請參閱 ttys(5) 說明。
有關 “single user 模式” 的介紹在 Section 12.6.2 這邊有詳盡介紹。 在 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
Note: 在 console 那行前面的註解有提到,可以把那行的 secure 改為 insecure, 如此一來,即使 FreeBSD 進入 single user 模式, 仍會要求您輸入 root 的密碼。
請審慎考慮是否要改為 insecure。 因為萬一忘記 root 密碼的話,若要登入 single user 模式就有些麻煩了。儘管還有其他方式可以登入,但對不熟 FreeBSD 開機程序的人而言,就會相當棘手。
FreeBSD console 預設顯示大小可以調整為 1024x768、1280x1024 或其他顯示卡與螢幕有支援的解析度大小。 要切換顯示大小,必須要重新編譯 kernel 並加入下面這兩項設定:
options VESA options SC_PIXEL_MODE
一旦 kernel 有加入這兩項並重新編譯完畢,就可以用 vidcontrol(1) 來偵測目前所支援的模式有哪些。 若要查看支援的模式,可以打:
# vidcontrol -i mode
該指令會顯示該機器所支援的顯示模式清單。 然後可以在 root console 內透過 vidcontrol(1) 指令, 來更改顯示模式:
# vidcontrol MODE_279
若對新的顯示模式覺得還不錯,可以在 /etc/rc.conf 設定之,以讓每次重開機後會自動生效。 以上面這情況為例,就是:
allscreens_flags="MODE_279"
FreeBSD 源自於 BSD UNIX,繼承了幾個重要的 UNIX 概念。 首先也最明顯,它是一款 multi-user 作業系統。 它可以同時處理多人多工, 負責徹底的分享與管理來自每位使用者對硬碟裝置、週邊設備、記憶體及 CPU 時間的要求。
也因為系統能夠支援多使用者, 所以系統管理的一切都有權限來決定誰可以讀取、寫入或執行資源。 這些權限分別使用三組八進位的數字儲存,一組代表檔案的所有者, 一組代表檔案所屬的群組,而最後一組則代表其他所有人。 表示這些數字的方式如下:
| 值 | 權限 | 目錄顯示 |
|---|---|---|
| 0 | 不可讀取, 不可寫入, 不可執行 | --- |
| 1 | 不可讀取, 不可寫入, 可執行 | --x |
| 2 | 不可讀取, 可寫入, 不可執行 | -w- |
| 3 | 不可讀取, 可寫入, 可執行 | -wx |
| 4 | 可讀取, 不可寫入, 不可執行 | r-- |
| 5 | 可讀取, 不可寫入, 可執行 | r-x |
| 6 | 可讀取, 可寫入, 不可執行 | rw- |
| 7 | 可讀取, 可寫入, 可執行 | rwx |
使用 ls(1) 指令時,可以加上
-l 參數, 來檢視詳細的目錄清單。
清單中欄位的資訊包含檔案對所有者、群組及其他人的權限。 在任一個目錄底下執行 ls -l,會顯示如下的結果:
% 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 ...
在這裡告所您該如何區分 ls -l 第一欄當中的資訊:
-rw-r--r--
第一個 (最左邊) 的字元用來表示這個檔案的類型為何, 除標準檔案以外,尚有目錄、特殊字元裝置 (Special character device)、 Socket 及其他特殊虛擬檔案裝置 (Special pseudo-file device), 在此例當中,- 表示該檔案為一個標準的檔案。 範例中接下來的三個字元中,rw- 代表所有者對檔案擁有的權限。 再接下來的三個字元, r-- 則代表群組對檔案擁有的權限, 最後三個字元,r-- 則代表其他人對檔案擁有的權限。 破折號 (-) 表示沒有權限,範例中的這個檔案的權限, 只允許所有者讀取、寫入檔案,群組以及其他人僅能讀取檔案。 根據以上的表格,此種權限的檔案可以使用 644 來表示, 每組數字分別代表檔案的三種權限。
以上是不錯的方式,但系統該如何控制裝置的權限? 實際上 FreeBSD 對大多的硬碟裝置就如同檔案,程式可以開啟、讀取以及寫入資料如一般檔案。 這些特殊裝置檔案 (Special device file) 都儲存於 /dev 目錄中。
目錄也同如檔案,擁有讀取、寫入及執行的權限, 但在執行權限上與檔案有明顯的差異。 當目錄被標示為可執行時,代表可以使用 “cd” (更改目錄) 進入該目錄。 也代表能夠存取在此目錄之中的已知檔名的檔案 (當然,檔案仍擁有自己的權限)
尤其,要能夠列出目錄內容,必須擁有目錄的讀取權限。 而當要刪除已知檔名的檔案時,也必須擁有檔案所在目錄的寫入 以及 執行的權限。
還有一些權限,但這些權限主要在特殊情況使用,如 setuid binaries 及 sticky directories。 如果您還想知道更多檔案權限的資訊及使用方法,請務必參閱 chmod(1) 說明文件。
權限符號可稱做符號表示, 使用字元的方式來取代使用數值來設定檔案或目錄的權限。 符號表示的格式依序為 (某人)(動作)(權限),可使用的符號如下:
| 項目 | 字母 | 意義 |
|---|---|---|
| (某人) | u | 使用者 |
| (某人) | g | 群組所有者 |
| (某人) | o | 其他 |
| (某人) | a | 全部(“world”) |
| (動作) | + | 增加權限 |
| (動作) | - | 移除權限 |
| (動作) | = | 指定權限 |
| (權限) | r | 讀取 |
| (權限) | w | 寫入 |
| (權限) | x | 執行 |
| (權限) | t | Sticky bit |
| (權限) | s | Set UID 或 GID |
如先前同樣使用 chmod(1) 指令來設定,但使用的參數為這些字元。 例如,您可以使用下列指令禁止其他使用者存取檔案 FILE:
% chmod go= FILE
若有兩個以上的符號表示可以使用逗號 (,) 區隔。 例如,下列指令將會移除群組及其他人對檔案 FILE 的寫入權限, 並使全部人(“world”)對該檔有執行權限。
% chmod go-w,a+x FILE
除了前面提到的檔案權限外,FreeBSD 支援使用 “檔案旗標”。 這些旗標增加了檔案的安全性及管理性,但不包含目錄。
檔案旗標增加了管理性,確保在某些時候 root 不會意外將檔案修改或移除。
修改的檔案 flag 僅需要使用擁有簡易的介面的 chflags(1) 工具。 例如,標示系統禁止刪除的旗標於檔案 file1,使用下列指令:
# chflags sunlink file1
若要移除系統禁止刪除的旗標,只需要簡單在 sunlink 前加上
“no”,例如:
# chflags nosunlink file1
使用 ls(1) 及參數 -lo 可檢視檔案目前的旗標:
# ls -lo file1
輸出的結果如下:
-rw-r--r-- 1 trhodes trhodes sunlnk 0 Mar 1 05:54 file1
多數的旗標僅能由 root 使用者來標示或移除,而部份旗標可由檔案所有者設定。 我們建議系統管理者可閱讀 chflags(1) 及 chflags(2) 說明以瞭解相關細節。
認識 FreeBSD 的目錄架構,就可對系統有概略的基礎理解。 最重要的莫過於整個目錄的根目錄,就是 “/” 目錄, 該目錄會在開機時最先掛載 (mount),裡面會有開機所會用到必備檔案。 此外,根目錄還有紀錄其他檔案系統的掛載點相關設定。
「掛載點」就是讓新增的檔案系統,能接到上層的檔案系統 (通常就是「根目錄」檔案系統)
的目錄。 在 Section 3.5 這邊對此有更詳細介紹。
標準的掛載點包括了 /usr、/var、 /tmp、/mnt 以及 /cdrom。 這些目錄通常會記錄在 /etc/fstab
設定檔內。 /etc/fstab 是記錄各檔案系統及相關掛載點的表格。
大部分在 /etc/fstab 有記錄的檔案系統,會在開機時由 rc(8) script
來自動掛載,除非它們有設定 noauto 選項。 其中細節說明可參閱
Section 3.6.1。
有關檔案系統架構的完整說明可參閱 hier(7)。 現在呢,讓我們大致先一窺常見的目錄有哪些吧。
| 目錄 | 說明 |
|---|---|
| / | 檔案系統的根目錄。 |
| /bin/ | single-user、multi-user 兩種模式皆可使用的基本工具 。 |
| /boot/ | 作業系統開機過程會用到的程式、設定檔。 |
| /boot/defaults/ | 預設的開機啟動設定檔,詳情請參閱 loader.conf(5) 。 |
| /dev/ | Device nodes,詳情請參閱 intro(4)。 |
| /etc/ | 系統設定檔及一些 script 檔。 |
| /etc/defaults/ | 預設的系統設定檔,詳情請參閱 rc(8)。 |
| /etc/mail/ | MTA(Mail Transport Agent)的相關設定檔,像是 sendmail(8)。 |
| /etc/namedb/ | named 設定檔,詳情請參閱 named(8)。 |
| /etc/periodic/ | 每日、每週、每月透過 cron(8); 執行的定期排程 script, 詳情請參閱 periodic(8)。 |
| /etc/ppp/ | ppp 設定檔,詳情請參閱 ppp(8)。 |
| /mnt/ | 系統管理者慣用充當臨時掛載點的空目錄。 |
| /proc/ | Process 檔案系統,詳情請參閱 procfs(5) 及 mount_procfs(8)。 |
| /rescue/ | 緊急救援用途的一些 statically linked 程式,詳情請參閱 rescue(8)。 |
| /root/ | root 帳號的家目錄。 |
| /sbin/ | 供 single-user 及 multi-user 環境使用的系統程式及管理工具 。 |
| /tmp/ | 臨時檔案。 一般而言,重開機之後 /tmp 內的東西會被清除掉。 而通常會將 memory-based 檔案系統掛載在 /tmp 上。 這些瑣事可透過 tmpmfs 相關的 rc.conf(5) 環境變數來自動完成 。(或是在 /etc/fstab 內做設定, 詳情請參閱 mdmfs(8)。) |
| /usr/ | 主要是使用者所安裝的工具程式、應用程式存放處。 |
| /usr/bin/ | 常用工具、開發工具、應用軟體。 |
| /usr/include/ | 標準 C include 的相關 header 檔案庫。 |
| /usr/lib/ | 函式庫存放處。 |
| /usr/libdata/ | 其他各式工具的資料檔。 |
| /usr/libexec/ | 系統 daemons 及系統工具程式(透過其他程式來執行)。 |
| /usr/local/ | 存放一些自行安裝的執行檔、函式庫等等。 同時,也是 FreeBSD ports 架構的預設安裝目錄。 /usr/local 內的目錄架構大致與 /usr 相同,詳情請參閱 hier(7) 說明。 但 man 目錄例外,它們是直接放在 /usr/local 底下,而非 /usr/local/share,而 ports 所安裝的說明文件則在 share/doc/port。 |
| /usr/obj/ | 在編譯 /usr/src 目錄時所產生的相關架構 object 檔案。 |
| /usr/ports | FreeBSD Ports Collection (optional)。 |
| /usr/sbin/ | 系統 daemon 及系統工具(直接由使用者執行)。 |
| /usr/share/ | 各架構皆共通的檔案。 |
| /usr/src/ | BSD 本身的原始碼(或自行新增的)。 |
| /usr/X11R6/ | X11R6 相關套件的執行檔、函式庫等(optional)。 |
| /var/ | 存放各種用途的 log 檔、臨時或暫時存放、列印或郵件的 spool 檔案。有時候,memory-based 檔案系統也會掛載在 /var。 這些瑣事可透過 varmfs 相關的 rc.conf(5) 環境變數來自動完成。(或是在 /etc/fstab 內做設定,相關細節請參閱 mdmfs(8)。) |
| /var/log/ | 各項系統記錄的 log 檔案。 |
| /var/mail/ | 各使用者的 mailbox 檔案。 |
| /var/spool/ | 各種印表機、郵件系統的 spool 目錄。 |
| /var/tmp/ | 臨時檔案。 這些檔案在重開機後通常仍會保留,除非 /var 是屬於 memory-based 檔案系統。 |
| /var/yp | 記錄 NIS maps。 |
FreeBSD 用來尋找檔案的最小單位就是檔案的名稱了。 檔案的名稱有大小寫之分,所以說 readme.txt 和 README.TXT 是兩個不同的檔案。 FreeBSD 並不使用副檔名 (.txt) 來判別這是一個程式檔、文件檔或是其他類型的檔案。
檔案存在目錄裡面。 一個目錄中可能沒有任何檔案,也可能有好幾百個檔案。 目錄之中也可以包含其他的目錄; 您可以建立階層式的目錄以便資料的管理。
檔案或目錄的對應是藉由給定的檔案或目錄名稱,然後加上正斜線符號 (/);之後再視需要加上其他的目錄名稱。 如果您有一個目錄 foo ,裡面有一個目錄叫作 bar,這個目錄中又包含了一個叫 readme.txt 的檔案,那麼這個檔案的全名,或者說檔案的路徑就是 foo/bar/readme.txt。
目錄及檔案儲存在檔案系統之中。 每個檔案系統都有唯一一個最上層的目錄,叫做根目錄 (root directory)。 然後在這個根目錄下面才能有其他的目錄。
到目前為止大概和其他您用過的的作業系統都差不多。 還是有些不一樣的地方就是了,例如 MS-DOS 用 \ 當檔案和目錄名稱的分隔符號,而 Mac OS® 則是用 : 符號。
FreeBSD 的路徑中並沒有使用磁碟機代號或其他的磁碟名稱。 因此,您不可以使用像 c:/foo/bar/readme.txt 這樣子的檔案名稱。
相對的,在 FreeBSD 系統中有一個檔案系統被指定為根檔案系統。 根檔案系統的根目錄由 / 表示。 然後其他的檔案系統再掛載 (mount) 在根檔案系統之下。因此無論您的 FreeBSD 系統上有多少顆硬碟,每一個目錄看起來就像在同一個磁碟上。
假設您有三個檔案系統,分別叫作 A、 B 及 C。 每個檔案系統都包含兩個目錄,叫做 A1、A2 (依此類推得 B1、B2 及 C1、C2)。
稱 A 為主要的檔案系統;如果您用 ls 指令查看此目錄的內容,您會看到兩個子目錄: A1 及 A2,如下所示:

一個檔案系統必須以目錄形式掛載於另一個檔案系統上。 因此,假設您將 B 掛載於 A1 之上,則 B 的根目錄就變成了 A1,而在 B 之下的任何目錄的路徑也隨之改變:

在 B1 或 B2 目錄中的任何檔案必須經由路徑 /A1/B1 或 /A1/B2 才能達到。 所有原來在 /A1 中的檔案會暫時被隱藏起來,直到 B 被「移除 (unmounted)」後才會再顯現出來。
如果 B 掛載在 A2 之上,則會變成:

上面的路徑分別為 /A2/B1 及 /A2/B2。
檔案系統可以掛在其他檔案系統的目錄之上。 延續之前的例子,C 檔案系統可以掛在檔案系統 B 的 B1 目錄之上,如圖所示:

或者 C 直接掛載於 A 的 A1 目錄之上:

如果您熟悉 MS-DOS 的話,這和 join 指令很類似 (雖然不儘相同)。
一般情況下您不需要擔心這些東西。 除非您要安裝新的磁碟,不然通常在您安裝 FreeBSD 時建立好檔案系統並決定好要掛載在何處之後就不會再做任何更動了。
您完全可以使用單一的一個大的根檔案系統 (root file system) 而不建立其他的檔案系統。 這樣有好處也有有壞處。
使用多個檔案系統的好處
不同的檔案系統在掛上的時候可以有不同的 掛載參數。 舉例來說,為求謹慎您可以將根檔案系統設成唯讀, 以避免不小心刪除或修改掉重要的檔案。 將使用者可寫入的檔案系統 (例如 /home) 獨立出來也可以讓他們用 nosuid 的參數掛載,此選項可以讓在這個檔案系統中執行檔的 suid/guid bits 失效,也許可以讓系統更安全。
FreeBSD 會自動根據您檔案系統的使用方式來做最佳的檔案配置方式。 因此,一個有很多小檔案、 常常寫入的檔案系統跟只有幾個較大的檔案的檔案系統配置是不一樣的。 如果您只有單一一個大的檔案系統,這部分就沒用了。
FreeBSD 的檔案系統在停電的時候很穩固。 然而,在某些重要的時候停電仍然會對檔案系統結構造成損害。 分割成許多個檔案系統的話在系統在停電後比較能夠正常啟動, 以便您在需要的時候將備份資料回存回來。
使用單一檔案系統的好處
檔案系統的大小是固定的。 您當初安裝 FreeBSD 的時候應該會給定一個大小,可是後來您可能會想把空間加大。 如果沒有備份的話是很難達成的; 您必須將檔案系統重新建立為您需要的大小,然後將備份回存回來。
Important: FreeBSD 的 growfs(8) 指令可以突破此限制直接變更檔案系統的大小。
檔案系統包含在分割區裡面。 因為 FreeBSD 承襲 UNIX 架構,這邊講的分割區和一般提到的分割區 (例如 MS-DOS 分割區) 不同。 每一個分割區由一個代號(字母)表示,從 a 到 h。 每個分割區只能包含一個檔案系統。 因此除了說常見到用檔案系統同的掛載點來表示檔案系統外, 也可以用包含他的分割區代號來表示。
FreeBSD 也會拿磁碟空間來當 swap space。 Swap space 給 FreeBSD 當作虛擬記憶體用。 這讓您的電腦好像擁有比實際更多的記憶體。 當 FreeBSD 的記憶體用完的時候,它會把一些目前沒用到的資料移到 swap space,然後在用到的時候移回去 (同時移出部份沒用到的)。
某些分割區有慣例的使用方式如下:
| 分割區 | 慣例 |
|---|---|
| a | 通常包含根檔案系統 (root file system) |
| b | 通常是 swap space |
| c | 通常和整個 slice 的大小一樣,給一些會用到整個 slice 的工具程式 (例如硬碟壞軌檢查工具) 來使用。 一般來說您應該不會把檔案系統建立在這個分割區。 |
| d | 分割區 d 曾經有代表特殊意義,但是已經不再使用。 所以現在 d 就和其他一般的分割區相同了。 |
每個包含有檔案系統的分割區是存在所謂的 slice 裡面。 FreeBSD 的 slice 就是指平常我們稱為分割區 (partition) 的東西。 同樣地,會這樣子稱呼也是因為 FreeBSD 的 UNIX 色彩。 而 slice 是有編號的,從 1 號編到 4 號。
slice 號碼跟在裝置名稱後面,先接一個字母 s,然後從 1 號開始編下去。 因此 “da0s1” 就是指第一個 SCSI 硬碟的第一個 slice。 一個磁碟上只能有四個實體的 slice,但是在實體的 slice 中您可以塞進適當類型的邏輯 slice。 這些延伸的 slice 編號從 5 開始,所以 “ad0s5” 是第一個 IDE 硬碟上的第一個延伸 slice。 檔案系統在裝置 (device) 裡就是在一個 slice 之中。
Slices、“dangerously dedicated” 模式的實體磁碟機,以及其他包含分割區(partition) 的磁碟都是以字母 a 到 h 的編號來表示。 編號是接在裝置名稱的後面的,因此 “da0a” 是磁碟機 da 上的第一個 “dangerously dedicated”模式之分割區。 而 “ad1s3e” 則是第二顆 IDE 硬碟上第三個 slice 的第五個分割區。
最後,我們就可以把系統上的每個磁碟都區分出來了。 一個磁碟的名稱會有一個代碼來表示這個磁碟的類型,接著是一個數字, 表示這是哪一個磁碟。 這邊跟 slice 每個磁碟編號從 0 開始不一樣。 常見的代碼可以參考 Table 3-1。
當要參照一個分割區的時候,FreeBSD 會要您一併輸入包含這個分割區的 slice 及磁碟機名稱;當要參照一個 slice 的時候,也必須輸入包含這個 slice 的磁碟名稱。 怎麼做呢?首先先列出磁碟名稱,然後 s 加上 slice 編號,最後再輸入分割區字母代號。 範例可以參考 Example 3-1.
Example 3-2 示範了一個基本的磁碟分布模式,相信對您有些幫助。
要安裝 FreeBSD,您必須先建置磁碟的 slice,接著於 slice 中建立要給 FreeBSD 用的分割區。 最後在這些分割區中建立檔案系統 (或 swap space) 並決定要將這些檔案系統掛載於哪裡。
檔案系統就像一顆樹。/ 就像是樹根,而 /dev,/usr 以及其他在根目錄下的目錄就像是樹枝,而這些樹枝上面又還有分支,像是 /usr/local 等。
因為某些原因,我們會將一些目錄分別放在不同的檔案系統上。 如 /var 包含了可能會滿出來的 log/,spool/ 等目錄以及各式各樣的暫存檔。 把根檔案系統塞到滿出來顯然不是個好主意,所以我們往往會比較傾向把 /var 從 / 中拉出來。
另一個常見到把某些目錄放在不同檔案系統上的理由是: 這些檔案在不同的實體或虛擬磁碟機上。 像是網路檔案系統 (Network File System) 或是光碟機。
在 /etc/fstab 裡面有設定的檔案系統會在開機 的過程中自動地被掛載 (除非該檔案系統有被加上 noauto 參數)。
/etc/fstab 檔案內容的格式如下:
device /mount-point fstype options dumpfreq passno
裝置名稱 (該裝置必須真的存在)。 詳情請參閱 Section 18.2.
檔案系統要掛載到的目錄 (該目錄必須真的存在)。
檔案系統類型,這是要傳給 mount(8) 的參數。 FreeBSD 預設的檔案系統是 ufs。
可讀可寫的檔案系統用 rw,而唯讀的檔案系統則是用 ro,後面視需要還可以加其他選項。 常見的選項如 noauto 是用在不要於開機過程中自動的掛載的檔案系統。 其他選項可參閱
mount(8) 說明。
dump(8) 由此項目決定那些檔案系統需要傾印。 如果這格空白則以零為預設值。
這個項目決定檔案系統檢查的順序。 對於要跳過檢查的檔案系統,它們的 passno 值要設為零。 根檔案系統的 passno 值應設為一 (因為需要比所有其他的還要先檢查),而其他的檔案系統的 passno 值應該要設得比一大。 若有多個檔案系統具有相同的 passno 值,則 fsck(8) 會試著平行地(如果可能的話)檢查這些檔案系統。
更多關於 /etc/fstab 檔案格式及選項的資訊請參閱 fstab(5) 說明文件。
mount(8) 指令是拿來掛載檔案系統用的。
基本的操作指令格式如下:
在 mount(8) 裡面有提到一大堆的選項,不過最常用的就是這些:
掛載選項
-a把 /etc/fstab 裡面所有還沒有被掛載、沒有被標記成 “noauto”
而且沒有用 -t 排除的檔案系統掛載起來。
-d執行所有的動作,但是不真的去呼叫掛載的 system call。 這個選項和 -v 搭配拿來推測 mount(8)
將要做什麼動作時很好用。
-f強迫掛載不乾淨的檔案系統 (危險),或是用來強制取消寫入權限 (把檔案系統的掛載狀態從可存取變成唯讀)。
-r用唯讀的方式掛載檔案系統。 這個選項和在 -o 選項中指定
ro (在 FreeBSD 5.2之前的版本是用 rdonly) 參數是一樣的。
-t fstype用指定的檔案系統型態 (fstype) 來掛載指定的檔案系統,或是在有 -a 選項時只掛載指定型態的檔案系統。
預設的檔案系統是 “ufs”。
-u更新檔案系統的掛載選項。
-v顯示較詳細資訊。
-w以可存取的模式掛載檔案系統。
-o 選項後面會接著以逗號分隔的參數,例如:
不允許在這個檔案系統上執行二進位程式碼, 這也是一個蠻有用的安全選項。
不解析檔案系統上的 setuid 或 setgid 旗標, 這也是一個蠻有用的安全選項。
umount(8)
指令的參數可以是掛載點 (mountpoint),裝置名稱,以及 -a 或是
-A 等選項。
加上 -f 可以強制卸載,加上 -v
則是會顯示詳細資訊。 要注意的是一般來說用 -f
並不是個好主意,強制卸載檔案系統有可能會造成電腦當機, 或者損壞檔案系統內的資料。
-a 和 -A
是用來卸載所有已掛載的檔案系統,另外還可以用 -t
來指定要卸載的是哪些種類的檔案系統。 要注意的是 -A
並不會試圖卸載根檔案系統。
FreeBSD 是一個多工的作業系統,也就是說在同一時間內可以跑超過一個程式。 每一個正在花時間跑的程式就叫做 程序 (process)。 您下的每個指令都至少會開啟一個新的程序, 而有些系統程序是一直在跑以維持系統正常運作的。
每一個程序都有一個不重覆的數字叫做 process ID ,或稱為 PID ,而且就像檔案一樣,每一個程序也有擁有者及群組。 擁有者及群組的資訊是用來決定什麼檔案或裝置是這個程序可以開啟的 (前面有提到過檔案權限)。 大部份的程序都有父程序。 父程序是開啟這個程序的程序,例如:您對 shell 輸入指令,shell 本身就是一個程序,而您執行的指令也是程序。 每一個您用這種方式跑的程序的父程序都是 shell。 有一個特別的程序叫做 init(8) 是個例外。init 永遠是第一個程序,所以他的 PID 一直都會是 1。 在 FreeBSD 開機的時候 init 會自動地被 kernel 開啟。
要看系統執行中的程序,有兩個相當有用的指令可用: ps(1) 以及 top(1)。ps 指令是用來列出正在執行之程序,而且可以秀它們的 PID、用了多少記憶體、執行的指令名稱及其後之參數是什麼等等。 top 指令則是顯示所有正在執行的程序, 並且數秒鐘更新一次。因此您可以互動式的觀看您的電腦正在做什麼。
在預設的情況下,ps 指令只會顯示您所擁有的的程序。 例如:
% 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
在這個範例裡可以看到 ps(1) 的輸出分成好幾個欄位。 PID 就是前面有提到的 process ID。 PID 的分配是從 1 開始一直到 99999,如果用完的話又會繞回來重頭開始分配 (若該 PID 已經在用了,則 PID 不會重新分配)。 TT 欄位是指這個程式在哪個 tty 上執行,在這裡可以先忽略不管。STAT 是程式的狀態,也可以先不要管。TIME 是這個程式在 CPU 上執行的時間——這通常不是程式總共花的時間, 因為當您開始執行程式後,大部份的程式在 CPU 上執行前會先花上不少時間等待 。 最後,COMMAND 是執行這個程式的命令列。
ps(1)
有幾個不同的選項組合可以用來變更顯示出來的資訊,其中一個最有用的組合是 auxww。 a
可以顯示所有正在跑的程序的指令,不只是您自已的。 u
則是顯示程序的擁有者名稱以及記憶體使用情況。 x 可以把 daemon
程序顯示出來, 而 ww 可讓 ps(1)
顯示出每個程序完整的內容, 而不致因過長而被螢幕截掉了。
top(1) 也有類似的輸出。 一般的情況看像是這樣:
% 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 ...
輸出的資訊分成兩個部份。開頭 (前五行) 秀出最近一個程序的 PID、系統平均負載 (系統有多忙錄的測試)、系統的開機時間 (從上次重開算起) 以及現在的時間等。 在開頭裡面的其他數字分別是在講有多少程序正在執行 (在本例中為47)、有多少記憶體及 swap space 被占用了,還有就是系統分別花了多少時間在不同的 CPU 狀態上。
接下來的部份是由好幾個欄位所構成,和 ps(1) 輸出的資訊類似。 就如同前例,您可以看到 PID、使用者名稱、CPU 花費的時間以及正在執行的指令。 top(1) 在預設的情況下還會告訴您程序用掉了多少的記憶體空間。 在這邊會分成兩欄,一個是總用量 (total size),另一個是實際用量 (resident size)——總用量是指這個應用程式需要的記憶體空間, 而實際用量則是指實際上該程式的記憶體使用量。 在這個例子裡面您可以看到 Netscape® 要了幾乎到 30 MB 的 RAM,但是只有用到 9 MB。
top(1) 每隔 2
秒鐘會自動更新顯示內容,可用 s 選項來改變間隔的時間。
當在執行文書編輯器時,您可以很容易地使用它,叫它讀取檔案或是什麼的。 可以這樣做是因為編輯器有提供這些功能, 還有就是編輯器依附在一個終端機 (Terminal) 之上。 有些程式並不是設計成一直在接收使用者的輸入的, 所以它們在一開始執行的時候就從終端機斷開了。 例如說, 網頁伺服器整天都在回應網頁方面的要求,它通常不需要您輸入任何東西。 另外,像是把信從一個站傳送到另一個站的程式,也是這種類型的應用程式。
我們把這種程式稱作 daemon。 Daemon (惡魔、守護神) 是希臘神話中的角色:祂們不屬於善良陣營或邪惡陣營,是守護的小精靈。 大致上來說祂們就是在替人類做一些有用的事情, 跟今天的網頁伺服器或是郵件伺服器很像。 這也就是為何 BSD 的吉祥物,長期以來都是一隻穿著帆布鞋拿著三叉耙的快樂小惡魔的原因。
通常來說 deamon 程式的名字後面都會加一個字母 “d”。 BIND 是 Berkeley Internet Name Domain 的縮寫 (但實際上執行的程式名稱是 named)、Apache 網頁伺服器的程式名稱是 httpd、印表機服務程式是 lpd,依此類推。 這是習慣用法,並沒有硬性規定,例如 Sendmail 主要的寄信 daemon 是叫做 sendmail 而不是 maild,跟您想像的不一樣。
有些時候會需要跟某個 daemon 程序溝通, 這些溝通是透過所謂的信號(signal)來傳遞給該 daemon 程序(或是其他執行中的程序)。 藉由送出信號,您可以和一個 daemon (或是任何一個正在跑的程序) 溝通。 信號有很多種——有些有特定的意義,有些則是會由應用程式來解讀。 應用程式的說明文件會告訴您該程式是如何解讀信號的。 您只能送信號給您擁有的程序,送 kill(1) 或 kill(2) 的信號給別人的程序是不被允許的。 不過 root 不受此限制,他可以送信號給任何人的程序。
FreeBSD 本身在某些情況也會送信號給應用程式。 假設有個應用程式寫得很爛,然後企圖要存取它不該碰的記憶體的時候,FreeBSD 會送一個 Segmentation Violation 信號 (SIGSEGV) 給這個程序。 又如果有一個應用程式用了 alarm(3) 的 system call 要求系統在過一段時間之後叫他一下,時間到了的時候鬧鐘的信號 (SIGALRM) 就會被送出了,其他的依此類推。
SIGTERM and SIGKILL 這兩個信號可以拿來終止程序。 用 SIGTERM 結束程序是比較有禮貌的方式,該程序會捕捉 (catch) 這個信號而了解到您想要把他關掉。 接著下來它會把它自已開的記錄檔通通關掉, 然後在關掉程序之前結束掉手邊的工作。 在某些情況下程序有可能會裝作沒看見 SIGTERM,假如它正在做一些不能中斷的工作的話。
SIGKILL 就沒有辦法被程序忽略了。 這是一個“我管你正在幹嘛,現在就給我停下來”的信號。 如果您送了 SIGKILL 信號給某個程序,FreeBSD 將會把它停掉[4]。
這些是其他您有可能會要用到的信號: SIGHUP,SIGUSR1,以及 SIGUSR2。 這些是通用的信號,當送出時不同的應用程式會有不同的反應。
假設您更動了您的網頁伺服器的設定檔—— 您想要叫網頁伺服器去重新讀取設定值。 您可以關閉後再重新啟動 httpd,但是這麼做會造成網頁伺服器暫停服務一段時間, 這樣子可能不太好。 大部份的 daemon 都寫成會去回應 SIGHUP。 當收到這個信號之後,它們會去重新讀取自已的設定檔。 因此您可以用送 SIGHUP 信號來取代關掉重開。 又因為沒有標準在規範如何回應這些信號,不同的 daemon 可能會有不同的行為,所以有疑問的話請先確認並翻閱 deamon 的說明文件。
信號是由 kill(1) 指令送出的,如範例所示:
送信號給程序
這個範例將會示範如何送一個信號給 inetd(8)。 inetd 的設定檔是 /etc/inetd.conf,而 inetd 會在收到 SIGHUP 的時候重新讀取這個設定檔。
找出您想要送信號的那個程序的 ID。 您會用到 ps(1) 以及 grep(1) 這兩個指令。
grep(1)
是用來在輸出中搜尋, 找出您指定的字串。 這個指令是由一般使用者執行,而 inetd(8) 是由 root 執行,所以在使用 ps(1) 時需要加上 ax 選項。
% ps -ax | grep inetd 198 ?? IWs 0:00.00 inetd -wW
因此可知 inetd(8) 的 PID 為 198。 在某些情況下 grep inetd 這個指令本身也會出現在輸出裡。 這是因為 ps(1) 乃是找所有執行中的程序的方式造成的。
用 kill(1) 來送信號。 又因為 inetd(8) 是由 root 執行的,您必須用 su(1) 切換成 root先。
% su Password: # /bin/kill -s HUP 198
一般情況對大多數 UNIX 指令來講,當 kill(1) 執行成功時並不會輸出任何訊息。 假設您送一個信號給某個不是您所擁有的程序, 那麼您就會吃到這個錯誤訊息: “kill: PID: Operation not permitted”。 而如果您打錯 PID 的話,那就會把信號送給錯誤的程序。 這樣可能會很糟, 不過如果您夠幸運的話,可能剛好就只是把信號送給一個非使用中的 PID,那您就只會看到 “kill: PID: No such process” 而已。
為什麼用 /bin/kill?: 很多 shell 有提供內建的 kill 指令。 也就是說這種 shell 會直接送信號,而不是執行 /bin/kill。 這樣是蠻方便的沒錯啦,但是不同的 shell 會有不同的語法來指定信號的名稱等。 與其嘗試去把它們通通學會,不如就單純的直接用 /bin/kill ... 吧。
要送其他的信號的話也是非常類似,就視需要把指令中的 TERM 或 KILL 替換掉即可。
在 FreeBSD 中,很多日常的工作是在一個叫做 shell 的文字介面中完成的。 Shell 的主要工作就是從輸入中收到命令並執行它們。 許多 shell 也有內建一些有助於日常工作的指令, 像是檔案管理、檔案比對、命令列編輯、指令巨集以及環境變數等。 FreeBSD 有內附了幾個 shell,像是 sh, Bourne Shell,以及 tcsh,改良版的 C-shell。 還有許多其他的 shell 可以從 FreeBSD Ports Collection 中取得,像是 zsh 以及 bash 等。
您用哪個 shell 呢? 其實每個人的喜好都不一樣。 如果您是一個 C 程式設計師,那對於使用像是 tcsh 這種 C-like 的 shell 可能會感到相當愉快。 如果你是從 Linux 跳過來的,或者您是一個 UNIX 新手,那您也許會想要用 bash 來當作文字介面。 每一個 shell 都有自已獨特之處,至於這些特點能不能配合您的工作環境? 那就是您選擇 shell 的重點了。
檔名自動補齊就是常見的 shell 功能。 首先輸入指令或檔案的前幾個字母,這時通常您只需要按下 Tab 鍵,接下來 shell 就會自動把指令或是檔案名稱剩餘的部份補齊。 假設您有兩個檔案分別叫作 foobar 及 foo.bar。 現在要刪掉 foo.bar,那麼可以輸入: rm fo[Tab].[Tab]
Shell 會印出這個: rm foo[嗶].bar。
[嗶] 是 console 的響鈴,這嗶的一聲是 shell 在告訴我說它沒有辦法完全自動補齊檔名,因為有不只一個檔名符合條件。 foobar 和 foo.bar 都是 fo 開頭的檔名,不過它至少可以補齊到 foo。 如果您接著輸入 . 然後再按 Tab 一次,那 shell 就能夠替您把剩下的檔名填滿了。
Shell 的另一項特點是使用了環境變數。 環境變數是以變數與鍵值(variable/key)的對應關係儲存於 shell 的環境空間中,任何由 shell 所產生的程序都可以讀取此空間, 因此這個空間儲存了許多程序的設定組態。 在此附上 一份常見環境變數與其涵義的列表:
| 變數 | 詳細說明 |
|---|---|
| USER | 目前登入的使用者名稱。 |
| PATH | 以冒號(:)隔開的目錄列表,用以搜尋執行檔的路徑。 |
| DISPLAY | 若存在這個環境變數,則代表 X11 連結顯示器的網路名稱。 |
| SHELL | 目前使用的 shell。 |
| TERM | 使用者終端機的名稱,能藉由此變數判斷終端機的能力。 |
| TERMCAP | Database entry of the terminal escape codes to perform various terminal functions. |
| OSTYPE | 作業系統的種類,如:FreeBSD。 |
| MACHTYPE | 目前系統所用的 CPU 架構。 |
| EDITOR | 使用者偏好的文字編輯器。 |
| PAGER | 使用者偏好的文字分頁器(text pager)。 |
| MANPATH | 以冒號(:)隔開的目錄列表,用以搜尋 manual pages 的路徑。 |
在不同的 shell 底下設定環境變數的方式也有所不同。 舉例來說,在 C-Style 的 shell 底下,像是 tcsh 和 csh,你必須使用 setenv 來設定環境變數。 但在 Bourne shells 底下,像是 sh 和 bash,你則必須使用 export 來設定你所使用的環境變數。 再舉個例子來說,若要設定或是修改 EDITOR 這個環境變數,在 csh 或 tcsh 下設定 EDITOR 這個環境變數為 /usr/local/bin/emacs 的指令是:
% setenv EDITOR /usr/local/bin/emacs
在 Bourne shells 下則是:
% export EDITOR="/usr/local/bin/emacs"
大多數的 shell 都支援使用者在命令列中將 $ 字元放在變數之前,以取得環境變數的值。 舉例來說,echo $TERM 會 顯示出 $TERM 的設定值,這是因為 shell 取得了 $TERM 的設定值, 並將其傳給 echo 顯示出來。
Shell 中有某些特別的字元是來表示特殊的資料,我們將其稱作 meta-characters。 其中最常見的是 * 字元,他代表了檔名中的任意字元。 這些特殊字元可以用在檔名展開(filename globbing)上,舉例來說,輸入 echo * 會和輸入 ls 得到幾乎相同的結果,這是因為 shell 會將所有符合 * 字元的檔案傳到命令列上,再由 echo 顯示出來。
為了避免 shell 轉譯這些特殊字元,我們可以在這些特殊字元前放一個反斜線 (\) 字元使他們跳脫(escape) shell 的轉譯。舉例來說, echo $TERM 會印出你目前設定的終端機格式, echo \$TERM 則會直接印出 $TERM 這幾個字。
變更 shell 最簡單的方法就是透過 chsh 命令。 執行 chsh 將會呼叫環境變數中 EDITOR 指定的文字編輯器。 如果沒有設定,則預設是 vi。 請依照需求去修改 “Shell:” 的值。
你也可以透過 chsh 的參數 -s,
這可以直接設定你的 shell 而不需要透過任何文字編輯器。 例如, 假設想把所用的 shell 改為
bash, 可以透過下列的方式:
% chsh -s /usr/local/bin/bash
Note: 你所使用的 shell 必須 列於 /etc/shells 裡頭。 如果是由 Ports Collection 來裝 shell, 那這個步驟已經完成了。 但若是手動安裝了一個 shell, 那麼就必須為新安裝的 shell 進行設定。
舉例來說,若手動安裝了 bash 並將它置於 /usr/local/bin 底下,你還得:
# echo "/usr/local/bin/bash" >> /etc/shells然後再重新執行 chsh。
在 FreeBSD 中有許多設定必須透過編輯文字檔完成。 因此,若能熟悉文字編輯器是再好不過的。 FreeBSD 本身(指 base system)就附有幾種文字編輯器, 此外,你也可以透過 Ports Collection 來安裝其他的文字編輯器。
最簡單易學的文字編輯器叫做 ee, 代表了其全名 easy editor。 要開始使用 ee, 必須在命令列上輸入 ee filename, 這邊的 filename 代表你想要編輯的檔案名稱。 舉例來說,要編輯 /etc/rc.conf,就要輸入 ee /etc/rc.conf。 而在 ee 的操作介面下, 所有編輯器的功能與操作都會顯示在螢幕的正上方。 其中的插入符號(^)代表鍵盤上的 Ctrl 鍵,所以 ^e 就等同於 Ctrl+e 。 若要結束 ee,請按下 Esc 鍵,接著選擇 leave editor 即可。 此時如果該檔案有修改過,編輯器會提醒你是否要存檔。
此外,FreeBSD 也內附了幾個好用的文字編輯器,像是 base system 的 vi 及 FreeBSD Ports Collection 內的其他編輯器, 比如 Emacs 及 vim (editors/emacs 及 editors/vim)。 這些文字編輯器提供更強的功能,但是也比較難學習。 然而若要從事大量文字編輯工作, 那麼花點時間來學習這些好用的編輯器, 會在日後為您省下更多的時間。
設備(device)主要是指跟硬體比較有關的術語, 包括磁碟、印表機、顯示卡和鍵盤。 FreeBSD 開機過程當中, 大多數硬體通常都能偵測到並顯示出來,也可以查閱 /var/run/dmesg.boot 內有開機的相關訊息。
舉例來說,acd0即為第一台 IDE 光碟機的代號, 而 kbd0 則代表鍵盤。
在 UNIX 作業系統, 大部分的設備都是透過叫做 device nodes(設備節點)的特殊檔案來作存取, 而這些檔案都位於 /dev 目錄。
若要在系統上建立新節點,或者是要編譯某些新硬體的支援軟體, 那麼就要先新增設備節點。
設備檔案系統(或稱為 DEVFS) 是指在整體檔案系統 namespace 提供 kernel 的設備 namespace。 DEVFS 乃是維護這些檔案系統,而不能新增或修改這些設備節點。
細節請參閱 devfs(5) 說明。
若要知道為何 FreeBSD 是採用 elf(5) 格式,必先瞭解當前 UNIX 系統中三種“影響最為重大”的可執行檔相關背景:
最古老、“經典” 的 UNIX object 檔格式。 It uses a short and compact header with a magic number at the beginning that is often used to characterize the format (see 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.
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 brandelf(1) for more information.
FreeBSD comes from the “classic” camp and used the 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.
在使用 FreeBSD 時,最詳細的使用說明莫過於 man 線上說明。 幾乎各程式都會有附上簡短說明,以介紹該程式的基本功能跟相關參數用法。 可以透過 man 指令來閱讀這些說明,而 man 指令的使用相當簡單易懂:
% man command
command 處就是想要知道的指令。 舉個例子, 若要知道 ls 的詳細用法,就可以打:
% man ls
而各線上說明因為性質不同,而區分為下列的數字章節:
使用者指令。
系統呼叫(System call) 及錯誤代號。
C 語言函式庫。
各設備的驅動程式。
檔案格式。
小遊戲程式及其他娛樂程式。
雜項工具、其他資訊。
系統維護、操作的指令。
Kernel 開發用途。
有些情況會有同樣主題但不同章節。 舉個例子,系統內會有 chmod
指令,但也有 chmod() 系統呼叫。 在這種情況,man 應該要指定所要查詢的章節:
% man 1 chmod
如此一來就會查 chmod 指令部分。 通常在寫文件時會把有參考到某特定章節的 man 號碼也一併寫在括號內。 所以 chmod(1) 就是指 chmod 指令,而 chmod(2) 則是指系統呼叫的部分。
如果您已經知道命令的名稱,只是不知道要怎樣使用的話,那就比較好辦。
但若不知道要用哪個指令時,該怎麼辦呢? 這個時候,就可以利用 man
的搜尋關鍵字功能, 以在各說明的介紹部分搜尋相關字眼。,它的選項是 -k:
% man -k mail
如此一來會看到一堆有 “mail” 關鍵字的說明, 事實上該功能與 apropos 指令是一樣的。
而有時你會看到像是 /usr/bin 有許多看起來頗炫的指令,但不知其用途? 只要簡單輸入:
% cd /usr/bin % man -f *
或者是
% cd /usr/bin % whatis *
這兩者的指令效果是一樣的。
FreeBSD 有許多程式跟工具來自於自由軟體基金會(FSF)。 除了 man 線上說明之外,這些程式提供了另外一種更具有彈性的 hypertext 格式文件, 叫做 info。 可以用 info 指令來閱讀,或者若有裝 emacs 亦可透過 emacs 的 info 模式閱讀。
要用 info(1) 指令,只需打:
% info
按 h 會有簡單說明,而若要快速查閱相關操作方式, 則請按 ?。
儘管 FreeBSD 在 base system 已加了很多系統工具。 然而,在實務運用上,您可能仍需要安裝額外的軟體。 FreeBSD 提供了 2 種安裝應用程式的套件管理系統︰Ports Collection (以 soucre 來編譯、安裝) 和 package(預先編譯好的 binary 檔)。 上述的方式,無論要用哪一種,都可以由像是 CDROM 等或網路上來安裝想裝的最新版軟體。
讀完這章,您將了解:
如何以 packages 來安裝軟體。
如何以 ports 來安裝軟體。
已安裝的 packages 或 ports 要如何移除。
如何更改(override) ports collection 所使用的預設值。
如何在套件管理系統中,找出想裝的軟體。
如何升級已安裝的軟體。
通常要在 UNIX 系統上安裝軟體時,有幾個步驟要作:
先下載該軟體壓縮檔(tarball),有可能是原始碼或是 binary 執行檔。
解開該壓縮檔。(通常是以 compress(1) , gzip(1) 或 bzip2(1) 壓縮的)
閱讀相關文件檔,以了解如何安裝。(通常檔名是 INSTALL 或 README ,或在 doc/ 目錄下的一些文件)
如果所下載的是原始碼,可能要先修改 Makefile 或是執行 ./configure 之類的 script ,接著再編譯該軟體。
最後測試再測試與安裝。
如果一切順利的話,就這麼簡單。 如果在安裝非專門設計(移植)給 FreeBSD 的軟體時出問題, 那可能需要修改一下它的程式碼,才能正常使用。
當然,我們可以在 FreeBSD 上使用上述的傳統方式來安裝軟體, 但是,我們還有更簡單的選擇。 FreeBSD 提供了兩種省事的軟體管理機制: packages 和 ports。 就在寫這篇文章的時候, 已經有超過 20,000 個 port 軟體可以使用。
所謂的 FreeBSD package 就是別人把該應用程式編譯、打包完畢。 該 package 會包括該應用程式的所有執行檔、設定檔、文件等。 而下載到硬碟上的 package 都可透過 FreeBSD 套件管理指令來進行管理,比如: pkg_add(1)、pkg_delete(1)、pkg_info(1) 等指令。 所以,只需簡單打個指令就可輕鬆安裝新的應用程式了。
而 FreeBSD port 則是用一些檔案,來自動處理應用程式的安裝流程。
請記住:如果打算自己來編譯的話,需要執行很多操作步驟 (下載、解壓、patch、編譯、安裝)。 而 port 呢,則是涵蓋所有需要完成這些工作的必備步驟, 所以只需打一些簡單的指令,那些原始程式碼就會自動下載、解壓、 patch、編譯,直至安裝完畢。
事實上,ports 機制還可以用來產生 packages,以便他人可以用 pkg_add 來安裝, 或是稍後會介紹到的其他套件管理指令。
而 packages 以及 ports 它們都是一樣會認 dependencies(軟體相依關係)。 假設:您想安裝某程式,但它有相依另一個已裝的函式庫(library), 而在 FreeBSD 的 port 以及 package 都有這程式以及該函式庫了。 所以無論是用 pkg_add 指令或者 port 方式來裝該程式, 這兩者(package、port)都會先檢查有沒有裝該函式庫, 若沒有就會自動先裝該函式庫了。
這兩種技術都很相似,您可能會好奇為什麼 FreeBSD 會弄出這兩種技術來呢。 其實,packages 和 ports 都有它們各自的長處, 使用哪一種完全取決於您自己的喜好。
Package 好處在於:
同樣是壓縮過的 package 與原始碼 tarball 相比, 前者通常會比後者小多了。
package 並不需再進行編譯。 對大型應用程式如 Mozilla、 KDE、 GNOME 而言,這點顯得相當重要, 尤其是使用速度緩慢的機器。
不需要瞭解如何在 FreeBSD 上編譯軟體的相關細節過程, 即可使用 package。
Ports 好處在於:
為了讓 package 能在大多數系統上順利執行, 通常在編譯時會使用比較保守的選項。 然而, 透過 port 安裝的話,則可針對特定環境(比如: Pentium 4 或 Athlon CPU) 來調整選項,以符合需求。
有些程式在編譯時,會有一些選項可以選擇。 舉例來說,Apache 可以設定一大堆的編譯選項。 若透過 port 來安裝的話, 會比較彈性多了,可以自己選而不必使用預設的編譯選項。
在某些情況,同樣的程式但不同編譯選項,則會分成不同的 package。 比如: Ghostscript 會因為是否要裝 X11 server, 而劃分為 ghostscript 以及 ghostscript-nox11 這兩種 package。 如此的調整對 package 算是可成立的, 但若該程式有一個以上或兩種不同的編譯選項時, 這對 package 就沒辦法了。
某些軟體的禁止以 binary 方式散佈, 或者說必須以原始碼方式散佈才可。
有些人並不信任 binary 套件機制,因為他們覺得至少有原始碼, (理論上)就可以自己檢閱,並尋找是否有潛在的問題。
若要對軟體加上自己改過的 patch, 那麼就必須要先有原始碼才能去上相關 patch 修正。
有些人喜歡有原始碼在手邊, 所以他們無聊時就可以自己閱讀、鑽研、借用 (當然要符合原始碼本身的授權規定)原始碼等等。
若想注意 port 更新動態的話,可以訂閱 FreeBSD ports 郵遞論壇 以及 FreeBSD ports bugs 郵遞論壇。
Warning: 在安裝軟體前,最好先看 http://vuxml.freebsd.org/ 內是否有該軟體的安全漏洞通報。
此外,也可以裝 ports-mgmt/portaudit,它會自動檢查所有已裝的 的軟體是否有已知的安全漏洞,另外,它還會在裝軟體的編譯過程前先行檢查。 也可以在裝了某些軟體之後,用 portaudit -F -a 來作全面強制安檢。
本章接下來將介紹如何在 FreeBSD 使用 package 及 port 來安裝、管理 third-party 軟體。
在安裝任何軟體之前,你必須先了解你想要什麼的軟體, 以及該軟體叫做什麼名稱。
FreeBSD 上可裝的軟體清單不斷在增加中, 不過,我們很慶幸有幾種方式可以來找你想裝的軟體:
FreeBSD 網站上有更新頻繁的軟體清單,在 http://www.FreeBSD.org/ports/ 。 各 ports 皆依其性質而分門別類,既可以透過軟體名稱來搜尋 (如果知道名字的話), 也可以在分類中列出所有可用的軟體。
由 Dan Langille 所維護 FreshPorts 網站,網址在 http://www.FreshPorts.org/。 FreshPorts 會不斷追蹤 port tree 中的各種變化, 也可以針對某些 port 以列入 “追蹤名單(watch)” 內, 當有任何軟體升級時,就會發 email 提醒。
如果不知道想裝的軟體名稱,那麼可透過像是 FreshMeat (http://www.freshmeat.net/) 這類的網站來找, 如果找到了,可以回 FreeBSD 網站去看一下這個應用程式是否已經被 port 進去了。
若知道該 port 的正確名稱,但不知道放在哪個分類目錄,可以用 whereis(1) 指令來找出來。 只要打 whereis file 即可,而 file 的地方請改為想裝的軟體名稱。 若找到該軟體,就會告訴你,就像下面這樣:
# whereis lsof lsof: /usr/ports/sysutils/lsof
如此一來,就會知道 lsof (系統工具程式) 是放在 /usr/ports/sysutils/lsof 目錄。
此外,也可以用 echo(1) 輕鬆找出該 port 是位於 porte tree 的何處。 舉例來說:
# echo /usr/ports/*/*lsof* /usr/ports/sysutils/lsof
請注意,這也會顯示 /usr/ports/distfiles 目錄內有符合檔名的檔案。
還有另一招,就是用 Ports Collection 本身內建的搜尋機制。 要用的時候,請先切換到 /usr/ports 目錄。 然後,打 make search name=程式名稱 ,其中 程式名稱 請改為想找的軟體名稱。 舉例來說,若要找的是 lsof 的話,那麼就是:
# cd /usr/ports # make search name=lsof Port: lsof-4.56.4 Path: /usr/ports/sysutils/lsof Info: Lists information about open files (similar to fstat(1)) Maint: obrien@FreeBSD.org Index: sysutils B-deps: R-deps:
這些搜尋結果中,要注意的是 “Path:” 這行, 因為這行會告訴你可以在哪邊找到該 port。 而搜尋結果的其他部分,因為與 port 安裝較無關係,所以這裡就不講了。
若要更徹底的搜尋,那麼可以改用 make search key=string,其中 string 請改為想搜尋的關鍵字。 如此一來會找 port 名稱、軟體簡介(comments)、軟體敘述檔(descriptions) 以及軟體相依關係(dependencies)裡面是否有符合關鍵字, 此外,不清楚軟體名稱的話,也可以拿來找有符合關鍵字主題的 port。
剛講的這兩種方式,搜尋字眼都是 case-insensitive(不必區分大小寫)。 比如,搜尋 “LSOF” 與 “lsof” 兩者結果都會是一樣的。
可以用 pkg_add(1) 從本機上或者透過網路來安裝任一 FreeBSD package。
Example 4-1. 手動下載、安裝 Package
# ftp -a ftp2.FreeBSD.org Connected to ftp2.FreeBSD.org. 220 ftp2.FreeBSD.org FTP server (Version 6.00LS) ready. 331 Guest login ok, send your email address as password. 230- 230- This machine is in Vienna, VA, USA, hosted by Verio. 230- Questions? E-mail freebsd@vienna.verio.net. 230- 230- 230 Guest login ok, access restrictions apply. Remote system type is UNIX. Using binary mode to transfer files. ftp> cd /pub/FreeBSD/ports/packages/sysutils/ 250 CWD command successful. ftp> get lsof-4.56.4.tgz local: lsof-4.56.4.tgz remote: lsof-4.56.4.tgz 200 PORT command successful. 150 Opening BINARY mode data connection for 'lsof-4.56.4.tgz' (92375 bytes). 100% |**************************************************| 92375 00:00 ETA 226 Transfer complete. 92375 bytes received in 5.60 seconds (16.11 KB/s) ftp> exit # pkg_add lsof-4.56.4.tgz
若手邊沒有 package 來源(像是 FreeBSD 光碟)的話, 那麼建議使用 pkg_add(1) 時,加上
-r 選項來更輕鬆安裝 package。如此一來,就會自動判斷正確的
package 格式、 以及所搭配的作業系統 release 版本, 然後會自己從 FTP 站抓回、安裝相對應的
package。
# pkg_add -r lsof
上面這例子會自動下載正確的 package 並安裝。 若想改換用其他 FreeBSD Packages Mirror 站,那麼就要設定 PACKAGESITE 環境變數, 如此一來才會取代預設設定。 pkg_add(1) 會用 fetch(3) 指令來下載檔案,而 fetch(3) 本身則會使用相關環境變數的設定, 像是: FTP_PASSIVE_MODE、FTP_PROXY 以及 FTP_PASSWORD。 如果你網路環境處於 firewall 後面,或者需要用 FTP/HTTP proxy 的話,那麼就需要設定。 設定細節請參閱 fetch(3)。 請注意:上面所說的例子是寫 lsof 而非 lsof-4.56.4。 當使用遠端抓取功能時,該 package 版號就不必加上去了。 pkg_add(1) 會自動下載該軟體的最新版回來安裝。
Note: 若用的是 FreeBSD-CURRENT 或 FreeBSD-STABLE 的話,pkg_add(1) 會自動下載該軟體最新版回來。 若用的是屬於 -RELEASE 版本,那麼他會抓回屬於該 release 上所編譯的 package。 也可以更改 PACKAGESITE 環境變數,以改變下載方式。 舉例來說,如果是 FreeBSD 5.4-RELEASE 的話,那麼 pkg_add(1) 預設會從 ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-5.4-release/Latest/ 來抓 package。若要強制 pkg_add(1) 下載 FreeBSD 5-STABLE 所用的 package,那麼就把 PACKAGESITE 改設為 ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-5-stable/Latest/ 即可。
Package 檔有 .tgz 以及 .tbz 兩種格式。 這些都可透過 ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/packages/ ,或者 FreeBSD 光碟內取得。 每張 4 片裝的 FreeBSD 光碟(以及 PowerPak 包等等)內都會在 /packages 目錄內放 package。 裡面的目錄架構類似 /usr/ports 的目錄架構。 每個分類都各自有專屬目錄,且每份 package 都會放在 All 目錄內。
package 目錄架構與 port 的都一致;它們共同構成整個 package/port 系統機制。
pkg_info(1) 可用來列出所有已安裝的軟體、軟體簡介。
# pkg_info cvsup-16.1 A general network file distribution system optimized for CV docbook-1.2 Meta-port for the different versions of the DocBook DTD ...
pkg_version(1) 則是列出所有已安裝的軟體版本。 它會顯示已裝版本以及目前機器上 port tree 的版本差異。
# pkg_version cvsup = docbook = ...
第二欄的符號表示:已安裝的軟體版本與目前機器上 port tree 的版本差異。
若要移除已裝的軟體,那麼請多利用 pkg_delete(1) 工具,比如:
# pkg_delete xchat-1.7.1
請注意 pkg_delete(1) 須要放上完整的軟體名稱以及版本, 若只輸入 xchat 就不行,必須換成 xchat-1.7.1 才可。 然而,我們可以用 pkg_version(1) 輕鬆找出已裝的所有軟體版本,或者以 wildcard (萬用字元) 的方式:
# pkg_delete xchat\*
以上面例子而言,將會移除所有以 xchat 開頭的軟體。
下面我們會介紹如何使用 Ports Collection 來安裝、移除軟體的基本用法。 至於其他可用的 make 詳細用法與環境設定,可參閱 ports(7)。
在安裝任一 ports 之前,必須先裝上 Ports Collection —— 它主要是由 /usr/ports 內一堆 Makefiles, patches 以及一些軟體簡介檔所組成的。
在裝 FreeBSD 時,若忘了在 sysinstall 內勾選要裝 Ports Collection 的話, 沒關係,可以照下列方式來安裝 ports collection:
CVSup 方式
使用 CVSup 是安裝、更新 Ports Collection 的快速方法之一。 若想更瞭解 CVSup 用法的話,請參閱 使用 CVSup。
Note: csup 是以 C 語言對 CVSup 軟體的重寫,在 FreeBSD 6.2 及之後版本即有附在系統內。 可以直接用系統所附的 csup 即可跳過步驟一的動作, 並將本文相關提到 cvsup 之處, 都改為 csup 即可。 此外, FreeBSD 6.2 之前的版本,則可裝 net/csup 或者 package 來使用 csup。
第一次跑 CVSup 之前,請先確認 /usr/ports 是乾淨的! 若你已經裝了 Ports Collection ,但又自行加上其他 patch 檔,那麼 CVSup 並不會刪除你自行加上的 patch 檔,這樣可能會導致要安裝某些軟體時, 發生 patch 失敗或編譯失敗。
安裝 net/cvsup-without-gui package:
# pkg_add -r cvsup-without-gui
細節用法請參閱 安裝 CVSup(Section A.5.2)。
執行 cvsup:
# cvsup -L 2 -h cvsup.tw.FreeBSD.org /usr/share/examples/cvsup/ports-supfile
請把 cvsup.tw.FreeBSD.org 請改成離你比較近 (快)的 CVSup 主機。 這部分可以參閱完整的 CVSup mirror 站列表(Section A.5.7)。
Note: 若想改用自己設的 ports-supfile,比如說, 不想每次都得打指令來指定所使用的 CVSup 主機。
這種情況下,請以 root 權限把 /usr/share/examples/cvsup/ports-supfile 複製到其他位置,比如 /root 或者自己帳號的家目錄。
修改新的 ports-supfile 檔。
把 CHANGE_THIS.FreeBSD.org 改為離你比較近(快)的 CVSup 主機。 這部分可以參閱完整的 CVSup Mirrors (Section A.5.7) 站列表
然後就開始以類似下列指令跑 cvsup:
# cvsup -L 2 /root/ports-supfile
執行 cvsup(1) 之後,就會開始更新 Ports Collection。 不過這動作只是『更新』並不是『升級』,不會把已裝的軟體重新編譯、升級。
Portsnap 方式
portsnap(8) 也是更新 Ports Collection 的方式之一。 FreeBSD 6.0 起開始內建 Portsnap 機制,而較舊的系統,則可透過 ports-mgmt/portsnap port 來安裝:
# pkg_add -r portsnap
Portsnap 細節功能,請參閱 Portsnap 使用篇。
若 /usr/ports 目錄不存在的話, 就建立一下吧:
# mkdir /usr/ports
接下來,下載壓縮的 Ports Collection 定期更新檔到 /var/db/portsnap 目錄。 完成下載後,要斷線與否都可以。
# portsnap fetch
若是第一次跑 Portsnap 的話, 則需要先解壓到 /usr/ports:
# portsnap extract
若已有 /usr/ports 而且只是想更新而已, 那麼就照下面作:
# portsnap update
Sysinstall 方式
這方式要用 sysinstall 透過安裝來源來裝 Ports Collection。 請注意:所安裝的 Ports Collection 版本只是該 release 發佈時的版本而已,而非最新。 若能上網(Internet)的話,請使用上述方式之一會比較好。
以 root 權限執行 sysinstall (在 FreeBSD 5.2 之前版本則是 /stand/sysinstall) ,方式如下:
# sysinstall
請以方向鍵移動選擇項目,選擇 Configure,然後按 Enter 鍵。
選擇 Distributions,然後按 Enter 鍵。
選擇 ports,然後按 Space 鍵。
選 Exit,然後按 Enter 鍵。
選擇要用的安裝來源,比如:CDROM(光碟)、FTP 等方式。
選 Exit,然後按 Enter 鍵。
按下 X 鍵就可離開 sysinstall 程式。
提到 Ports Collection,首先要先說明的是:何謂 “skeleton”。 簡單來講,port skeleton 就是讓軟體如何在 FreeBSD 順利編譯、安裝的最基本檔案組合。 每份 port skeleton 基本上會有:
Makefile 檔。 這個 Makefile 內容有分許多部分, 是用來指定要如何編譯,以及該裝在系統的何處。
distinfo 檔。 編譯該軟體所需下載的檔案、checksum(使用 md5(1) 及 sha256(1) 來檢驗檔案)都會記錄在這檔, 以確保所下載的檔案是正確無誤的。
files 目錄。 這目錄放的是讓軟體正常編譯、 安裝的 patch 檔。 Patches 檔基本上是一些小檔案,並針對特定檔案來做修改, 而且是純文字檔格式, 基本上內容通常會像是 “Remove line 10(刪除第 10 行)” 或 “Change line 26 to this ...(把第 26 行改為...)” 之類的。 這些 Patches 通常也稱為 “diffs” ,因為都是由 diff(1) 程式所產生的。
此外,本目錄也可能會放一些協助編譯該 port 的檔案。
pkg-descr 檔,內容是比較詳細的軟體介紹, 通常會寫得比較多行。
pkg-plist 檔,該 port 會安裝的所有檔案清單。 也是告訴系統在移除該 port 時,需要刪除哪些檔案。
有些 port 還會有其他檔案,像是 pkg-message 檔。 port 系統在一些情況時,會用這些檔案。 如果想知道這些檔案的更多細節用途,以及 port 一般用法,請參閱 FreeBSD Porter's Handbook。
port 內寫的是告訴系統如何編譯 source code 的相關指令, 但並不是真正的 source code。 而 source code 可以從光碟或網路(Internet)來取得, 該軟體開發者可能會把 source code 以各種格式來發佈。 通常是以 tar 以及 gzip 這兩者工具一起壓縮的檔案, 也有可能是以其他工具壓縮,或根本沒壓縮。 而軟體的 source code 無論是以哪一種壓縮檔型態,我們都稱之為 “distfile”。 下面將介紹兩種安裝 FreeBSD port 的方式。
Note: 要安裝 port 的話,請務必切為 root 身份。
Warning: 在安裝任何 port 之前,請務必確認有更新 Ports Collection 到最新版, 此外請檢閱 http://vuxml.freebsd.org/ 來檢查所要裝的 port 是否有相關安全漏洞議題需要注意的。
portaudit 會在安裝任何 port 之前, 先自動檢查是否有相關已知的安全漏洞。這個工具在 Ports Collection 內有 (ports-mgmt/portaudit)。 在安裝 port 之前,可以先跑 portaudit -F 指令, 如此一來就會抓最新的資安漏洞資料庫回來核對。 每天的系統定期安檢會自動更新資料庫,並作安全稽核。 詳情請參閱 portaudit(1) 以及 periodic(8) 的線上說明。
Ports Collection 會假設你的網路是可正常連線的。 如果沒有的話,那麼需手動把所需的 distfile 檔複製到 /usr/ports/distfiles 才行。
開始操作之前,要先進入打算安裝的 port 目錄內:
# cd /usr/ports/sysutils/lsof
一旦進入 lsof 目錄後,就可以看到這個 port 的 skeleton 結構。 接下來,就是編譯,也就是 “build” 這個 port。 只需簡單輸入 make 指令,就可輕鬆完成編譯。 完成後,應該可以看到類似下面訊息:
# make >> lsof_4.57D.freebsd.tar.gz doesn't seem to exist in /usr/ports/distfiles/. >> Attempting to fetch from ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/. ===> Extracting for lsof-4.57 ... [extraction output snipped] ... >> Checksum OK for lsof_4.57D.freebsd.tar.gz. ===> Patching for lsof-4.57 ===> Applying FreeBSD patches for lsof-4.57 ===> Configuring for lsof-4.57 ... [configure output snipped] ... ===> Building for lsof-4.57 ... [compilation output snipped] ... #
請注意:編譯完成後,就會回到提示列(prompt)。接下來就是安裝該 port 了,要裝的話,只需在原本的 make 指令後面再加上一個字即可, 那個字就是 install:
# make install
===> Installing for lsof-4.57
...
[installation output snipped]
...
===> Generating temporary packing list
===> Compressing manual pages for lsof-4.57
===> Registering installation for lsof-4.57
===> SECURITY NOTE:
This port has installed the following binaries which execute with
increased privileges.
#
一旦回到提示列(prompt),就可以執行剛裝的程式了。 另外,因為 lsof 這程式執行時會有額外權限, 所以會出現安全警告。在編譯、安裝 port 的時候, 請留意任何出現的警告。
此外,建議刪除編譯用的工作目錄(預設是 work), 這目錄內為在編譯過程中所用到的一些臨時檔案, 這些檔案不只佔硬碟空間,而且也可能會在該 port 升級新版時, 造成不必要的困擾。
# make clean ===> Cleaning for lsof-4.57 #
Note: 用 make install clean 就可以一口氣完成剛所說 make、make install、 make clean 這三個步驟了。
Note: 有些 shell 會依據 PATH 環境變數的路徑, 把那些路徑的執行檔 cache 起來,來加速搜尋執行檔。 如果你用的是這類的 shell,那麼在裝完 port 後需要打 rehash 指令,才能執行新裝的執行檔,而 rehash 指令可以在 tcsh 之類的 shell 上使用,若是 sh 的話,則是 hash -r。 詳情請參閱你所使用的 shell 相關文件。
有些由所謂 third-party 所發行的 DVD-ROM 產品,像是 FreeBSD Mall 所發行的 FreeBSD Toolkit 會包括 distfiles 檔案, 這些檔案可用來搭配 Ports Collection。 把 DVD-ROM 掛載在 /cdrom。 若使用其他掛載點的話,要記得設定 CD_MOUNTPTS 環境變數為相對應的掛載點。 如此一來,光碟上若有所需的 distfiles 就會自動使用光碟的檔案。
Note: 請注意,有少數 port 並不允許透過光碟來發佈檔案。 可能的原因有:需先填註冊單才能下載或散佈檔案,或其他原因。 如果想安裝在光碟上沒附上的 port,就需連上網路才能繼續進行安裝。
ports 系統採用 fetch(1) 來下載檔案, 它有許多可調整的環境變數,包括: FTP_PASSIVE_MODE、FTP_PROXY、 FTP_PASSWORD。 如果是處於有防火牆的環境, 或者需要使用 FTP/HTTP proxy,那麼就需要設定這些變數。 使用細節請參閱 fetch(3) 說明。
若無法隨時一直上網的話,那麼可以利用 make fetch。 只要在 port 的最上層路徑(/usr/ports) 打這指令,那麼所有需要用到的檔案都會下載。 這指令也可以在下層目錄使用,例如: /usr/ports/net。 請注意,若該 port 有相依的 library 或者其他 port 的話, 那麼它並不會跟著一起下載其他所相依的檔案。 若想一次下載所有相依的 port 所有檔案,那麼指令參數請改用 fetch-recursive 而非 fetch。
Note: 可以在某類別或最上層路徑打 make 指令來編譯所有的 port,或者以上述的 make fetch 指令來下載所有檔案。 然而,這樣是相當危險,因為有些 port 不能並存。 也有另一種情況,有些 port 可能會以相同檔名, 但是實際上卻是不同內容的檔案。
在某些罕見情況,可能需加上 MASTER_SITES (檔案的原始下載處)之外的下載點,以下載所需的檔案。 可以用下列指令,來更改預設的 MASTER_SITES 下載點:
# cd /usr/ports/directory # make MASTER_SITE_OVERRIDE= \ ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/ fetch
上面這例子,是把 MASTER_SITES 改設 ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/ 為下載點。
Note: 有些 port 允許(或要求)您得指定編譯選項, 以啟用、停用該軟體中非必須的功能、安全選項以及其他可自訂的選項。 具有代表性的包括了 www/mozilla、security/gpgme、mail/sylpheed-claws。 若有這類選項時,通常在編譯時會出現相關提示訊息。
有時候,會發現到使用其他目錄作為 port、distfiles 目錄可能相當有用(甚至是必須),可以設定 PORTSDIR 及 PREFIX 環境變數以修改預設的 port 目錄。舉例:
# make PORTSDIR=/usr/home/example/ports install
以上會在 /usr/home/example/ports 內進行編譯, 並把所有檔案安裝到 /usr/local 內。
# make PREFIX=/usr/home/example/local install
則會在 /usr/ports 目錄內編譯, 並把所有檔案安裝到 /usr/home/example/local 內。
當然囉,
# make PORTSDIR=../ports PREFIX=../local install
則會同時包含兩種設定(還有很多變化以致無法在本頁全部都有寫到, 但您應該已經有抓到大概概念了吧)。
此外,這些變數也以作為環境變數來設定。 請依您所使用的 shell 去參閱相關說明,以瞭解如何設定。
有些 port 會使用 imake(X Window 系統的一部份) 無法正常運用 PREFIX 變數, 它們會堅持把檔案都安裝到 /usr/X11R6 目錄。 同樣地,也有一些 Perl port 會忽略 PREFIX 並把檔案安裝到 Perl 目錄架構內。 讓這些 ports respect PREFIX 是相當困難,甚至是不可能的事。
在編譯某些 port 時會出現選單畫面(ncurses-based), 可以用來選擇安裝選項。 通常裝好該 port 之後,便不太會需要重加、 移除、更改一些當初安裝的選項。 但日後若有需要的話, 也有許多方式可以調整這些選項。 其中一種方式便是切到該 port 目錄, 並打 make config 即可再次回到選項畫面去作調整。 另外還可用 make showconfig 以顯示該 port 安裝時所用的選項。 也可以用 make rmconfig 來把所有選項回到初始設定。 這些選項跟其他動作都可參閱 ports(7) 內的詳細說明。
現在您已經知道如何安裝 port,而開始想瞭解如何移除。 比如裝了一個 port 後才意識到裝錯 port 了。 在此,我們將移除前面例子所裝的那個 port (沒仔細注意的話,我們再提醒一下就是 lsof)。 跟移除 package 時相當類似(在 Packages section 有介紹),都是使用 pkg_delete(1) 指令:
# pkg_delete lsof-4.57
首先,用 pkg_version(1) 指令來列出目前 Ports Collection 中提供了那些可升級的 port 版本:
# pkg_version -v
每次更新完 Ports Collection 之後,請務必記得在升級 port 前, 先看看 /usr/ports/UPDATING, 這裡會寫升級方面的各式問題,比如:檔案格式改變、變更設定檔位置、 與舊版不相容的問題等,以及怎麼解決的完整步驟。
若 UPDATING 內容與你看到的其他文件有些不同 、相衝的話, 那麼請以 UPDATING 為準。
portupgrade 可以輕鬆升級已裝的軟體。 該工具可從 ports-mgmt/portupgrade port 安裝, 安裝方式就如同其他 port 一樣,用 make install clean 指令就可以了:
# cd /usr/ports/ports-mgmt/portupgrade # make install clean
首先最好先以 pkgdb -F 來掃瞄已裝的 ports 資料庫是否有誤,並修正有問題的地方。 在每次做升級之前,最好定期做一下 pkgdb -F 動作會較為妥當。
跑 portupgrade -a 的話, portupgrade 會升級系統上所有已裝的過舊 ports。 若用 -i 則在升級每個 port 過程當中,
會要求確認相關動作是否符合所需。
# portupgrade -ai
若只想升級某特定程式而非全部,那麼可以用 portupgrade pkgname 來做指定。 若想要 portupgrade 優先升級某 port 所相依的相關套件,則請用 -R 參數即可。
# portupgrade -R firefox
若要用 package 而非 port 來安裝,則需指定 -P 才可以。
若有指定這選項,則 portupgrade 會搜尋 PKG_PATH 變數所指定的本機目錄, 若找不到則透過網路來下載安裝。
若本機跟網路都沒有可用的 package 的話,則 portupgrade 會使用
port 方式安裝。 若不想如此又變成使用 port 方式安裝,則用 -PP
即可強制避免使用 port 方式安裝。
# portupgrade -PP gnome2
若只想下載 distfiles(或者若指定 -P 的話,則是
package)而不想編譯或安裝檔案,可以使用 -F。 詳情請參閱
portupgrade(1)
的說明。
Portmanager 也可以用來輕鬆升級已裝的軟體。 該工具可從 ports-mgmt/portmanager port 安裝:
# cd /usr/ports/ports-mgmt/portmanager # make install clean
所有已裝的軟體,都可以輕鬆用類似下列指令來升級:
# portmanager -u
此外,使用參數可以改為 -ui,如此一來 Portmanager 在升級一些有特殊選項的軟體時 ,就會詢問該如何升級。
Portmanager 也可以用來裝新 port。與以往常用的 make install clean 指令不同之處在於: 它會先升級你要裝的 port
所相依的所有 ports,然後才開始編譯、 安裝要裝的 port。
# portmanager x11/gnome2
若要裝的 port 之軟體相依關係有問題時,也可以用 Portmanager 使它們重歸正軌。 而 Portmanager 解決相依問題完畢之後,該 port 也會重新編譯,以因應正確的相依關係。
# portmanager graphics/gimp -f
其餘運用法門,請參閱 portmanager(1) 說明。
因為使用 Ports Collection 遲早可能會用光硬碟空間, 所以在裝完軟體後,記得要以 make clean 指令來清除臨時的 work 目錄。 此外,可以用下列指令來清除整個 Ports Collection 內的臨時目錄:
# portsclean -C
ports 用久了,您可能會在 distfiles 目錄內會累積著許多的原始碼檔案。 可以手動刪除這些檔案, 或者用下列指令來清除所有 port 都不使用的舊檔:
# portsclean -D
或者要清除所有已裝的 port 都不再使用的舊檔:
# portsclean -DD
Note: portsclean 這工具乃是 portupgrade 套件的一部分。
不要忘了移除那些已經安裝,但不再需要用到的 ports。 有個 ports-mgmt/pkg_cutleaves port,正是可自動完成這功能的好工具。
通常,安裝完軟體後,我們可以閱讀所附的一些文件,或需要編輯設定檔, 來確保這個軟體能順利運作,或在機器開機的時候啟動(如果是 daemon 的話) 等等。
不同的軟體會有不同的設定步驟。不管怎樣,如果裝好了軟體, 但是不知道下一步怎麼辦的時候, 可以試試看這些小技巧:
善用 pkg_info(1) ,這指令可以顯示:透過套件管理系統 (Packages/Ports)裝了哪些軟體、檔案裝在哪邊。舉例來說,若剛裝了 FooPackage (版本 1.0.0),那麼下面這指令:
# pkg_info -L foopackage-1.0.0 | less
就會顯示這軟體所安裝的檔案清單。 請特別注意在 man/ 目錄內是說明檔、 etc/ 目錄內是設定檔、 doc/ 目錄內是完整文件。
若不確定已裝的套件版本為何,可以用類似下列指令來查:
# pkg_info | grep -i foopackage
以上將會搜尋所有已裝的套件,列出有符合 foopackage 的套件名稱。 請自行依需求,修改 foopackage 為想找的套件名稱。
一旦確認該程式的線上說明有安裝,就可以用 man(1) 來翻閱。 同樣地,若該程式有提供的話,也可以參考設定檔樣本,以及其他文件。
若該程式有官網的話,還可以透過網站來找文件、常見問答集(FAQ)等。 若不知道網址,請用下列指令:
# pkg_info foopackage-1.0.0
若該程式有官網的話,則會有一行 WWW: 開頭的出現,這行會列出該程式的官網網址(URL)。
Port 若須在開機時就會啟動(就像 Internet 主機),通常都會安裝 script 到 /usr/local/etc/rc.d 目錄。 您可以檢閱這 script 的正確與否,或若有需要,也可以修改、改名。 詳情請參閱 啟動 Services。
如果發現某個 port 無法順利安裝、運作, 有幾種方法可以試試看:
從 Problem Report 資料庫 中挖寶看看,說不定已經有人送可用的 patch 上去囉, 那麼或許就可以順利解決問題哩。
向該 port 的 maintainer 尋求協助:請打 make maintainer 或翻閱 Makefile 以查詢 maintainer 的 email address。記得寄信給 maintainer 時,要附註該 port 的名稱、版本(或是把 Makefile 內的 $FreeBSD: 那一整行附上) 以及相關錯誤訊息。
Note: 有些 port 不是由專門的單一 maintainer 負責,而是透過 mailing list 的專題討論。許多(但非全部)的聯絡 email 格式通常是
<freebsd-list名稱@FreeBSD.org>。發問時,請記得把『freebsd-list名稱』改為相關討論的 mailing list 名稱。尤其當 port 的 maintainer 欄位是
<freebsd-ports@FreeBSD.org>時,事實上已經沒人當該 port maintainer 了。 因此若該 port 仍有修正或其他技術支援的話,相關討論都會在 freebsd-ports 郵遞論壇上出現。 喔,對了,如果有熟悉該軟體者,志願當該 port maintainer 的話,我們也都很歡迎您的加入喔。
若 port maintainer 沒有回覆您的信件, 則可以用 send-pr(1) 來提交問題報告 PR。(請參閱 Writing FreeBSD Problem Reports)。
試試看修正它吧! Porter's Handbook 包括了 “Ports” 架構的細節部份,這些書中內容有助您修好有問題的 port 甚至提交自己的 port﹗
從較近的 FTP 站點下載編譯好的 package。 package collection 的最上游站是在 ftp.FreeBSD.org 上的 packages 目錄內,但請記得先檢查是否已有 local mirror 站! 通常情況下這些 package 都可以直接使用, 而且應該比自行編譯快一些。 用 pkg_add(1) 即可順利安裝 package 。
FreeBSD 使用 X11 來提供使用者相當好用的 GUI 介面。 X11 是 X Window 系統,包括 Xorg 以及 XFree86 實作的自由軟體版本 (以及其他未在本章有介紹的軟體)。 FreeBSD 一直到 FreeBSD 5.2.1-RELEASE 都仍可在預設的安裝程式內去裝 XFree86 (由 The XFree86 Project, Inc 發行的 X11 server)。 而 FreeBSD 5.3-RELEASE 起,預設的 X11 改為 Xorg(由 X.Org 基金會所開發的 X11 server,並採用與 FreeBSD 相當類似的 license)。 此外,當然也有商業 X servers 的 FreeBSD 版。
本章主要是介紹 X11 (主要著重於 Xorg 7.4 版部分)的安裝與設定。 若欲瞭解 XFree86 的詳細資料(早期的 FreeBSD 內, XFree86 乃是預設的 X11 套件),請參閱舊版的 FreeBSD Handbook,網址為 http://docs.FreeBSD.org/doc/ 。
欲知 X11 對於顯示方面硬體的支援情況,請參閱 Xorg 網站。
讀完這章,您將了解:
X Window 系統的各組成部份,以及它們是如何相互運作。
如何安裝、設定 X11。
如何安裝並使用不同的 window managers。
如何在 X11 上使用 TrueType® 字型。
如何設定系統以使用圖形登入介面。 (XDM)
在開始閱讀這章之前,您需要︰
知道如何運用 ports、packages 來安裝軟體。 (Chapter 4)
第一次接觸 X 的人,大概都會有些震撼,尤其是熟悉其他 GUI 介面(像是 Microsoft Windows 或 Mac OS)的使用者。
雖然 X 各元件的所有細節及運作方式,並不是必須要知道的。 但對它們有些基本概念會更容易上手。
X 並非 UNIX 上第一套視窗系統,但它卻是最廣為流傳運用。 原本的 X 研發團隊在研發 X 之前有開發另一套視窗系統。 那套系統叫做 “W”(取 “Window” 的第一個字)。 而 X 則是 W 之後的下一個羅馬字母。
X 亦被稱之為 “X”、“X Window System”、 “X11”,以及其他一些詞彙。 使用 “X Windows” 這字眼來稱呼 X11,可能會讓有些人不爽;這部分細節可參閱 X(7) 說明。
X 一開始是設計為網路架構環境,並採用 “client-server” 架構。
在 X 架構下, “X server” 是在有鍵盤、螢幕、滑鼠的電腦上運作。 而 server 部份則是負責像是顯示部份的管理、 處理來自鍵盤、滑鼠及其他設備(比方像是以繪圖板來輸入、 或者是顯示到投影機)的輸入等等, 每個 X 程式(像是 XTerm,或 Netscape)都是 “client”。 client 會傳訊息到 server 上,比如:“Please draw a window at these coordinates”,接著 server 會傳回訊息,比如: “The user just clicked on the OK button”。
在家庭或小辦公室環境,通常 X server 跟 X client 都是在同一台電腦上執行的。 然而,也可以在比較爛的桌機上執行 X server, 並在比較強、比較貴的電腦上跑 X 程式(client)來做事情。 在這種場景,X client 與 server 之間的溝通就需透過網路來進行。
這點可能會讓有些人產生困惑,因為 X 術語與他們原本的認知剛好相反。 他們原本以為 “X server” 是要在最強悍的機器上跑才行,而 “X client” 則是在他們桌機上面跑。 實際上卻不是這樣。
有點相當重要,請記住 X server 是在有接螢幕、鍵盤的機器上運作, 而 X client 則是顯示這些視窗的程式。
協定(protocol)內並無強制規定 client 以及 server 兩邊機器都得是同一作業系統,或者得是同型機器才可以。 換句話說,也可以在 Microsoft Windows 或蘋果電腦(Apple)的 Mac OS 上跑 X server,而且可以透過許多免費或商業軟體完成這些安裝、設定。
X 設計哲學與 UNIX 設計哲學相當類似,都是 “tools, not policy”。 也就是說,X 不會試圖強制規定某任務應該要如何完成,而是只提供使用者一些工具, 至於如何運用這些工具,則是使用者本身的事了。
X 延續這哲學,它並不規定:螢幕上的視窗該長什麼樣、要如何移動滑鼠指標、 該用什麼組合鍵來切換各視窗(比如:在 Microsoft Windows 的 Alt+Tab鍵)、各視窗的標題列長相,以及是否該有關閉鈕等等。
事實上,X 把這部分交給所謂的 “Window Manager” 來管理。 有一堆 window manager 程式,像是: AfterStep 、Blackbox、ctwm 、Enlightenment、 fvwm、Sawfish、 twm、 Window Maker 等等。每一種 window manager 都提供不同的使用經驗; 有些還可使用 “virtual desktops(虛擬桌面) ”;有些則可自訂組合鍵來管理桌面;有些會有 “Start(開始) ”鈕或其他類似設計;有些則是 “可更換佈景主題”, 可自行安裝新的佈景主題以更換外觀。 這些跟其他的 window manager 在 Ports Collection 內的 x11-wm 目錄內都有。
此外,KDE 及 GNOME 桌面環境則有其自屬並整合完整的 window manager。
每個 window manager 也各有其不同的設定機制;有些需手動寫設定檔, 而有的則可透過 GUI 工具來完成大部分的設定。舉個例子: Sawfish 就有以 Lisp 語言寫的設定檔。
Focus Policy: window manager 的另一特色就是負責滑鼠指標的 “focus policy”。 每一種視窗系統都需要選擇作用視窗的方式 ,以接受鍵盤輸入,以及決定目前哪個視窗是處於使用中的狀態。
通常較為人熟悉的 focus policy 叫做 “click-to-focus”, 這是 Microsoft Windows 所採用的模式,也就是指標在該視窗按一下的話, 該視窗就會處於使用中的狀態。
X 並不支援一些特殊的 focus policy。 換句話說,window manager 會控制哪個視窗在何時是作用中。 不同的 window manager 有不同的支援方式。 但它們都支援 click-to-focus, 而且大多數都有支援多種方式。
以下是目前最流行的 focus policy:
- focus-follows-mouse
滑鼠移到哪個視窗就是使用該視窗。 該視窗不一定位於其他視窗上面, 但只要把滑鼠移到該視窗就可以改變作用中的視窗, 而不需在它上面點擊。
- sloppy-focus
該 policy 是針對 focus-follows-mouse 的小小延伸。 對於 focus-follows-mouse 而言,若把游標移到最初的視窗(或桌面), 那所有其他視窗都會處於非作用中,而且所有鍵盤輸入也會失效。 若是選用 sloppy-focus,則只有在游標移到新視窗時, 作用中的視窗才會變成新的, 而只離開目前作用中的視窗仍不會改變作用狀態。
- click-to-focus
由游標點擊才會決定作用中的視窗。 並且該視窗會被 “raised(凸顯)” 到所有其他視窗之前, 即使游標移到其他視窗,所有的鍵盤輸入仍會由該視窗所接收。
許多 window manager 也支援其他 policy,與這些相比起來又有些不同, 細節部分請參閱該 window manager 的文件說明。
The X approach of providing tools and not policy extends to the widgets seen on screen in each application.
“Widget” is a term for all the items in the user interface that can be clicked or manipulated in some way; buttons, check boxes, radio buttons, icons, lists, and so on. Microsoft Windows calls these “controls”.
Microsoft Windows and Apple's Mac OS both have a very rigid widget policy. Application developers are supposed to ensure that their applications share a common look and feel. With X, it was not considered sensible to mandate a particular graphical style, or set of widgets to adhere to.
As a result, do not expect X applications to have a common look and feel. There are several popular widget sets and variations, including the original Athena widget set from MIT, Motif® (on which the widget set in Microsoft Windows was modeled, all bevelled edges and three shades of grey), OpenLook, and others.
Most newer X applications today will use a modern-looking widget set, either Qt, used by KDE, or GTK+, used by the GNOME project. In this respect, there is some convergence in look-and-feel of the UNIX desktop, which certainly makes things easier for the novice user.
Xorg 是 FreeBSD 預設的 X11 實作。 Xorg 是由 X.Org 基金會所發行之開放源碼軟體 X Window 系統實作的 X server。 Xorg 乃是以 XFree86 4.4RC2 以及 X11R6.6 為基礎所產生的。 目前 FreeBSD Ports Collection 內的 Xorg 版本為 7.4。
從 Ports Collection 來安裝 Xorg 的安裝方式:
# cd /usr/ports/x11/xorg # make install clean
Note: 若要編譯完整的 Xorg, 請先確認至少有 4 GB 的磁碟空間。
此外 X11 也可直接透過 package 方式來安裝,可使用 pkg_add(1) 來安裝編譯好的 X11 套件,記得在透過網路安裝時不要指定版本即可, pkg_add(1) 會自動抓該套件最新版的套件回來。
若要自動透過 package 方式來裝 Xorg ,直接打下面這行即可:
# pkg_add -r xorg
Note: 上面的例子會裝完整的 X11 套件,包括 server、client、字型等。 此外,還有其他的 X11 子套件可透過 package 或 port 方式來單獨安裝。
本章其餘部分將介紹如何設定 X11, 以及如何打造高生產力的桌面環境。
在開始設定 X11 之前,要先瞭解所要裝的機器資料為何:
螢幕規格
顯示卡的晶片規格
顯示卡的記憶體容量
X11 會依螢幕規格來決定解析度以及更新頻率。 這些規格通常可從螢幕所附的文件或廠商網站上取得。 最重要的是要知道水平、垂直更新頻率為何。
而顯示卡晶片則決定 X11 要用哪一種驅動程式模組。 大多數的晶片都可以自動偵測,但最好還是要知道是何種晶片, 以免萬一自動偵測失敗。
Video memory on the graphic adapter determines the resolution and color depth which the system can run at. This is important to know so the user knows the limitations of the system.
Xorg 自 7.3 版起不再需任何設定檔,只要打下列即可:
% startx
若這指令不行或預設設定無法使用,那麼就需要手動設定 X11。 設定 X11 需要幾個步驟,首先是以系統管理者帳號來建立初始設定檔:
# Xorg -configure
這會在 /root 目錄內產生 xorg.conf.new 設定檔(無論是用 su(1) 或直接登入為 root,都會改變 root 預設的 $HOME 環境變數)。 X11 程式接著會偵測系統的顯示卡相關硬體,並將偵測到硬體訊息寫入設定檔, 以便載入正確的驅動程式。
下一步是測試現有的設定檔,以便確認 Xorg 可以與顯示卡、螢幕相關硬體正確運作:
# Xorg -config xorg.conf.new
若看得到一堆黑灰夾雜的網格畫面,以及 X 形的滑鼠游標, 那麼設定檔就是成功的。 要退出測試,只要同時按下 Ctrl+Alt+Backspace 即可。
Note: 若滑鼠不正確運作,那麼需要先對其作設定。 請參閱 FreeBSD 安裝一章中的 Section 2.10.10 說明。
Next, tune the xorg.conf.new configuration file to taste. Open the file in a text editor such as emacs(1) or ee(1). First, add the frequencies for the target system's monitor. These are usually expressed as a horizontal and vertical synchronization rate. These values are added to the xorg.conf.new file under the "Monitor" section:
Section "Monitor"
Identifier "Monitor0"
VendorName "Monitor Vendor"
ModelName "Monitor Model"
HorizSync 30-107
VertRefresh 48-120
EndSection
The HorizSync and VertRefresh keywords may be missing in the configuration file. If they are, they need to be added, with the correct horizontal synchronization rate placed after the HorizSync keyword and the vertical synchronization rate after the VertRefresh keyword. In the example above the target monitor's rates were entered.
X allows DPMS (Energy Star) features to be used with capable monitors. The xset(1) program controls the time-outs and can force standby, suspend, or off modes. If you wish to enable DPMS features for your monitor, you must add the following line to the monitor section:
Option "DPMS"
While the xorg.conf.new configuration file is still open in an editor, select the default resolution and color depth desired. This is defined in the "Screen" section:
Section "Screen"
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Viewport 0 0
Depth 24
Modes "1024x768"
EndSubSection
EndSection
The DefaultDepth keyword describes the color depth to run at
by default. This can be overridden with the -depth command
line switch to Xorg(1). The Modes keyword describes the resolution to run at for the given color
depth. Note that only VESA standard modes are supported as defined by the target system's
graphics hardware. In the example above, the default color depth is twenty-four bits per
pixel. At this color depth, the accepted resolution is 1024 by 768 pixels.
Finally, write the configuration file and test it using the test mode given above.
Note: One of the tools available to assist you during troubleshooting process are the X11 log files, which contain information on each device that the X11 server attaches to. Xorg log file names are in the format of /var/log/Xorg.0.log. The exact name of the log can vary from Xorg.0.log to Xorg.8.log and so forth.
If all is well, the configuration file needs to be installed in a common location where Xorg(1) can find it. This is typically /etc/X11/xorg.conf or /usr/local/etc/X11/xorg.conf.
# cp xorg.conf.new /etc/X11/xorg.conf
The X11 configuration process is now complete. Xorg 目前可透過 startx(1) 來啟動之。 The X11 server may also be started with the use of xdm(1).
Note: There is also a graphical configuration tool, xorgcfg(1), which comes with the X11 distribution. It allows you to interactively define your configuration by choosing the appropriate drivers and settings. This program can be invoked from the console, by typing the command xorgcfg -textmode. For more details, refer to the xorgcfg(1) manual pages.
Alternatively, there is also a tool called xorgconfig(1). This program is a console utility that is less user friendly, but it may work in situations where the other tools do not.
Configuration with Intel i810 integrated chipsets requires the agpgart AGP programming interface for X11 to drive the card. 詳情請參閱 agp(4) 說明。
This will allow configuration of the hardware as any other graphics board. Note on systems without the agp(4) driver compiled in the kernel, trying to load the module with kldload(8) will not work. This driver has to be in the kernel at boot time through being compiled in or using /boot/loader.conf.
本節假設各位已經有些微進階設定的功力。 如果試著使用上述設定工具會有問題的話,請多利用相關 log 檔 (會記錄相關訊息)以便找出解法。 找尋解法過程中,可能會需要用到文字編輯器作為輔助。
目前的寬螢幕 (WSXGA, WSXGA+, WUXGA, WXGA, WXGA+ 等) 都有支援 16:10 及 10:9 比例,以及一些可能有問題的比例。 以下是一些常見的 16:10 螢幕解析度:
2560x1600
1920x1200
1680x1050
1440x900
1280x800
某方面而言,要增加這些解析度設定也是相當容易的, 只要在 Section "Screen" 內的 Mode 加上去就好,比如:
Section "Screen"
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Viewport 0 0
Depth 24
Modes "1680x1050"
EndSubSection
EndSection
Xorg 可以透過 I2C/DDC 來得知該寬螢幕所支援的解析度等相關資訊, 因此就能正確偵測出該螢幕所能支援的頻率、解析度。
若驅動程式並未包括 ModeLine 訊息的話, 那麼就要為 Xorg 做些設定才行。 我們可以透過 /var/log/Xorg.0.log 檔來取得 ModeLine 相關設定資料,即可讓螢幕正常顯示。 應該可以看到類似下面的訊息:
(II) MGA(0): Supported additional Video Mode: (II) MGA(0): clock: 146.2 MHz Image Size: 433 x 271 mm (II) MGA(0): h_active: 1680 h_sync: 1784 h_sync_end 1960 h_blank_end 2240 h_border: 0 (II) MGA(0): v_active: 1050 v_sync: 1053 v_sync_end 1059 v_blanking: 1089 v_border: 0 (II) MGA(0): Ranges: V min: 48 V max: 85 Hz, H min: 30 H max: 94 kHz, PixClock max 170 MHz
這些訊息被稱為 EDID 訊息。 可以藉由這些資料, 搭配下列的正確順序來產生 ModeLine 設定:
ModeLine <name> <clock> <4 horiz. timings> <4 vert. timings>
所以這個案例 Section "Monitor" 的 ModeLine 就會是像下面這樣:
Section "Monitor" Identifier "Monitor1" VendorName "Bigname" ModelName "BestModel" ModeLine "1680x1050" 146.2 1680 1784 1960 2240 1050 1053 1059 1089 Option "DPMS" EndSection
這樣子就簡單完成了,X 視窗就可以打造為新的寬螢幕環境囉。
The default fonts that ship with X11 are less than ideal for typical desktop publishing applications. Large presentation fonts show up jagged and unprofessional looking, and small fonts in Netscape are almost completely unintelligible. However, there are several free, high quality Type1 (PostScript®) fonts available which can be readily used with X11. For instance, the URW font collection (x11-fonts/urwfonts) includes high quality versions of standard type1 fonts (Times Roman®, Helvetica®, Palatino® and others). The Freefonts collection (x11-fonts/freefonts) includes many more fonts, but most of them are intended for use in graphics software such as the Gimp, and are not complete enough to serve as screen fonts. In addition, X11 can be configured to use TrueType fonts with a minimum of effort. For more details on this, see the X(7) manual page or the section on TrueType fonts.
To install the above Type1 font collections from the ports collection, run the following commands:
# cd /usr/ports/x11-fonts/urwfonts # make install clean
And likewise with the freefont or other collections. To have the X server detect these fonts, add an appropriate line to the X server configuration file (/etc/X11/xorg.conf), which reads:
FontPath "/usr/local/lib/X11/fonts/URW/"
Alternatively, at the command line in the X session run:
% xset fp+ /usr/local/lib/X11/fonts/URW % xset fp rehash
This will work but will be lost when the X session is closed, unless it is added to the startup file (~/.xinitrc for a normal startx session, or ~/.xsession when logging in through a graphical login manager like XDM). A third way is to use the new /usr/local/etc/fonts/local.conf file: see the section on anti-aliasing.
Xorg has built in support for rendering TrueType fonts. There are two different modules that can enable this functionality. The freetype module is used in this example because it is more consistent with the other font rendering back-ends. To enable the freetype module just add the following line to the "Module" section of the /etc/X11/xorg.conf file.
Load "freetype"
Now make a directory for the TrueType fonts (for example, /usr/local/lib/X11/fonts/TrueType) and copy all of the TrueType fonts into this directory. Keep in mind that TrueType fonts cannot be directly taken from a Macintosh®; they must be in UNIX/MS-DOS/Windows format for use by X11. Once the files have been copied into this directory, use ttmkfdir to create a fonts.dir file, so that the X font renderer knows that these new files have been installed. ttmkfdir is available from the FreeBSD Ports Collection as x11-fonts/ttmkfdir.
# cd /usr/local/lib/X11/fonts/TrueType # ttmkfdir -o fonts.dir
Now add the TrueType directory to the font path. This is just the same as described above for Type1 fonts, that is, use
% xset fp+ /usr/local/lib/X11/fonts/TrueType % xset fp rehash
or add a FontPath line to the xorg.conf file.
That's it. Now Netscape, Gimp, StarOffice™, and all of the other X applications should now recognize the installed TrueType fonts. Extremely small fonts (as with text in a high resolution display on a web page) and extremely large fonts (within StarOffice) will look much better now.
Anti-aliasing has been available in X11 since XFree86 4.0.2. However, font configuration was cumbersome before the introduction of XFree86 4.3.0. Beginning with XFree86 4.3.0, all fonts in X11 that are found in /usr/local/lib/X11/fonts/ and ~/.fonts/ are automatically made available for anti-aliasing to Xft-aware applications. Not all applications are Xft-aware, but many have received Xft support. Examples of Xft-aware applications include Qt 2.3 and higher (the toolkit for the KDE desktop), GTK+ 2.0 and higher (the toolkit for the GNOME desktop), and Mozilla 1.2 and higher.
In order to control which fonts are anti-aliased, or to configure anti-aliasing properties, create (or edit, if it already exists) the file /usr/local/etc/fonts/local.conf. Several advanced features of the Xft font system can be tuned using this file; this section describes only some simple possibilities. For more details, please see fonts-conf(5).
This file must be in XML format. Pay careful attention to case, and make sure all tags are properly closed. The file begins with the usual XML header followed by a DOCTYPE definition, and then the <fontconfig> tag:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
As previously stated, all fonts in /usr/local/lib/X11/fonts/ as well as ~/.fonts/ are already made available to Xft-aware applications. If you wish to add another directory outside of these two directory trees, add a line similar to the following to /usr/local/etc/fonts/local.conf:
<dir>/path/to/my/fonts</dir>
After adding new fonts, and especially new font directories, you should run the following command to rebuild the font caches:
# fc-cache -f
Anti-aliasing makes borders slightly fuzzy, which makes very small text more readable and removes “staircases” from large text, but can cause eyestrain if applied to normal text. To exclude font sizes smaller than 14 point from anti-aliasing, include these lines:
<match target="font">
<test name="size" compare="less">
<double>14</double>
</test>
<edit name="antialias" mode="assign">
<bool>false</bool>
</edit>
</match>
<match target="font">
<test name="pixelsize" compare="less" qual="any">
<double>14</double>
</test>
<edit mode="assign" name="antialias">
<bool>false</bool>
</edit>
</match>
Spacing for some monospaced fonts may also be inappropriate with anti-aliasing. This seems to be an issue with KDE, in particular. One possible fix for this is to force the spacing for such fonts to be 100. Add the following lines:
<match target="pattern" name="family">
<test qual="any" name="family">
<string>fixed</string>
</test>
<edit name="family" mode="assign">
<string>mono</string>
</edit>
</match>
<match target="pattern" name="family">
<test qual="any" name="family">
<string>console</string>
</test>
<edit name="family" mode="assign">
<string>mono</string>
</edit>
</match>
(this aliases the other common names for fixed fonts as "mono"), and then add:
<match target="pattern" name="family">
<test qual="any" name="family">
<string>mono</string>
</test>
<edit name="spacing" mode="assign">
<int>100</int>
</edit>
</match>
Certain fonts, such as Helvetica, may have a problem when anti-aliased. Usually this manifests itself as a font that seems cut in half vertically. At worst, it may cause applications such as Mozilla to crash. To avoid this, consider adding the following to local.conf:
<match target="pattern" name="family">
<test qual="any" name="family">
<string>Helvetica</string>
</test>
<edit name="family" mode="assign">
<string>sans-serif</string>
</edit>
</match>
Once you have finished editing local.conf make sure you end the file with the </fontconfig> tag. Not doing this will cause your changes to be ignored.
The default font set that comes with X11 is not very desirable when it comes to anti-aliasing. A much better set of default fonts can be found in the x11-fonts/bitstream-vera port. This port will install a /usr/local/etc/fonts/local.conf file if one does not exist already. If the file does exist, the port will create a /usr/local/etc/fonts/local.conf-vera file. Merge the contents of this file into /usr/local/etc/fonts/local.conf, and the Bitstream fonts will automatically replace the default X11 Serif, Sans Serif, and Monospaced fonts.
Finally, users can add their own settings via their personal .fonts.conf files. To do this, each user should simply create a ~/.fonts.conf. This file must also be in XML format.
One last point: with an LCD screen, sub-pixel sampling may be desired. This basically treats the (horizontally separated) red, green and blue components separately to improve the horizontal resolution; the results can be dramatic. To enable this, add the line somewhere in the local.conf file:
<match target="font">
<test qual="all" name="rgba">
<const>unknown</const>
</test>
<edit name="rgba" mode="assign">
<const>rgb</const>
</edit>
</match>
Note: Depending on the sort of display, rgb may need to be changed to bgr, vrgb or vbgr: experiment and see which works best.
Anti-aliasing should be enabled the next time the X server is started. However, programs must know how to take advantage of it. At present, the Qt toolkit does, so the entire KDE environment can use anti-aliased fonts. GTK+ and GNOME can also be made to use anti-aliasing via the “Font” capplet (see Section 5.7.1.3 for details). By default, Mozilla 1.2 and greater will automatically use anti-aliasing. To disable this, rebuild Mozilla with the -DWITHOUT_XFT flag.
The X Display Manager (XDM) is an optional part of the X Window System that is used for login session management. This is useful for several types of situations, including minimal “X Terminals”, desktops, and large network display servers. Since the X Window System is network and protocol independent, there are a wide variety of possible configurations for running X clients and servers on different machines connected by a network. XDM provides a graphical interface for choosing which display server to connect to, and entering authorization information such as a login and password combination.
Think of XDM as providing the same functionality to the user as the getty(8) utility (see Section 24.3.2 for details). That is, it performs system logins to the display being connected to and then runs a session manager on behalf of the user (usually an X window manager). XDM then waits for this program to exit, signaling that the user is done and should be logged out of the display. At this point, XDM can display the login and display chooser screens for the next user to login.
The XDM daemon program is located in /usr/local/bin/xdm. This program can be run at any time as root and it will start managing the X display on the local machine. If XDM is to be run every time the machine boots up, a convenient way to do this is by adding an entry to /etc/ttys. For more information about the format and usage of this file, see Section 24.3.2.1. There is a line in the default /etc/ttys file for running the XDM daemon on a virtual terminal:
ttyv8 "/usr/local/bin/xdm -nodaemon" xterm off secure
By default this entry is disabled; in order to enable it change field 5 from off to on and restart init(8) using the directions in Section 24.3.2.2. The first field, the name of the terminal this program will manage, is ttyv8. This means that XDM will start running on the 9th virtual terminal.
The XDM configuration directory is located in /usr/local/lib/X11/xdm. In this directory there are several files used to change the behavior and appearance of XDM. Typically these files will be found:
| File | Description |
|---|---|
| Xaccess | Client authorization ruleset. |
| Xresources | Default X resource values. |
| Xservers | List of remote and local displays to manage. |
| Xsession | Default session script for logins. |
| Xsetup_* | Script to launch applications before the login interface. |
| xdm-config | Global configuration for all displays running on this machine. |
| xdm-errors | Errors generated by the server program. |
| xdm-pid | The process ID of the currently running XDM. |
Also in this directory are a few scripts and programs used to set up the desktop when XDM is running. The purpose of each of these files will be briefly described. The exact syntax and usage of all of these files is described in xdm(1).
The default configuration is a simple rectangular login window with the hostname of the machine displayed at the top in a large font and “Login:” and “Password:” prompts below. This is a good starting point for changing the look and feel of XDM screens.
The protocol for connecting to XDM-controlled displays is called the X Display Manager Connection Protocol (XDMCP). This file is a ruleset for controlling XDMCP connections from remote machines. It is ignored unless the xdm-config is changed to listen for remote connections. By default, it does not allow any clients to connect.
This is an application-defaults file for the display chooser and login screens. In it, the appearance of the login program can be modified. The format is identical to the app-defaults file described in the X11 documentation.
This is the default session script for XDM to run after a user has logged in. Normally each user will have a customized session script in ~/.xsession that overrides this script.
These will be run automatically before displaying the chooser or login interfaces. There is a script for each display being used, named Xsetup_ followed by the local display number (for instance Xsetup_0). Typically these scripts will run one or two programs in the background such as xconsole.
This contains settings in the form of app-defaults that are applicable to every display that this installation manages.
This contains the output of the X servers that XDM is trying to run. If a display that XDM is trying to start hangs for some reason, this is a good place to look for error messages. These messages are also written to the user's ~/.xsession-errors file on a per-session basis.
In order for other clients to connect to the display server, you must edit the access control rules, and enable the connection listener. By default these are set to conservative values. To make XDM listen for connections, first comment out a line in the xdm-config file:
! SECURITY: do not listen for XDMCP or Chooser requests ! Comment out this line if you want to manage X terminals with xdm DisplayManager.requestPort: 0
and then restart XDM. Remember that comments in app-defaults files begin with a “!” character, not the usual “#”. More strict access controls may be desired —— look at the example entries in Xaccess, and refer to the xdm(1) manual page for further infomation.
Several replacements for the default XDM program exist. One of them, kdm (bundled with KDE) is described later in this chapter. The kdm display manager offers many visual improvements and cosmetic frills, as well as the functionality to allow users to choose their window manager of choice at login time.
本章會介紹在 FreeBSD 中的 X 裡頭,有哪些不同的桌面環境。 “桌面環境”範圍很廣,從簡單的 window manager 到 完整的桌面應用程式,例如 KDE 或 GNOME。
GNOME is a user-friendly desktop environment that enables users to easily use and configure their computers. GNOME includes a panel (for starting applications and displaying status), a desktop (where data and applications can be placed), a set of standard desktop tools and applications, and a set of conventions that make it easy for applications to cooperate and be consistent with each other. Users of other operating systems or environments should feel right at home using the powerful graphics-driven environment that GNOME provides. More information regarding GNOME on FreeBSD can be found on the FreeBSD GNOME Project's web site. The web site also contains fairly comprehensive FAQs about installing, configuring, and managing GNOME.
可透過 package 或 Ports Collection 的方式來輕鬆安裝:
透過網路利用 package 安裝 GNOME:
# pkg_add -r gnome2
從 ports tree 透過原始碼編譯安裝 GNOME:
# cd /usr/ports/x11/gnome2 # make install clean
當 GNOME 安裝完成後, 必須告訴 X server 啟動 GNOME 而非原本的 window manager。
啟動 GNOME 最簡單的方法是利 用 GDM(GNOME Display Manager)。 GDM, which is installed as a part of the GNOME desktop (but is disabled by default), can be enabled by adding gdm_enable="YES" to /etc/rc.conf. Once you have rebooted, GNOME will start automatically once you log in —— no further configuration is necessary.
GNOME may also be started from the command-line by properly configuring a file named .xinitrc. If a custom .xinitrc is already in place, simply replace the line that starts the current window manager with one that starts /usr/local/bin/gnome-session instead. If nothing special has been done to the configuration file, then it is enough simply to type:
% echo "/usr/local/bin/gnome-session" > ~/.xinitrc
Next, type startx, and the GNOME desktop environment will be started.
Note: If an older display manager, like XDM, is being used, this will not work. Instead, create an executable .xsession file with the same command in it. To do this, edit the file and replace the existing window manager command with /usr/local/bin/gnome-session:
% echo "#!/bin/sh" > ~/.xsession % echo "/usr/local/bin/gnome-session" >> ~/.xsession % chmod +x ~/.xsession
Yet another option is to configure the display manager to allow choosing the window manager at login time; the section on KDE details explains how to do this for kdm, the display manager of KDE.
X11 supports anti-aliasing via its “RENDER” extension. GTK+ 2.0 and greater (the
toolkit used by GNOME) can make use of this functionality.
Configuring anti-aliasing is described in Section 5.5.3. So,
with up-to-date software, anti-aliasing is possible within the GNOME desktop. Just go to Applications->Desktop
Preferences->Font, and select either Best shapes, Best contrast, or
Subpixel smoothing (LCDs). For a GTK+ application that is
not part of the GNOME desktop, set the environment variable
GDK_USE_XFT to 1 before launching
the program.
KDE is an easy to use contemporary desktop environment. Some of the things that KDE brings to the user are:
A beautiful contemporary desktop
A desktop exhibiting complete network transparency
An integrated help system allowing for convenient, consistent access to help on the use of the KDE desktop and its applications
Consistent look and feel of all KDE applications
Standardized menu and toolbars, keybindings, color-schemes, etc.
Internationalization: KDE is available in more than 40 languages
Centralized, consistent, dialog-driven desktop configuration
A great number of useful KDE applications
KDE comes with a web browser called Konqueror, which is a solid competitor to other existing web browsers on UNIX systems. More information on KDE can be found on the KDE website. For FreeBSD specific information and resources on KDE, consult the KDE on FreeBSD team's website.
如同 GNOME 或其他桌面管理軟體一樣, 也可以輕鬆透過 package 或 Ports Collection 來安裝:
To install the KDE package from the network, simply type:
# pkg_add -r kde
pkg_add(1) will automatically fetch the latest version of the application.
To build KDE from source, use the ports tree:
# cd /usr/ports/x11/kde3 # make install clean
After KDE has been installed, the X server must be told to launch this application instead of the default window manager. This is accomplished by editing the .xinitrc file:
% echo "exec startkde" > ~/.xinitrc
Now, whenever the X Window System is invoked with startx, KDE will be the desktop.
If a display manager such as XDM is being used, the configuration is slightly different. Edit the .xsession file instead. Instructions for kdm are described later in this chapter.
Now that KDE is installed on the system, most things can be discovered through the help pages, or just by pointing and clicking at various menus. Windows or Mac® users will feel quite at home.
The best reference for KDE is the on-line documentation. KDE comes with its own web browser, Konqueror, dozens of useful applications, and extensive documentation. The remainder of this section discusses the technical items that are difficult to learn by random exploration.
An administrator of a multi-user system may wish to have a graphical login screen to welcome users. XDM can be used, as described earlier. However, KDE includes an alternative, kdm, which is designed to look more attractive and include more login-time options. In particular, users can easily choose (via a menu) which desktop environment (KDE, GNOME, or something else) to run after logging on.
To enable kdm, the ttyv8 entry in /etc/ttys has to be adapted. The line should look as follows:
ttyv8 "/usr/local/bin/kdm -nodaemon" xterm on secure
XFce is a desktop environment based on the GTK+ toolkit used by GNOME, but is much more lightweight and meant for those who want a simple, efficient desktop which is nevertheless easy to use and configure. Visually, it looks very much like CDE, found on commercial UNIX systems. Some of XFce's features are:
A simple, easy-to-handle desktop
Fully configurable via mouse, with drag and drop, etc.
Main panel similar to CDE, with menus, applets and applications launchers
Integrated window manager, file manager, sound manager, GNOME compliance module, and more
Themeable (since it uses GTK+)
Fast, light and efficient: ideal for older/slower machines or machines with memory limitations
More information on XFce can be found on the XFce website.
A binary package for XFce exists (at the time of writing). To install, simply type:
# pkg_add -r xfce4
Alternatively, to build from source, use the ports collection:
# cd /usr/ports/x11-wm/xfce4 # make install clean
Now, tell the X server to launch XFce the next time X is started. Simply type this:
% echo "/usr/local/bin/startxfce4" > ~/.xinitrc
The next time X is started, XFce will be the desktop. As before, if a display manager like XDM is being used, create an .xsession, as described in the section on GNOME, but with the /usr/local/bin/startxfce4 command; or, configure the display manager to allow choosing a desktop at login time, as explained in the section on kdm.
既然基礎的部分已經提過了,接下來的這個部分將會討論一些常會用到的 FreeBSD 的特色,這些章節包括:
介紹給您常見且實用的桌面應用軟體:網頁瀏覽器、生產力工具、文件檢視程式等。
介紹給您眾多 FreeBSD 上可用的多媒體工具。
解釋如何編譯自訂 FreeBSD 核心以增加額外系統功能的流程。
詳細描述列印系統,包含桌上型印表機及網路印表機的設定。
展示給您看如何在您的 FreeBSD 系統中執行 Linux 應用軟體。
這些章節中有些需要您預先閱讀些相關文件,在各章節開頭的概要內會提及。
在 FreeBSD 上面可以執行非常多種類的桌面應用程式, 像是網頁瀏覽器和文字處理軟體等。 這些程式大都可以透過套件來安裝或是從 Ports Collection 中自動編譯安裝。 許多新的使用者會希望能在在他們的桌面系統中找到這些程式。 這章將會告訴你如何不用費太多功夫去安裝一些熱門的桌面應用程式, 不管是從套件或是從 Ports Collection 中安裝。
需要注意到的是:當從 ports 中安裝程式的時候, 它們是從原始碼開始編譯的。依照你編譯的 ports 和電腦速度(硬體等級), 有可能會花很長一段時間才能完成。 如果從原始碼編譯對你來說會花太多時間的話, 大部分的 ports 你都能找到事先編譯好的套件來安裝。
因為 FreeBSD 具有相容 Linux 二進制的特性, 許多原先在 Linux 上開發的應用程式都能在你的 FreeBSD 桌面環境執行。 在安裝任何 Linux 應用程式之前,強烈建議你先閱讀 Chapter 10 Linux 執行相容模式這個章節。 而許多用 Linux 二進制相容模式的軟體在 ports 裡頭通常都會用 “linux-” 開頭。 當你在搜尋某個特定軟體時,記住這點,並且可以使用 whereis(1) 來找。 在下列的說明中, 都假設你在安裝任何 Linux 應用軟體之前, 已經事先啟用了 Linux 二進制相容模式。
下列目錄是這章中所涵蓋的應用程式:
瀏覽器 (像是 Mozilla, Opera, Firefox, Konqueror)
辦公軟體 (像是 KOffice, AbiWord, The GIMP, OpenOffice.org)
文件瀏覽軟體 (像是 Acrobat Reader®, gv, Xpdf, GQview)
財務處理軟體 (像是 GnuCash, Gnumeric, Abacus)
在閱讀這章之前,你必須
知道如何安裝其他的軟體(third-party software) (Chapter 4).
知道如何安裝 Linux 軟體 (Chapter 10).
要知道更多關於多媒體環境的資訊,請先閱讀 Chapter 7 多媒體章節。 如果你想要設定和使用電子郵件,也請你先看 Chapter 26郵件章節。
在 FreeBSD 中並沒有預先安裝好的特定瀏覽器。 但在 Ports Collection 之中卻有許多瀏覽器可供你安裝使用。 如果你沒有足夠時間去編譯所有的東西 (在某些情況下這可能會花上很長的一段時間), 這些都有現成的套件可供直接安裝。
KDE 和 GNOME 桌面環境都已提供 HTML 瀏覽器。 請參考 Section 5.7 來了解更多有關如何設定這些完整的桌面環境系統資訊。
如果你在尋找輕量化的瀏覽器,你可以從 Ports Collection 中找到下面的幾種: www/dillo, www/links, 或 www/w3m。
這節介紹這些瀏覽器:
| 瀏覽器名稱 | 所需的系統資源 | 從 ports 安裝時間 | 主要相依的軟體 |
|---|---|---|---|
| Mozilla | 多 | 長 | Gtk+ |
| Opera | 少 | 短 | FreeBSD 和 Linux 的版本都有。 Linux 的版本需要 Linux 二進制相容模組以及 linux-openmotif. |
| Firefox | 中度 | 長 | Gtk+ |
| Konqueror | 中度 | 長 | KDE 函式庫 |
Mozilla 是相當現代化、穩定且完全移植至 FreeBSD 系統上。 它也具備有十分符合 HTML 標準的顯示引擎, 它更提供了郵件及新聞群組的閱讀功能。 此外如果你打算要自己寫一些網頁的話,它還提供了 HTML 的編輯器。 如果是 Netscape 的使用者, 你可能會認出這跟 Communicator 很像, 它們其實同樣是使用相同基礎的瀏覽器。
在速度較慢,像是 CPU 速度少於 233MHz 或是小於 64MB 記憶體的機器上面, 完全使用 Mozilla 會是件極度耗費資源的事。 所以在這樣的機器上面,你可能會想要使用 Opera 這樣輕量級的瀏覽器,而接下來後面會提到。
如果你有什麼原因不能或是不想編譯 Mozilla 的話,FreeBSD GNOME 團隊已經為你做好了這件事。 只要用下面的指令透過網路安裝套件就行了:
# pkg_add -r mozilla
如果沒有找到套件可以使用,而你也有足夠的時間和磁碟空間來編譯 Mozilla 並安裝到你的系統中, 你可以透過下列步驟來安裝:
# cd /usr/ports/www/mozilla # make install clean
Mozilla 需要使用 root 的權限來執行 chrome 註冊來確保正確的初始化。 另外,如果你需要抓一些額外的外掛程式像是 mouse gestures, 你就必須要使用 root 的權限來安裝, 以適當的安裝這些外掛程式。
一旦你完成了 Mozilla 的安裝,你就再也不需要 root 的權限了。 你可以直接打下面的指令來啟動 Mozilla:
% mozilla
也可以直接打下列指令,直接啟動郵件和新聞閱讀器:
% mozilla -mail
Firefox 是以 Mozilla 原始碼為基礎的新世代瀏覽器。 Mozilla 是一堆應用軟體的整合套裝, 像是瀏覽器、郵件程式、聊天室軟體等所組成。 Firefox 則純粹是瀏覽器, 這也是為何它能短小精悍之故。
可以打下列指令來安裝:
#pkg_add -r firefox
也可以透過 Ports Collection,以編譯原始碼的方式來安裝:
#cd /usr/ports/www/firefox # make install clean
Note: 本節以及下一節,均假設您已裝好 Firefox 或 Mozilla。
FreeBSD 基金會與 Sun Microsystems 有達成授權協議, 可以散播 Java Runtime Environment(JRE™) 及 Java Developement Kit(JDK™) 的 FreeBSD 版 binary(執行檔)。 FreeBSD 版的 binary 可以在 FreeBSD 基金會 網站下載。
要讓 Firefox 或 Mozilla 支援 Java™ 的話,首先要先裝 java/javavmwrapper 這個 port。 然後再去 http://www.freebsdfoundation.org/downloads/java.shtml 下載 Diablo JRE,並以 pkg_add(1) 指令來安裝之。
接著啟動瀏覽器,在網址列輸入 about:plugins 然後按 Enter 鍵,就會顯示目前已裝的 plugins 清單, 這時應該就可以看到 Java 也有列出來。 若仍未看到的話,那就切換為 root 帳號, 打下列指令:
# ln -s /usr/local/diablo-jre1.5.0/plugin/i386/ns7/libjavaplugin_oji.so \ /usr/local/lib/browser_plugins/
最後,重啟瀏覽器即可。
Macromedia® Flash™ plugin 程式並沒有 FreeBSD 版, 然而可以透過軟體層(wrapper)來執行 Linux 版的 plugin 程式。 這個 wrapper 同時也支援 Adobe® Acrobat® 以及 RealPlayer® plugin 等。
接下來去裝 www/linuxpluginwrapper。 linuxpluginwrapper 需要先裝一個很大的 emulators/linux_baseport。 然後根據 port 所指示的作法, 去正確地設定你的 /etc/libmap.conf! 設定的範例檔案位於 /usr/local/share/examples/linuxpluginwrapper/ 的目錄底下。
下一步,則是裝 www/linux-flashplugin7。 裝好後,再啟動瀏覽器,在網址列輸入 about:plugins, 然後按 Enter 鍵就會顯示目前已裝的 plugin 清單。
若 Flash plugin 沒出現的話,大多可能是因為漏了做 symlink 連結之故。 請切為 root 帳號,打下列指令:
# ln -s /usr/local/lib/npapi/linux-flashplugin/libflashplayer.so \ /usr/local/lib/browser_plugins/ # ln -s /usr/local/lib/npapi/linux-flashplugin/flashplayer.xpt \ /usr/local/lib/browser_plugins/
最後,重啟瀏覽器應該就可看到了。
Note: linuxpluginwrapper 只能在 i386 的系統架構下運行。
Opera 是個具備完整功能、符合標準的瀏覽器。 它同時也具備了內建的郵件、新聞閱讀器、IRC、RSS/Atom feeds 閱讀器等。 此外 Opera 更是個輕量級、 執行速度又快的瀏覽器。 它在 ports 中有兩種版本:「原生」的 FreeBSD 版本還有在 Linux 模擬模式下的版本。
要用 Opera 的 FreeBSD 版本來瀏覽網頁的話, 用下面的指令安裝:
# pkg_add -r opera
有些 FTP 站台並沒有全部的套件, 但是打下面的指令就能從 Ports Collection 中安裝:
# cd /usr/ports/www/opera # make install clean
要安裝 Opera 的 Linux 版本的話, 請將上面例子中的 opera 替換成 linux-opera。 有些時候, Linux 的版本是十分有用的, 像是只有 Linux 版本外掛程式的時候。 但在其他方面來說, FreeBSD 和 Linux 的版本功能上是一樣的。
Konqueror 是 KDE 桌面系統的一部分,但是它也可以藉由安裝 x11/kdebase3 在 KDE 環境以外使用。 Konqueror 不只是個網頁瀏覽器, 他同時也是檔案管理器和多媒體瀏覽器。
Konqueror 也有許多的外掛程式, 這些外掛程式可以從 misc/konq-plugins 中安裝。
Konqueror 也支援 Flash 的外掛程式。 如何安裝的說明請參閱:http://freebsd.kde.org/howto.php。
當開始進行辦公, 新的使用者通常會去找好用的辦公室軟體或是好上手的文字處理器。 目前 有些桌面環境 像是 KDE已經提供了辦公軟體組合的套件。 FreeBSD 提供了所需的所有辦公軟體,桌面環境也不例外。
這節涵蓋了下列的這些軟體:
| 軟體名稱 | 所需系統資源 | 從 Ports 安裝的時間 | 主要相依套件 |
|---|---|---|---|
| KOffice | 少 | 長 | KDE |
| AbiWord | 少 | 短 | Gtk+ 或是 GNOME |
| The Gimp | 少 | 長 | Gtk+ |
| OpenOffice.org | 多 | 很久 | JDK 1.4, Mozilla |
KDE 社群在它的桌面環境裡頭提供了一個可以在 KDE 外使用的辦公軟體組合。 它包含了四種模組: KWord 是文字處理器, KSpread 是試算表程式, KPresenter 是簡報播放程式, 另外 Karbon14 讓你可以產生圖形化的文件。 [5]
在安裝最新版的 KOffice 之前, 請先確定你有最新版本的 KDE。
若要用套件來安裝 KOffice, 請依照下面的指令:
# pkg_add -r koffice
如果套件不存在的話,你可以使用 ports collection. 例如要安裝 KDE3 中的 KOffice,請使用下列指令安裝:
# cd /usr/ports/editors/koffice-kde3 # make install clean
AbiWord 是一個免費的文字處理軟體,外觀和感覺都近似於 Microsoft Word。 它適合處理文件、信件、報告、備忘錄等等。 它也非常快速,包含了許多功能而且非常容易上手。
AbiWord 可以輸入或輸出許多檔案格式, 包括一些有專利的格式,例如微軟(Microsoft)公司的 .doc 格式。
AbiWord 也能用套件安裝, 你可以用下列指令來安裝:
# pkg_add -r abiword
如果找不到套件的話,它也可以從 Ports Collection 中編譯安裝。 而 Ports Collection 應該要保持在最新的狀態。 AbiWord 可以透過下列方式編譯安裝:
# cd /usr/ports/editors/abiword # make install clean
對於影像的編輯及修改來說,GIMP 是非常精緻的影像處理軟體。 它可以當作簡單的繪圖軟體或是高品質的相片處理軟體。 它支援為數眾多的外掛程式及指令稿 (script-fu) 介面。 GIMP 可以讀寫許多檔案格式。 它也支援掃描器 [6] 和手寫板。
譯註:GIMP 在目前是 2.x 版,如果你想要安裝 1.x 版的話,請用 Ports Collection 中的 graphics/gimp1。 另外如果你已經使用習慣 Adobe Photoshop,而且不習慣 GIMP 介面的話,你也可以嘗試安裝 graphics/gimpshop, 它的使用介面十分類似 Adobe Photoshop。
你可以使用下面指令安裝套件:
# pkg_add -r gimp
如果的你的 FTP 站台沒有這個套件,你可以使用 Ports Collection。 在 Ports Collection 的 graphics 目錄下也包含了 The Gimp Manual(GIMP 使用手冊)。 下面示範如何安裝這些程式:
# cd /usr/ports/graphics/gimp # make install clean # cd /usr/ports/graphics/gimp-manual-pdf # make install clean
譯註:另外在 Ports Collection 中也有一些外掛程式可以使用, 例如說可以處理數位相機 raw 檔案格式的 gimp-ufraw。
Note: GIMP 使用手冊也有 HTML 格式的,你可以在 graphics/gimp-manual-html 中安裝。
OpenOffice.org 包含了所有完整的辦公軟體組合: 文字處理器、試算表、簡報軟體還有繪圖軟體。 除了它的使用者介面非常類似其他的辦公軟體, 他還能夠輸入和輸出許多熱門的檔案格式。 它也包含了不同語言的使用者介面、拼字檢查和字典。
OpenOffice.org 的文字處理器使用 XML 檔案格式來增加移植性及彈性。 試算表程式支援巨集(macro)功能而且能夠使用外來的資料庫介面。 OpenOffice.org 已經十分穩定, 並且能夠在 Windows, Solaris™, Linux, FreeBSD 及 Mac OS X 等作業系統上面執行。 想知道更多關於 OpenOffice.org 的資訊可以在 OpenOffice.org 網頁 上查詢。你也可以在 FreeBSD OpenOffice.org 移植團隊 的網頁上查詢關於 FreeBSD 上 OpenOffice 特定的資訊或直接下載已編譯好的套件
要安裝 OpenOffice.org, 請用以下方式來執行:
# pkg_add -r openoffice.org
Note: 當你在使用 FreeBSD -RELEASE 版本的時候,上面的作法應該行得通。 要是其他的版本,你應該看一下 FreeBSD OpenOffice.org 移植團隊的網站,並且用 pkg_add(1) 安裝合適的套件。 在這個站台都可以下載到穩定的釋出版(release)或開發中的版本。
當已經安裝完之後,你只要鍵入下面的指令就能執行 OpenOffice.org:
% openoffice.org
譯註:端看你的版本,有時候需要輸入如 openoffice.org-2.0.1 之類的指令,不過你也可以用 shell 中的 alias 或是用 symbolic link 來處理。
Note: 在第一次啟動的時候,OpenOffice 會問到一些問題。 而且在你的家目錄底下會自動建立 .openoffice.org2 的資料夾。
如果無法取得 OpenOffice.org 的套件,你仍然可以選擇從 port 編譯。 不過你必須謹記在心:編譯的過程會需要大量的磁碟空間且相當耗時。
# cd /usr/ports/editors/openoffice.org-2 # make install clean
Note: 如果你想要安裝本地化的版本,把前面的指令代換成下面的:
# make LOCALIZED_LANG=你的語言 install clean你必須把你的語言 換成正確的語言 ISO-code [7] 所支援的語言代碼清單可以在 port 目錄裡的 files/Makefile.localized 檔案中找到。
一旦完成了上述步驟, OpenOffice.org 可用以下指令啟動:
% openoffice.org
近年來有些文件格式變得愈來愈流行, 基本的系統中也許不會有這些格式所需的標準閱覽器。 在這一節,我們來看看怎麼安裝這些軟體。
這張涵蓋了下列的軟體
| 軟體名稱 | 所需系統資源 | 從 Ports 安裝時間 | 主要相依套件 |
|---|---|---|---|
| Acrobat Reader | 少 | 短 | Linux 二進制相容模組 |
| gv | 少 | 短 | Xaw3d |
| Xpdf | 少 | 短 | FreeType |
| GQview | 少 | 短 | Gtk+ 或是 GNOME |
許多文件在散佈的時候都是用 PDF 的檔案格式, 這個格式是基於 “可攜式文件格式(Portable Document Format)”。 其中一個推薦的閱覽軟體就是Acrobat Reader, 它是由 Adobe 公司發行給 Linux 使用的版本。 因為 FreeBSD 也可以執行 Linux 二進位檔案, 所以它也能在 FreeBSD 上面執行。
要從 Ports Collection 中安裝 Acrobat Reader 7 只要:
# cd /usr/ports/print/acroread7 # make install clean
因為授權的限制,所以不提供編譯好的套件。
gv是 PostScript 和 PDF 的閱覽器。 它建構於 ghostview的基礎上, 不過因為使用 Xaw3d 函式庫, 所以外觀看起來比較漂亮。 gv 速度快,介面簡潔並且有許多功能, 比如說方向性、紙張大小、縮放比例、和反鋸齒(antialias)等。 而且幾乎所有的使用都可以從鍵盤或滑鼠來完成。
用套件來安裝 gv,使用下列指令:
# pkg_add -r gv
如果你不能取得套件,你可以使用 Ports Collection:
# cd /usr/ports/print/gv # make install clean
如果你想要一個小型的 FreeBSD PDF 閱覽軟體, Xpdf是個輕量級而且有效率的閱覽器。 它只需要非常少的資源而且十分穩定。 它只使用標準的 X 字型而不需要 Motif 或是其他的 X 工具組(toolkit)。
用套件來安裝 Xpdf,使用下列指令:
# pkg_add -r xpdf
如果套件不存在或是你偏好使用 Ports Collection, 使用以下指令:
# cd /usr/ports/graphics/xpdf # make install clean
一旦完成了安裝,你可以啟動 Xpdf 並且使用滑鼠右鍵去使用選單。
GQview 是影像管理軟體。 你可以用單鍵來閱覽檔案、啟動額外的編輯器、縮圖預覽等功能。 它也有幻燈片播放(slideshow)及一些基本的檔案操作功能。 你可用 GQview 管理影像集並能輕鬆地找出重複的檔案。 GQview 能夠使用全螢幕觀看並支援國際化。
如果你想要安裝 GQview的套件, 請使用下列指令:
# pkg_add -r gqview
如果套件無法取得,或是你比較喜歡使用 Ports Collection,只要:
# cd /usr/ports/graphics/gqview # make install clean
如果有任何理由你想要在你的 FreeBSD 桌面環境上管理你的個人財務, 這裡有一些功能強大、使用簡單的應用程式可供安裝。 這些財務管理軟體之中有些是相容於流行的 Quicken® 或 Excel 文件。
這節涵蓋了下面這些軟體:
GnuCash 是 GNOME 團隊努力成果中的一部分, 而 GNOME 主要是提供終端使用者(end-users) 親切而強大的桌面應用程式。 使用 GnuCash, 你可以持續紀錄你的收入及花費、你的銀行帳戶、或是你的股票證券等。 它的特性是介面直覺但功能仍非常專業。
GnuCash 提供了一個智慧的註冊器、 帳戶層級系統、許多快速鍵及自動完成(auto-completion)模式。 它也能分開單一的報表至數個詳細的部份。 GnuCash 也能夠輸入及合併 Quicken QIF 檔案。 它也能處理大部分國際的日期及通用貨幣之格式。
要安裝 GnuCash 到你的系統中, 只要做下列步驟:
# pkg_add -r gnucash
如果不能取得套件,你可以使用 Ports Collection:
# cd /usr/ports/finance/gnucash # make install clean
Gnumeric 是 GNOME 桌面環境中的試算表。 它的特點是能夠根據儲存格格式(cell format)及自動補齊的系統, 來方便自動地「猜出」使用者的輸入。 它也能夠輸入許多熱門的檔案格式,像是 Excel, Lotus 1-2-3, 或是 Quattro Pro。 Gnumeric 支援使用 math/guppi 繪圖軟體來繪圖。 它有許多內建的函數而且允許一般的儲存格格式,像是: 數字、貨幣、日期、時間及其他格式等。
要用套件安裝 Gnumeric,只要打以下指令:
# pkg_add -r gnumeric
如果套件不存在,你可以做下面的步驟來使用 Ports Collection 編譯安裝:
# cd /usr/ports/math/gnumeric # make install clean
Abacus 是個小巧又使用簡單的試算表。 它包含了許多內建的函數,在相關的領域如統計學、財務、數學中很實用。 它也可以輸出輸入 Excel 的檔案格式。 另外 Abacus也能夠輸出 PostScript 格式。
從套件安裝 Abacus 只要做:
# pkg_add -r abacus
如果套件不能取得的話,你可以使用 Ports Collection, 並用以下指令:
# cd /usr/ports/deskutils/abacus # make install clean
雖然 FreeBSD 是因為效能及穩定性而在 ISP 之間很流行, 不過它也可以完全當作桌面環境(desktop)來使用, 並不侷限於使用在伺服器上面。目前有數千種應用程式的 套件(packages) 或 ports, 可供使用,你可以根據你的需求打造出一個完美的桌面環境。
下面是這章涵蓋的所有桌面應用軟體之快速回顧表:
| 軟體名稱 | 套件名稱 | Ports 名稱 |
|---|---|---|
| Mozilla | mozilla | www/mozilla |
| Opera | opera | www/opera |
| Firefox | firefox | www/firefox |
| KOffice | koffice-kde3 | editors/koffice-kde3 |
| AbiWord | abiword | editors/abiword |
| The GIMP | gimp | graphics/gimp |
| OpenOffice.org | openoffice | editors/openoffice-1.1 |
| Acrobat Reader | acroread | print/acroread7 |
| gv | gv | print/gv |
| Xpdf | xpdf | graphics/xpdf |
| GQview | gqview | graphics/gqview |
| GnuCash | gnucash | finance/gnucash |
| Gnumeric | gnumeric | math/gnumeric |
| Abacus | abacus | deskutils/abacus |
FreeBSD 廣泛地支援各種音效卡, 讓您可以享受來自電腦上的高傳真音質(Hi-Fi), 此外還包括了錄製和播放 MPEG Audio Layer 3 (MP3)、 WAV、 以及 Ogg Vorbis 等許多種格式聲音的能力。同時 FreeBSD Ports Collection 也包括了許多的應用程式, 讓您可以錄音、編修音效以及控制 MIDI 配備。
要是喜歡動手嘗試不同的體驗, FreeBSD 也能播放一般的視訊檔和 DVD。 編碼、轉換和播放視訊的程式比起處理聲音的程式略少一些。例如, 在撰寫這章時, FreeBSD Ports Collection 中還沒有類似 audio/sox 那樣好用的編碼工具,能夠用來轉換不同的格式。 不過,這個領域的軟體研發進展是相當迅速的。
本章將介紹設定音效卡的必要步驟。先前介紹到的 X11 (Chapter 5) 安裝和設定裡,已經講到了顯示卡的部份, 但要想有更好的播放效果, 仍需要一些細部調整。
讀完這章,您將了解:
如何設定系統,以正確識別音效卡。
如何運用樣本程式,以測試音效卡是否正常運作。
如何解決音效卡的設定問題。
如何播放、錄製 MP3 及其他聲音檔案格式。
X server 是如何支援顯示卡。
Ports Collections 內有哪些好用的影像播放、錄製軟體。
如何播放 DVD 的 .mpg 及 .avi 檔
如何從 CD 和 DVD 中擷取(rip)檔案。
如何設定電視卡
如何設定掃描器
在閱讀這章之前,您應當了解:
知道如何設定、安裝新的 kernel (Chapter 8)。
Warning: 如果要用 mount(8) 指令來 mount 音樂光碟的話,通常會發生錯誤, 甚至導致 kernel panic。 這是因為音樂光碟是特殊編碼,而非一般的 ISO 檔案系統之故。
開始設定之前,必須先知道你的音效卡型號、晶片為何,以及是 PCI 或 ISA 規格。 FreeBSD 有支援許多種的 PCI、ISA 音效卡,請檢查支援的音效硬體表 Hardware Notes,以確認你的音效卡是否支援。 本文也會提到相對應該卡的驅動程式。
要使用音效卡,必須要載入正確的驅動程式才行。有兩種方式都可以完成這動作, 最簡單方式就是以 kldload(8) 來輕鬆載入 kernel 動態模組(module), 像是下列指令:
# kldload snd_emu10k1
或者把相關驅動程式加到 /boot/loader.conf 檔,像是:
snd_emu10k1_load="YES"
上面例子是給 Creative SoundBlaster® Live! 音效卡使用的。 其他可用的音效卡驅動程式模組,可參考 /boot/defaults/loader.conf 範例。 若不確定到底該用哪一種驅動程式,那麼可以試試載入 snd_driver 模組看看:
# kldload snd_driver
This is a metadriver loading the most common device drivers at once. This speeds up the search for the correct driver. It is also possible to load all sound drivers via the /boot/loader.conf facility.
If you wish to find out the driver selected for your soundcard after loading the snd_driver metadriver, you may check the /dev/sndstat file with the cat /dev/sndstat command.
Note: Under FreeBSD 4.X, to load all sound drivers, you have to load the snd module instead of snd_driver.
A second method is to statically compile in support for your sound card in your kernel. The section below provides the information you need to add support for your hardware in this manner. For more information about recompiling your kernel, please see Chapter 8.
The first thing to do is adding the generic audio driver sound(4) to the kernel, for that you will need to add the following line to the kernel configuration file:
device sound
Under FreeBSD 4.X, you would use the following line:
device pcm
Then we have to add the support for our sound card. Therefore, we need to know which driver supports the card. Check the supported audio devices list of the Hardware Notes, to determine the correct driver for your sound card. For example, a Creative SoundBlaster Live! sound card is supported by the snd_emu10k1(4) driver. To add the support for this card, use the following:
device snd_emu10k1
Be sure to read the manual page of the driver for the syntax to use. Information regarding the syntax of sound drivers in the kernel configuration can also be found in the /usr/src/sys/conf/NOTES file (/usr/src/sys/i386/conf/LINT for FreeBSD 4.X).
Non-PnP ISA cards may require you to provide the kernel with information on the sound card settings (IRQ, I/O port, etc). This is done via the /boot/device.hints file. At system boot, the loader(8) will read this file and pass the settings to the kernel. For example, an old Creative SoundBlaster 16 ISA non-PnP card will use the snd_sbc(4) driver in conjunction with snd_sb16(4). For this card the following lines have to be added to the kernel configuration file:
device snd_sbc device snd_sb16
as well as the following in /boot/device.hints:
hint.sbc.0.at="isa" hint.sbc.0.port="0x220" hint.sbc.0.irq="5" hint.sbc.0.drq="1" hint.sbc.0.flags="0x15"
In this case, the card uses the 0x220 I/O port and the IRQ 5.
The syntax used in the /boot/device.hints file is covered in the sound driver manual page. On FreeBSD 4.X, these settings are directly written in the kernel configuration file. In the case of our ISA card, we would only use this line:
device sbc0 at isa? port 0x220 irq 5 drq 1 flags 0x15
The settings shown above are the defaults. In some cases, you may need to change the IRQ or the other settings to match your card. See the snd_sbc(4) manual page for more information.
Note: Under FreeBSD 4.X, some systems with built-in motherboard sound devices may require the following option in the kernel configuration:
options PNPBIOS
After rebooting with the modified kernel, or after loading the required module, the sound card should appear in your system message buffer (dmesg(8)) as something like:
pcm0: <Intel ICH3 (82801CA)> port 0xdc80-0xdcbf,0xd800-0xd8ff irq 5 at device 31.5 on pci0 pcm0: [GIANT-LOCKED] pcm0: <Cirrus Logic CS4205 AC97 Codec>
The status of the sound card may be checked via the /dev/sndstat file:
# cat /dev/sndstat FreeBSD Audio Driver (newpcm) Installed devices: pcm0: <Intel ICH3 (82801CA)> at io 0xd800, 0xdc80 irq 5 bufsz 16384 kld snd_ich (1p/2r/0v channels duplex default)
The output from your system may vary. If no pcm devices show up, go back and review what was done earlier. Go through your kernel configuration file again and make sure the correct device is chosen. Common problems are listed in Section 7.2.2.1.
If all goes well, you should now have a functioning sound card. If your CD-ROM or DVD-ROM drive is properly coupled to your sound card, you can put a CD in the drive and play it with cdcontrol(1):
% cdcontrol -f /dev/acd0 play 1
Various applications, such as audio/workman can provide a friendlier interface. You may want to install an application such as audio/mpg123 to listen to MP3 audio files. A quick way to test the card is sending data to the /dev/dsp, like this:
% cat filename > /dev/dsp
where filename can be any file. This command line should produce some noise, confirming the sound card is actually working.
Note: FreeBSD 4.X users need to create the sound card device nodes before being able to use it. If the card showed up in message buffer as pcm0, you will have to run the following as root:
# cd /dev # sh MAKEDEV snd0If the card detection returned pcm1, follow the same steps as shown above, replacing snd0 with snd1.
MAKEDEV will create a group of device nodes that will be used by the different sound related applications.
Sound card mixer levels can be changed via the mixer(8) command. More details can be found in the mixer(8) manual page.
| Error | Solution |
|---|---|
| “unsupported subdevice XX” |
One or more of the device nodes was not created correctly. Repeat the steps above. |
| “sb_dspwr(XX) timed out” |
The I/O port is not set correctly. |
| “bad irq XX” |
The IRQ is set incorrectly. Make sure that the set IRQ and the sound IRQ are the same. |
| “xxx: gus pcm not attached, out of memory” |
There is not enough available memory to use the device. |
| “xxx: can't open /dev/dsp!” |
Check with fstat | grep dsp if another application is holding the device open. Noteworthy troublemakers are esound and KDE's sound support. |
It is often desirable to have multiple sources of sound that are able to play simultaneously, such as when esound or artsd do not support sharing of the sound device with a certain application.
FreeBSD lets you do this through Virtual Sound Channels, which can be set with the sysctl(8) facility. Virtual channels allow you to multiplex your sound card's playback channels by mixing sound in the kernel.
To set the number of virtual channels, there are two sysctl knobs which, if you are the root user, can be set like this:
# sysctl hw.snd.pcm0.vchans=4 # sysctl hw.snd.maxautovchans=4
The above example allocates four virtual channels, which is a practical number for
everyday use. hw.snd.pcm0.vchans is the number of virtual
channels pcm0 has, and is configurable once a device has been
attached. hw.snd.maxautovchans is the number of virtual channels
a new audio device is given when it is attached using kldload(8). Since the
pcm module can be loaded independently of the hardware
drivers, hw.snd.maxautovchans can store how many virtual
channels any devices which are attached later will be given.
Note: You cannot change the number of virtual channels for a device while it is in use. First close any programs using the device, such as music players or sound daemons.
If you are not using
devfs(5), you
will have to point your applications at /dev/dsp0.x, where x is 0 to 3
if hw.snd.pcm.0.vchans is set to 4 as in the above example.
On a system using
devfs(5), the
above will automatically be allocated transparently to the user.
Note: 本功能只有在 FreeBSD 5.3-RELEASE 及之後版本才有支援。
The default values for the different mixer channels are hardcoded in the sourcecode of the pcm(4) driver. There are a lot of different applications and daemons that allow you to set values for the mixer they remember and set each time they are started, but this is not a clean solution, we want to have default values at the driver level. This is accomplished by defining the appropriate values in /boot/device.hints. E.g.:
hint.pcm.0.vol="100"
This will set the volume channel to a default value of 100, when the pcm(4) module is loaded.
MP3 (MPEG Layer 3 Audio) accomplishes near CD-quality sound, leaving no reason to let your FreeBSD workstation fall short of its offerings.
By far, the most popular X11 MP3 player is XMMS (X Multimedia System). Winamp skins can be used with XMMS since the GUI is almost identical to that of Nullsoft's Winamp. XMMS also has native plug-in support.
XMMS can be installed from the multimedia/xmms port or package.
XMMS' interface is intuitive, with a playlist, graphic equalizer, and more. Those familiar with Winamp will find XMMS simple to use.
The audio/mpg123 port is an alternative, command-line MP3 player.
mpg123 can be run by specifying the sound device and the MP3 file on the command line, as shown below:
# mpg123 -a /dev/dsp1.0 Foobar-GreatestHits.mp3 High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2 and 3. Version 0.59r (1999/Jun/15). Written and copyrights by Michael Hipp. Uses code from various people. See 'README' for more! THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK! Playing MPEG stream from Foobar-GreatestHits.mp3 ... MPEG 1.0 layer III, 128 kbit/s, 44100 Hz joint-stereo
/dev/dsp1.0 should be replaced with the dsp device entry on your system.
Before encoding a CD or CD track to MP3, the audio data on the CD must be ripped onto the hard drive. This is done by copying the raw CDDA (CD Digital Audio) data to WAV files.
The cdda2wav tool, which is a part of the sysutils/cdrtools suite, is used for ripping audio information from CDs and the information associated with them.
With the audio CD in the drive, the following command can be issued (as root) to rip an entire CD into individual (per track) WAV files:
# cdda2wav -D 0,1,0 -B
cdda2wav will support ATAPI (IDE) CDROM drives. To rip from an IDE drive, specify the device name in place of the SCSI unit numbers. For example, to rip track 7 from an IDE drive:
# cdda2wav -D /dev/acd0a -t 7
The -D 0,1,0 indicates
the SCSI device 0,1,0, which corresponds to the output of cdrecord -scanbus.
To rip individual tracks, make use of the -t option as
shown:
# cdda2wav -D 0,1,0 -t 7
This example rips track seven of the audio CDROM. To rip a range of tracks, for example, track one to seven, specify a range:
# cdda2wav -D 0,1,0 -t 1+7
The utility dd(1) can also be used to extract audio tracks on ATAPI drives, read Section 18.6.5 for more information on that possibility.
Nowadays, the mp3 encoder of choice is lame. Lame can be found at audio/lame in the ports tree.
Using the ripped WAV files, the following command will convert audio01.wav to audio01.mp3:
# lame -h -b 128 \ --tt "Foo Song Title" \ --ta "FooBar Artist" \ --tl "FooBar Album" \ --ty "2001" \ --tc "Ripped and encoded by Foo" \ --tg "Genre" \ audio01.wav audio01.mp3
128 kbits seems to be the standard MP3 bitrate in use. Many enjoy the higher
quality 160, or 192. The higher the bitrate, the more disk space the resulting MP3 will
consume--but the quality will be higher. The -h option turns
on the “higher quality but a little slower” mode. The options beginning with --t indicate ID3 tags, which usually contain song information, to
be embedded within the MP3 file. Additional encoding options can be found by consulting
the lame man page.
In order to burn an audio CD from MP3s, they must be converted to a non-compressed WAV format. Both XMMS and mpg123 support the output of MP3 to an uncompressed file format.
Writing to Disk in XMMS:
Launch XMMS.
Right-click on the window to bring up the XMMS menu.
Select Preference under Options.
Change the Output Plugin to “Disk Writer Plugin”.
Press Configure.
Enter (or choose browse) a directory to write the uncompressed files to.
Load the MP3 file into XMMS as usual, with volume at 100% and EQ settings turned off.
Press Play —— XMMS will appear as if it is playing the MP3, but no music will be heard. It is actually playing the MP3 to a file.
Be sure to set the default Output Plugin back to what it was before in order to listen to MP3s again.
Writing to stdout in mpg123:
Run mpg123 -s audio01.mp3 > audio01.pcm
XMMS writes a file in the WAV format, while mpg123 converts the MP3 into raw PCM audio data. Both of these formats can be used with cdrecord to create audio CDs. You have to use raw PCM with burncd(8). If you use WAV files, you will notice a small tick sound at the beginning of each track, this sound is the header of the WAV file. You can simply remove the header of a WAV file with the utility SoX (it can be installed from the audio/sox port or package):
% sox -t wav -r 44100 -s -w -c 2 track.wav track.raw
Read Section 18.6 for more information on using a CD burner in FreeBSD.
Video playback is a very new and rapidly developing application area. Be patient. Not everything is going to work as smoothly as it did with sound.
Before you begin, you should know the model of the video card you have and the chip it uses. While Xorg and XFree86 support a wide variety of video cards, fewer give good playback performance. To obtain a list of extensions supported by the X server using your card use the command xdpyinfo(1) while X11 is running.
It is a good idea to have a short MPEG file which can be treated as a test file for evaluating various players and options. Since some DVD players will look for DVD media in /dev/dvd by default, or have this device name hardcoded in them, you might find it useful to make symbolic links to the proper devices:
# ln -sf /dev/acd0c /dev/dvd # ln -sf /dev/racd0c /dev/rdvd
On FreeBSD 5.X, which uses devfs(5) there is a slightly different set of recommended links:
# ln -sf /dev/acd0 /dev/dvd # ln -sf /dev/acd0 /dev/rdvd
Note that due to the nature of devfs(5), manually created links like these will not persist if you reboot your system. In order to create the symbolic links automatically whenever you boot your system, add the following lines to /etc/devfs.conf:
link acd0 dvd link acd0 rdvd
Additionally, DVD decryption, which requires invoking special DVD-ROM functions, requires write permission on the DVD devices.
Some of the ports discussed rely on the following kernel options to build correctly. Before attempting to build, add this option to the kernel configuration file, build a new kernel, and reboot:
options CPU_ENABLE_SSE
Note: On FreeBSD 4.X options USER_LDT should be added to the kernel configuration file. This option is not available on FreeBSD 5.X and later version.
To enhance the shared memory X11 interface, it is recommended that the values of some sysctl(8) variables should be increased:
kern.ipc.shmmax=67108864 kern.ipc.shmall=32768
There are several possible ways to display video under X11. What will really work is largely hardware dependent. Each method described below will have varying quality across different hardware. Secondly, the rendering of video in X11 is a topic receiving a lot of attention lately, and with each version of Xorg, or of XFree86, there may be significant improvement.
A list of common video interfaces:
X11: normal X11 output using shared memory.
XVideo: an extension to the X11 interface which supports video in any X11 drawable.
SDL: the Simple Directmedia Layer.
DGA: the Direct Graphics Access.
SVGAlib: low level console graphics layer.
Xorg and XFree86 4.X have an extension called XVideo (aka Xvideo, aka Xv, aka xv) which allows video to be directly displayed in drawable objects through a special acceleration. This extension provides very good quality playback even on low-end machines.
To check whether the extension is running, use xvinfo:
% xvinfo
XVideo is supported for your card if the result looks like:
X-Video Extension version 2.2
screen #0
Adaptor #0: "Savage Streams Engine"
number of ports: 1
port base: 43
operations supported: PutImage
supported visuals:
depth 16, visualID 0x22
depth 16, visualID 0x23
number of attributes: 5
"XV_COLORKEY" (range 0 to 16777215)
client settable attribute
client gettable attribute (current value is 2110)
"XV_BRIGHTNESS" (range -128 to 127)
client settable attribute
client gettable attribute (current value is 0)
"XV_CONTRAST" (range 0 to 255)
client settable attribute
client gettable attribute (current value is 128)
"XV_SATURATION" (range 0 to 255)
client settable attribute
client gettable attribute (current value is 128)
"XV_HUE" (range -180 to 180)
client settable attribute
client gettable attribute (current value is 0)
maximum XvImage size: 1024 x 1024
Number of image formats: 7
id: 0x32595559 (YUY2)
guid: 59555932-0000-0010-8000-00aa00389b71
bits per pixel: 16
number of planes: 1
type: YUV (packed)
id: 0x32315659 (YV12)
guid: 59563132-0000-0010-8000-00aa00389b71
bits per pixel: 12
number of planes: 3
type: YUV (planar)
id: 0x30323449 (I420)
guid: 49343230-0000-0010-8000-00aa00389b71
bits per pixel: 12
number of planes: 3
type: YUV (planar)
id: 0x36315652 (RV16)
guid: 52563135-0000-0000-0000-000000000000
bits per pixel: 16
number of planes: 1
type: RGB (packed)
depth: 0
red, green, blue masks: 0x1f, 0x3e0, 0x7c00
id: 0x35315652 (RV15)
guid: 52563136-0000-0000-0000-000000000000
bits per pixel: 16
number of planes: 1
type: RGB (packed)
depth: 0
red, green, blue masks: 0x1f, 0x7e0, 0xf800
id: 0x31313259 (Y211)
guid: 59323131-0000-0010-8000-00aa00389b71
bits per pixel: 6
number of planes: 3
type: YUV (packed)
id: 0x0
guid: 00000000-0000-0000-0000-000000000000
bits per pixel: 0
number of planes: 0
type: RGB (packed)
depth: 1
red, green, blue masks: 0x0, 0x0, 0x0
Also note that the formats listed (YUV2, YUV12, etc) are not present with every implementation of XVideo and their absence may hinder some players.
If the result looks like:
X-Video Extension version 2.2 screen #0 no adaptors present
Then XVideo is probably not supported for your card.
If XVideo is not supported for your card, this only means that it will be more difficult for your display to meet the computational demands of rendering video. Depending on your video card and processor, though, you might still be able to have a satisfying experience. You should probably read about ways of improving performance in the advanced reading Section 7.4.3.
The Simple Directmedia Layer, SDL, was intended to be a porting layer between Microsoft Windows, BeOS, and UNIX, allowing cross-platform applications to be developed which made efficient use of sound and graphics. The SDL layer provides a low-level abstraction to the hardware which can sometimes be more efficient than the X11 interface.
The SDL can be found at devel/sdl12.
Direct Graphics Access is an X11 extension which allows a program to bypass the X server and directly alter the framebuffer. Because it relies on a low level memory mapping to effect this sharing, programs using it must be run as root.
The DGA extension can be tested and benchmarked by dga(1). When dga is running, it changes the colors of the display whenever a key is pressed. To quit, use q.
This section discusses the software available from the FreeBSD Ports Collection which can be used for video playback. Video playback is a very active area of software development, and the capabilities of various applications are bound to diverge somewhat from the descriptions given here.
Firstly, it is important to know that many of the video applications which run on FreeBSD were developed as Linux applications. Many of these applications are still beta-quality. Some of the problems that you may encounter with video packages on FreeBSD include:
An application cannot playback a file which another application produced.
An application cannot playback a file which the application itself produced.
The same application on two different machines, rebuilt on each machine for that machine, plays back the same file differently.
A seemingly trivial filter like rescaling of the image size results in very bad artifacts from a buggy rescaling routine.
An application frequently dumps core.
Documentation is not installed with the port and can be found either on the web or under the port's work directory.
Many of these applications may also exhibit “Linux-isms”. That is, there may be issues resulting from the way some standard libraries are implemented in the Linux distributions, or some features of the Linux kernel which have been assumed by the authors of the applications. These issues are not always noticed and worked around by the port maintainers, which can lead to problems like these:
The use of /proc/cpuinfo to detect processor characteristics.
A misuse of threads which causes a program to hang upon completion instead of truly terminating.
Software not yet in the FreeBSD Ports Collection which is commonly used in conjunction with the application.
So far, these application developers have been cooperative with port maintainers to minimize the work-arounds needed for port-ing.
MPlayer is a recently developed and rapidly developing video player. The goals of the MPlayer team are speed and flexibility on Linux and other Unices. The project was started when the team founder got fed up with bad playback performance on then available players. Some would say that the graphical interface has been sacrificed for a streamlined design. However, once you get used to the command line options and the key-stroke controls, it works very well.
MPlayer resides in multimedia/mplayer. MPlayer performs a variety of hardware checks during the build process, resulting in a binary which will not be portable from one system to another. Therefore, it is important to build it from ports and not to use a binary package. Additionally, a number of options can be specified in the make command line, as described in the Makefile and at the start of the build:
# cd /usr/ports/multimedia/mplayer # make N - O - T - E Take a careful look into the Makefile in order to learn how to tune mplayer towards you personal preferences! For example, make WITH_GTK1 builds MPlayer with GTK1-GUI support. If you want to use the GUI, you can either install /usr/ports/multimedia/mplayer-skins or download official skin collections from http://www.mplayerhq.hu/homepage/dload.html
The default port options should be sufficient for most users. However, if you need the XviD codec, you have to specify the WITH_XVID option in the command line. The default DVD device can also be defined with the WITH_DVD_DEVICE option, by default /dev/acd0 will be used.
As of this writing, the MPlayer port will build its HTML documentation and two executables, mplayer, and mencoder, which is a tool for re-encoding video.
The HTML documentation for MPlayer is very informative. If the reader finds the information on video hardware and interfaces in this chapter lacking, the MPlayer documentation is a very thorough supplement. You should definitely take the time to read the MPlayer documentation if you are looking for information about video support in UNIX.