3.2 Virtual Consoles 和終端機

有很多方法可以操作 FreeBSD ,其中一種就是在文字終端機上打字。 如此使用 FreeBSD 即可輕易的體會到 UNIX® 作業系統的威力和彈性。 這一節描述什麼是“終端機”和“console”,及以您在 FreeBSD 中可以怎麼使用它們。

3.2.1 The Console

如果您沒有將 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。

3.2.2 登入 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 了。

3.2.3 多重 Console

在一個 Console 下執行 UNIX 當然是沒有問題,然而FreeBSD是可以同時執行很多程式的。 像 FreeBSD 這樣可以同時執行一大堆程式的作業系統,只有一個 console 可以輸入指令是有點浪費。 在此“virtual consoles”就很有用了。

FreeBSD 可以被設定成同時有很多 virtual console ,用幾個按鍵的組合就可以從一個 virtual console 跳到別的 virtual console 去。 每一個 console 都有自已不同的輸出頻道, 當從某一個 virtual console 切換到下一個的時候,FreeBSD 會適當的處理鍵盤輸入及螢幕輸出。

FreeBSD 保留了特別的按鍵組合來切換 console [3]。 您可以用 Alt-F1Alt-F2、到 Alt-F8來切換 FreeBSD 的不同 console。

當您從一個 console 切換到下一個的時候, FreeBSD 會處理螢幕輸出的儲存及回復。 這就“好像”有很多“虛擬”的螢幕和鍵盤可以讓您輸入指令給 FreeBSD 執行。 在某一個 console 上執行的程式並不會因為切到別的 console 而停止執行,當您切換到另一個 console 的時候,他們會繼續執行。

3.2.4 The /etc/ttys File

The default configuration of FreeBSD will start up with eight virtual consoles. This is not a hardwired setting though, and you can easily customize your installation to boot with more or fewer virtual consoles. The number and settings of the virtual consoles are configured in the /etc/ttys file.

You can use the /etc/ttys file to configure the virtual consoles of FreeBSD. Each uncommented line in this file (lines that do not start with a # character) contains settings for a single terminal or virtual console. The default version of this file that ships with FreeBSD configures nine virtual consoles, and enables eight of them. They are the lines that start with ttyv:

# name  getty                           type    status          comments
#
ttyv0   "/usr/libexec/getty Pc"         cons25  on  secure
# Virtual terminals
ttyv1   "/usr/libexec/getty Pc"         cons25  on  secure
ttyv2   "/usr/libexec/getty Pc"         cons25  on  secure
ttyv3   "/usr/libexec/getty Pc"         cons25  on  secure
ttyv4   "/usr/libexec/getty Pc"         cons25  on  secure
ttyv5   "/usr/libexec/getty Pc"         cons25  on  secure
ttyv6   "/usr/libexec/getty Pc"         cons25  on  secure
ttyv7   "/usr/libexec/getty Pc"         cons25  on  secure
ttyv8   "/usr/X11R6/bin/xdm -nodaemon"  xterm   off secure

For a detailed description of every column in this file and all the options you can use to set things up for the virtual consoles, consult the ttys(5) manual page.

3.2.5 Single User Mode Console

A detailed description of what “single user mode” is can be found in Section 12.6.2. It is worth noting that there is only one console when you are running FreeBSD in single user mode. There are no virtual consoles available. The settings of the single user mode console can also be found in the /etc/ttys file. Look for the line that starts with console:

# 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: As the comments above the console line indicate, you can edit this line and change secure to insecure. If you do that, when FreeBSD boots into single user mode, it will still ask for the root password.

Be careful when changing this to insecure. If you ever forget the root password, booting into single user mode is a bit involved. It is still possible, but it might be a bit hard for someone who is not very comfortable with the FreeBSD booting process and the programs involved.

Notes

[1]

這就是 i386 的意義。 注意即使您不是在 Intel 的 386 處理器上執行 FreeBSD ,一樣是i386。 這不是指你的處理器的型號,這裡顯示的是你處理器的“架構”

[2]

這些起動的 script 是在開機的時候 FreeBSD 會自動執行的程式。 他們主要的功能是將所有該執行的東西設定好,並將您設定成背景執行的服務啟動。

[3]

syscons(4)atkbd(4)vidcontrol(1)、以及 kbdcontrol(1)等 manual page 中,對於 FreeBSD 的 console 及鍵盤驅動程式有十分技術性且詳細的描述。 我們在這裡不討論細節,有興趣的讀者隨時可以在 manual page 中查到關於運作方式的更詳細且完整的解釋

This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.

For questions about FreeBSD, read the documentation before contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.