跳轉到內容

多座配置/faketty

來自華夏公益教科書

本文介紹了 **使用 Faketty 的多終端** 的工作原理以及如何實現。它使用 Aivils Stoss 開發的 faketty 模組,並且不使用 evdev 協議或核心補丁。它是建立 多終端 的最著名方法之一。

本文介紹了使用 faketty 模組配置多終端系統所需的步驟。faketty 是由 Aivils Stoss 開發的核心模組,它將系統鍵盤與名為 /dev/fttyXX 的裝置檔案關聯起來(其中 XX 是一個標識鍵盤的數字),X 使用這些檔案讀取鍵盤事件。該模組使用 X 通常用於從鍵盤讀取事件的相同協議,即 TTY 協議,它省略了 evdev 的使用。這種方法的另一個優點是不需要對核心進行任何修補。

缺點是,這種解決方案需要編譯一個核心模組,而且這種方法只在少數顯示卡組合中執行良好(穩定)。

作業系統

[編輯 | 編輯原始碼]

Debian Sarge(您也可以使用其他 GNU/Linux 發行版,只需進行少量更改)

使用的硬體

[編輯 | 編輯原始碼]

顯示卡

  • 4 塊 SiS 315 顯示卡(也可以是其他卡,但並非所有卡都受支援)。

鍵盤和滑鼠

  • 1 個 PS/2 鍵盤
  • 1 個 PS/2 滑鼠
  • 3 個 USB 鍵盤
  • 3 個 USB 滑鼠

Udev 安裝

[編輯 | 編輯原始碼]

有必要安裝 udev,它根據連線的裝置提供動態更新的目錄 /dev。

apt-get install udev

udev 需要核心 2.6.12 或更高版本。

編譯和載入 faketty 模組

[編輯 | 編輯原始碼]

確認您已安裝核心(正在使用)的標頭。如果您使用的是 Debian,請執行以下命令

apt-get install linux-headers-$(uname -r)

下一步是為您的核心編譯 faketty 模組。您可以在此處找到模組原始碼: http://www.ltn.lv/~aivils/files/faketty-0.05.tar.bz2

