[实践OK]FreeBSD 使用手冊之Virtual Consoles 和終端機

jackxiang 2018-2-13 10:09 | |
背景:ps -ef|grep tty,出现很多tttyv进程,而有什么用呢?和Linux的不大一样,但又有点一样的,最扣只剩下一个ttyv0   "/usr/libexec/getty Pc"     xterm   on   secure,其余均给关掉,VPS服务器本来内存就少,少一个 进程少点资源占用。
一、发现现象:

二、编辑配置:/etc/ttys文件,vi /etc/ttys ,也就是ttyv0外的,tty1-->tty7都是FreeBSD/i386 (pc3.example.org) (ttyv0),也就是默认就是ttyv0,而其它虚拟终端,FreeBSD 保留了特別的按鍵組合來切換 console,得用 Alt-F1、 Alt-F2、到 Alt-F8來切換 FreeBSD 的不同 console,对于云主机来讲除开查一些登录不了(启动不了,或运程登录不上去)疑难问题外,没有啥鸟用,但有时可能还真有用。


三、关掉没有用的(云主机,虚拟终端ttv0外基本上没有用)重新启动:
重新读取/etc/ttys来强制init对/etc/ttys文件做一个必要的修改后,你必须发送一个SIGHUP信号给初始化进程来迫使它重新读取配置文件,例如:
# kill -HUP 1
注意:init总是系统运行时的第一个进程,因此它总是PID 1。

如果能够正确设置,所有的线缆都是适当的,终端将可以启用了,然后一个getty进程将在每个终端运行,你将在你的终端上看到登陆命令行。
对于终端,init会在每个配置串口上为每个拨入连接产生一个getty进程。例如,如果一个modem被附带在/dev/ttyv1中,用命令ps ax可以显示下面这些:
#ps ax|grep ttyv
2929 v0  Is+       0:00.00 /usr/libexec/getty Pc ttyv0
2930 v1  Is+       0:00.00 /usr/libexec/getty Pc ttyv1
2931 v2  Is+       0:00.00 /usr/libexec/getty Pc ttyv2
2932 v3  Is+       0:00.00 /usr/libexec/getty Pc ttyv3
2933 v4  Is+       0:00.00 /usr/libexec/getty Pc ttyv4
2934 v5  Is+       0:00.00 /usr/libexec/getty Pc ttyv5
2935 v6  Is+       0:00.00 /usr/libexec/getty Pc ttyv6
2936 v7  Is+       0:00.00 /usr/libexec/getty Pc ttyv7

实践如下,留下两个ttyv0,ttyv1,其余都off掉:
(1)ttyv2到ttyv7全部off掉,修改/etc/ttys:


(2)#kill -HUP 1  ,发送一个SIGHUP信号给初始化进程来迫使它重新读取/etc/ttys配置文件。

(3)再看就只有俩了:
#ps -ef|grep tty
2929 v0  Is+  0:00.00 TERM=xterm /usr/libexec/getty Pc ttyv0
2930 v1  Is+  0:00.00 TERM=xterm /usr/libexec/getty Pc ttyv1
四、学习资料来自:ftp://ftp.uwc.ac.za/FOSS/freebsdcvs/www/data/doc/zh_TW/books/handbook/consoles.html

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-F1、 Alt-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 中查到關於運作方式的更詳細且完整的解釋



作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/9638/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: jackxiang 编辑于2018-2-13 10:18
评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]