(注意:faketty 的新版本可從 http://www.ltn.lv/~aivils/files/faketty-0.06.tar.bz2 獲得,如果您在使用舊版本時遇到任何問題,請嘗試使用它)最近是這個版本 http://www.ltn.lv/~aivils/files/faketty-2.6.30.tar.bz2。適合核心 > 2.6.23

解壓縮檔案,並在包含 "Makefile" 檔案的目錄中執行以下命令來編譯和安裝模組

make && make install

要載入核心模組,請執行以下命令

modprobe faketty
[編輯 | 編輯原始碼]

有必要檢查 /proc/bus/input/devices 檔案,以瞭解每個鍵盤與哪個 ffty 檔案關聯。下面顯示了 /proc/bus/input/devices 檔案的示例

I: Bus=0011 Vendor=0001 Product=0001 Version=ab41
N: Name="AT Translated Set 2 keyboard"
P: Phys=isa0060/serio0/input0
H: Handlers=kbd event0 ftty1
B: EV=120013
B: KEY=4 2000000 3802078 f840d001 f2ffffdf ffefffff ffffffff fffffffe
B: MSC=10
B: LED=7

I: Bus=0011 Vendor=0002 Product=0005 Version=0000
N: Name="ImPS/2 Generic Wheel Mouse"
P: Phys=isa0060/serio1/input0
H: Handlers=mouse0 event1
B: EV=7
B: KEY=70000 0 0 0 0 0 0 0 0
B: REL=103

I: Bus=0003 Vendor=0a81 Product=0101 Version=0110
N: Name="CHESEN USB Keyboard"
P: Phys=usb-0000:00:10.2-1/input0
H: Handlers=kbd event2 ftty2
B: EV=120003
B: KEY=10000 7 ff87207a c14057ff febeffdf ffefffff ffffffff fffffffe
B: LED=7

I: Bus=0003 Vendor=0a81 Product=0101 Version=0110
N: Name="CHESEN USB Keyboard"
P: Phys=usb-0000:00:10.2-1/input1
H: Handlers=kbd event3 ftty3
B: EV=3
B: KEY=1f 0 20000 3878 d801d101 1e0000 0 0 0

I: Bus=0003 Vendor=04fc Product=0013 Version=06b0
N: Name="USB OpticalWheel Mouse"
P: Phys=usb-0000:00:10.2-2/input0
H: Handlers=mouse1 event4
B: EV=7
B: KEY=70000 0 0 0 0 0 0 0 0
B: REL=103

您可以注意到顯示了三個鍵盤,其中第一個與 /dev/ftty1 檔案關聯,第二個與 /dev/ftty2 檔案關聯。與 input0 不同,其 "P: Phys" 屬性以 input1 結尾的鍵盤(如該檔案的第三個鍵盤),應該重新考慮,因為它指的是某些鍵盤的特殊鍵和特殊功能。

您還可以看到示例檔案中存在兩個滑鼠,它們分別與 /dev/input/mouse0 和 /dev/input/mouse1 關聯。

X 在初始化時,會開啟 /dev/ttyXX 檔案來讀取鍵盤事件,其中 XX 是 X 作為引數接收的 VT(虛擬終端)編號。由於無法請求 X 開啟其他檔案,因此有必要將 /dev/ttyXX 檔案連結到 /proc/bus/input/devices 檔案中指示的 ftty 檔案。在下面的示例中,我們建立了 4 個連結,每個鍵盤一個,從 /dev/tty50 檔案開始。

rm -f /dev/tty5[0-3]
ln -s /dev/ftty1 /dev/tty50
ln -s /dev/ftty2 /dev/tty51
ln -s /dev/ftty3 /dev/tty52
ln -s /dev/ftty4 /dev/tty53

驅動程式安裝到 SiS 顯示卡

[編輯 | 編輯原始碼]

1. 將以下行新增到 /etc/apt/sources.list 檔案中

deb http://www.winischhofer.net/sis/debian/stable ./

2. 更新系統軟體包資訊並安裝 x-driver-sis 驅動程式

apt-get update
apt-get install x-driver-sis

熱插拔

[編輯 | 編輯原始碼]

安裝 hotplug 軟體包

apt-get update
apt-get install hotplug

XOrg 伺服器安裝

[編輯 | 編輯原始碼]

下一步是安裝 XOrg 伺服器。

1. 對 /etc/init.d/xfree-common 檔案進行備份並刪除它。2. 將以下行新增到 /etc/apt/sources.list 檔案中

deb http://people.debian.org/~nobse/xorg-x11/ sarge main
deb-src http://people.debian.org/~nobse/xorg-x11/ sarge main

3. 安裝 xserver-xorg 軟體包

apt-get update
apt-get install xserver-xorg
apt-get upgrade

XOrg 伺服器配置

[編輯 | 編輯原始碼]

xorg.conf

[編輯 | 編輯原始碼]

此配置將在多終端執行期間使用。在此檔案中,將根據我們配置的終端數量建立額外的節。對於每個終端,我們將為滑鼠、鍵盤、顯示卡、顯示器、螢幕和佈局建立節。例如,在具有四個終端的多終端的情況下,該檔案將具有四個滑鼠節、四個鍵盤節,以及依此類推。

每個節中建議的“識別符號”值並非強制性。它們可以修改,只要保持所有配置中名稱的一致性即可。

每個裝置的物理地址(選項“Dev Phys”)可以從 /proc/bus/input/devices 檔案中獲得,如前所述。

以下是每種型別的部分的示例。

Section "InputDevice"
        Identifier      "Generic Keyboard 0"
        Driver          "keyboard"

        # The options below are adjusted to a brazilian keyboard
        # with cedilha (ABNT2).
        Option          "XkbRules"      "xorg"
        Option          "XkbModel"      "abnt2"
        Option          "XkbLayout"     "br"
        Option          "XkbVariant"    "abnt2"
        Option          "XkbOptions"    "abnt2"
        Option          "CoreKeyboard"
EndSection


Section "InputDevice"
        Identifier      "Configured Mouse 0"
        Driver          "mouse"

        # Substitute the value of "Device" option by the correspondent
        # mouse file, obtained from /proc/bus/input/devices file        
        Option          "Protocol"      "ImPS/2"
        Option          "Device"      "/dev/input/mouse0"

        # All mouses should have the "CorePointer" option
        Option          "CorePointer"
        Option          "ZAxisMapping"          "4 5"
EndSection


Section "Device"
        Identifier      "Placa de Vídeo Genérica 0"
        Driver          "sis"
        Screen          0

        # It's mandatory to explicit the BusID of all cards. 
        # To obtain it, use "lspci | grep VGA". Be carefull with the values,
        # while the address supplied by lspci is in hexadecimal base
        # the XOrg wait a decimal value.  To convert this, use
        # "echo $((0xHEXADECIMAL_VALUE))".
        BusID           "PCI:1:0:0"

        # This option disables the VGA and VBE calls of IRQ 10, to 
        # prevent that some card intervenes with others.  See also the
        # "xorg.conf.probe" file.
        Option          "NoInt10"       "Yes"

        # This option to sis video cards, prevents problems during alternating between
        # virtual terminals or while exiting X server.
        Option          "RestoreBySetMode"      "no"

EndSection


# The values below are default.  Maintain the configuration that you normally would use
# to your monitors.
Section "Monitor"
        Identifier      "Monitor Genérico 0"
        HorizSync       30-60
        VertRefresh     50-75
        Option          "DPMS"
EndSection


# The screen configuration below also is illustrative, personalize it
# in accordance with your preferences.
Section "Screen"
        Identifier      "Default Screen 0"
        Device          "Placa de Vídeo Genérica 0"
        Monitor         "Monitor Genérico 0"
        DefaultDepth    24
        SubSection "Display"
        Depth           24
                Modes           "1024x768" "800x600" "640x480"
        EndSubSection
EndSection


Section "ServerLayout"
        # The Identifier will be used at the call in command line.
        Identifier      "Layout0"
        Screen          "Default Screen 0"
        InputDevice     "Generic Keyboard 0"
        InputDevice     "Configured Mouse 0"

        Option          "SingleCard"
EndSection

xorg.conf.probe

[編輯 | 編輯原始碼]

除了 xorg.conf 預設檔案之外,還需要建立一個第二個配置檔案,即 xorg.conf.probe。在使用多終端時,我們將停用 10 通道(IRQ 10)上的中斷,以防止一張卡的 VGA 呼叫(和 VESA VBE)干擾其他卡。但是,停用這些呼叫後,輔助卡將無法初始化。為了解決這個問題,在系統初始化過程中,XOrg 將使用 xorg.conf.probe 檔案執行。它將對這些卡的存在進行檢查(探測),在測試期間啟用 IRQ 10,從而初始化它們。

要建立 xorg.conf.probe,請將 xorg.conf 作為基礎,刪除與主顯示卡相關的部分(在啟動計算機時由 BIOS 初始化),並將 NoInt10 選項更改為“No”。只需要一個佈局,但要包括所有輔助卡。例如,請檢視上面從 xorg.conf 派生的 xorg.conf.probe 檔案的一些片段。

# At all Device sections (of video cards), change the option
# NoInt10 to:
        Option          "NoInt10"               "no"

# Declare only one layout, and without to use the "SingleCard" option.
# All the secondary screens should be included. The
# screens disposal (LeftOf, etc.) isn't important, so little
# the input devices used.
Section "ServerLayout"
        Identifier      "probe"
        Screen          "Default Screen 1"
        Screen          "Default Screen 2"   LeftOf  "Default Screen 1"
        Screen          "Default Screen 3"   LeftOf  "Default Screen 2"
        InputDevice     "Generic Keyboard 1"
        InputDevice     "Configured Mouse 1"
EndSection

為了執行測試(探測),提供了 xorg-multiterminal 檔案。它以探測模式(僅測試裝置並結束)執行 X 伺服器,使用 xorg.conf.probe 檔案。如上所述,此步驟會初始化輔助顯示卡。該檔案的內容是

file=/etc/X11/xorg.conf.probe

[[ -f "file" ]] && /usr/X11R6/bin/X -config "$file" -probeonly 2>/dev/null

將其儲存為可執行指令碼,並配置初始化系統以執行它。在 Debian 的情況下,補丁應該是 /etc/init.d/xorg-multiterminal,並且存在兩種配置系統的方式

  • 透過 update-rc.d 命令。此命令適用於使用系統標準 Debian(sysv-rc)的使用者以及使用 file-rc 軟體包的使用者。
update-rc.d xorg-multiterminal start 70 S .
  • 手動

在使用標準初始化方案的 Debian 系統中,建立一個連結

ln -s /etc/init.d/xorg-multiterminal /etc/rcS.d/S70xorg-multiterminal

在安裝了 file-rc 軟體包的 Debian 系統中,在 /etc/init.d/runlevel.conf 檔案中的適當位置新增以下行

70        -        S        /etc/init.d/xorg-multiterminal

最後一步是配置登入管理器以初始化所有 X 伺服器。我們將只處理 GDM。其他管理器,如 XDM 和 KDM,可以透過類似的過程進行配置。

需要編輯 /etc/gdm/gdm.conf 檔案的“[servers]”部分,使其包含多個輸入,例如以下示例中的四個終端

[servers]
0=XServer0
1=XServer1
2=XServer2
3=XServer3

伺服器名稱是任意的,但需要為每個伺服器新增一個部分,其中包含以下內容

[server-XServer0]
name=Standard server
command=/usr/X11R6/bin/X -br -audit 0 -layout Layout0 :0 vt50
flexible=true

[server-XServer1]
name=Standard server
mmand=/usr/X11R6/bin/X -br -audit 0 -layout Layout1 :1 vt51
flexible=true

[server-XServer2]
name=Standard server
mmand=/usr/X11R6/bin/X -br -audit 0 -layout Layout2 :2 vt52
flexible=true

[server-XServer3]
name=Standard server
mmand=/usr/X11R6/bin/X -br -audit 0 -layout Layout3 :3 vt53
flexible=true

請注意,四個伺服器分別使用 50、51、52 和 53 VT。因此,X 伺服器將使用 /dev/tty50、/dev/tty51、/dev/tty52 和 /dev/tty53 檔案來讀取鍵盤事件,這些檔案實際上是到 /dev/fttyXX 檔案的連結,正如我們之前建立的那樣。

解決問題

[編輯 | 編輯原始碼]

可以在 /var/log/Xorg.*.log 檔案中分析多終端初始化中的問題。每個終端的 X 伺服器將建立其自己的日誌檔案。

[編輯 | 編輯原始碼]
華夏公益教科書