跳轉至內容

多座位配置/Xephyr

來自華夏公益教科書,開放的書籍,開放的世界

在這裡,我們將描述如何使用 Xephyr 建立一個 **多終端系統**。已經有很多種建立 **多終端系統**(也稱為 **多座位**)的方法,並且不斷有新的方法被開發出來。

這裡描述的方法是在 **Xephyr** 上進行修改,使其能夠用來實現多終端系統。該系統被配置為執行一個 **X** 伺服器來控制所有影片卡,並且每個螢幕執行一個 Xephyr,就像 Xnest 一樣,在主 X 伺服器之上執行。

雖然正常的 Xephyr 從其父 X 伺服器接收事件,但修改後的 Xephyr 現在能夠直接從核心事件介面讀取輸入裝置事件。

所需的作業系統

[編輯 | 編輯原始碼]

Debian Etch(但很容易移植到其他 Linux 發行版)。

Xephyr 是一個在另一個 X 伺服器中執行的 X 伺服器。Xephyr 同時是 X 客戶端和 X 伺服器。Xephyr 是真實 X 伺服器的客戶端,但也對其自己的客戶端是伺服器。Xephyr 通常用於允許同時使用兩個或多個桌面。但是,我們已經對其進行了修改,以便使用 Xephyr 來實現多終端系統。

該系統按以下方式工作。只執行一個“真實”X 伺服器,配置為使用多個螢幕,每個螢幕都與一個影片卡相關聯。X 啟動後,在每個螢幕內執行一個 Xephyr。每個使用者將以透明的方式使用一個 Xephyr。

原始的 Xephyr 從其父 X 伺服器獲取輸入裝置事件。然而,為了讓 Xephyr 能夠在多終端系統中使用,我們必須修改其原始碼,使其能夠直接從核心事件介面讀取事件,繞過 X。為了讀取滑鼠和鍵盤事件,使用了 evdev 協議。

這種方法的巨大優勢在於能夠使用任意組合的影片卡來建立多終端系統,只要這些影片卡得到 X 的支援。除此之外,Xephyr 比 Xnest 有幾個優勢:Xephyr 正在維護中,比 Xnest 更快,並且更容易支援 X 擴充套件的實現。

安裝 XOrg

[編輯 | 編輯原始碼]

以下是在使用 XOrg X 伺服器配置多終端系統的步驟,儘管可以進行少量修改來使用 XFree86。為了使用 XOrg,您應該使用 Debian Etch 或更高版本,因為 Debian Sarge 沒有 XOrg,只有 XFree86。如果您使用的是 Debian Sarge,請按照這些說明將其升級到 Etch。

注意:對於大多數步驟,您需要成為系統根使用者。為此,請使用命令“su”,然後輸入根使用者密碼。

1. 將檔案 /etc/apt/sources.list 中出現的“sarge”或“stable”改為“etch”,例如:

deb http://ftp.debian.org/debian sarge main contrib non-free

應該變成:

deb http://ftp.debian.org/debian etch main contrib non-free

2. 更新系統並安裝 xserver-xorg 包:

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

Evdev 和 Udev

[編輯 | 編輯原始碼]

確保您的核心已編譯了 evdev 支援。此外,安裝 udev,它提供了一個動態的 /dev 目錄,根據連線的裝置進行更新。

apt-get install udev

Udev 需要核心 2.6 或更高版本。

輸入裝置

[編輯 | 編輯原始碼]

現在,您需要檢查您的輸入裝置(滑鼠和鍵盤)是否已被核心正確檢測到。為此,請分析檔案 /proc/bus/input/devices,該檔案顯示有關核心檢測到的輸入裝置的詳細資訊。使用以下命令在終端中檢視此檔案的內容:

$ cat /proc/bus/input/devices 

下面是一個示例檔案。只有兩個欄位很重要:每個裝置的名稱,顯示在以“N: Name=”開頭的行中,以及與每個裝置相關的檔案的名稱,顯示在以“H: Handlers=”開頭的行中。

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
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
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
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

請注意,該檔案似乎表明存在 3 個鍵盤,儘管實際系統中只有兩個鍵盤。這是因為許多 USB 鍵盤都有特殊的按鍵(用於控制多媒體或訪問網際網路,例如),核心會將這些按鍵檢測為輔助鍵盤,其物理地址以“input1”結尾。您只需要配置主鍵盤,其物理地址以“input0”結尾。因此,將忽略與輔助鍵盤的物理地址“usb-0000:00:10.2-1/input1”相對應的部分。

給出的示例顯示了 2 個“主”鍵盤,分別與檔案 /dev/input/event0 和 /dev/input/event2 相關聯,以及 2 個滑鼠,分別與檔案 /dev/input/event1 和 /dev/input/event4 相關聯。這些檔案很重要,因為它們用於將多終端系統的每個頭與正確的輸入裝置相關聯。

將以下行新增到檔案 /etc/ld.so.conf 中:(在 Ubuntu 8.04 中不需要)

/usr/local/lib

之後,執行 ldconfig:

ldconfig

修改後的 Xephyr 下載

[編輯 | 編輯原始碼]
  1. 這裡 下載 Xephyr 二進位制檔案。解壓縮到目錄 /usr/local。您可以單擊 這裡 (Xorg 7.2 的較新版本,Xorg 7.3 已經包含了所需的補丁[1]) 檢視補丁,但只有在使用者要編譯時才需要補丁。
  2. 下載執行 Xephyr 所需的包裝器指令碼:Xephyr.sh。該指令碼必須複製到 /usr/sbin 並具有可執行許可權。要授予檔案可執行許可權,請執行以下命令:
chmod +x /usr/sbin/Xephyr.sh

對於 Ubuntu 8.04,以下命令將安裝並更新 Xephyr 二進位制檔案:

# apt-get install xserver-xephyr

X(XOrg) 配置

[編輯 | 編輯原始碼]

要配置一個具有 N 個終端的多終端系統,請編輯檔案 /etc/X11/xorg.conf,並執行以下操作:

1. 定義具有 N 個螢幕的佈局。

Section "ServerLayout"
	Identifier	"Layout"
	Screen		"Screen 1"
	Screen		"Screen 2"	Below	"Screen 1"
	Screen		"Screen 3"	Below	"Screen 2"
	.
	.
	Screen		"Screen N"	Below	"Screen N-1"
	InputDevice	"Generic Keyboard 1"
EndSection

2. 為每個影片卡定義一個 Device Section。

Section "Device"
	Identifier	"Video Card 1"
	Driver		"sis"	
	BusID		"PCI:0:5:0"	
	Screen		0	
EndSection
	#
	# Change the video card driver and the BusID according to your hardware.
	#
	# The BusID option identifies your video card. To obtain the BusIDs of your video cards,
	#use the command "lspci | grep VGA".
	# Beware: the lspci command shows address in hexadecimal, while X expects decimal numbers.
	#The command "echo $((0xHEX_NUMBER))" is your friend.
	.
	.
	.
Section "Device"
	Identifier	"Video Card N"
	Driver		"sis"
	BusID		"PCI:0:6:0"
	Screen		0	
EndSection

3. 定義 Monitor Sections。

Section "Monitor"
	Identifier	"Monitor 1"
	HorizSync	30-71
	VertRefresh	50-160
	Option		"DPMS"
EndSection			
	.
	.
	.		
Section "Monitor"
	Identifier	"Monitor N"
	HorizSync	30-71
	VertRefresh	50-160
	Option		"DPMS"
EndSection

4. 定義 Screen Sections。

Section "Screen"
	Identifier	"Screen 1"
	Device		"Video Card 1"
	Monitor		"Monitor 1"
	DefaultDepth	24	
	SubSection "Display"
		Depth		24
		Modes		"1024x768" "800x600" "640x480"
	EndSubSection
EndSection
	.
	.
	.
Section "Screen"
	Identifier	"Screen N"
	Device		"Video Card N"
	Monitor		"Monitor N"
	DefaultDepth	24	
	SubSection "Display"
		Depth		24
		Modes		"1024x768" "800x600" "640x480"
	EndSubSection
EndSection

5. 鍵盤定義可以與 xorg.conf 中已經存在的定義相同,但是請確認 Identifier 與佈局部分中定義的 Identifier 相同(“Generic Keyboard”)。這對於讓滑鼠指向裝置 /dev/input/mice 是必要的。

Section "InputDevice"
        Identifier      "Configured Mouse 1"
        Driver          "mouse"
        Option          "CorePointer"
        Option          "Device"                "/dev/input/mice"
        Option          "Protocol"              "ImPS/2"
EndSection

6. Xorg.conf 應該只有一個鍵盤部分,如下所示:

Section "InputDevice"
    Identifier  "Generic Keyboard 1"
    Driver      "kbd"
EndSection

7. 為了避免因滑鼠無法識別而導致 X 伺服器初始化出現問題,您可以毫無問題地包含以下部分

Section "ServerFlags"
	Option "AllowMouseOpenFail"	"yes"
EndSection

Ps:這不會影響多終端,因為鍵盤/滑鼠裝置將作為引數傳遞給 Xephyr。

8. 最後,要停用 VT 更改和 Ctrl+Alt+Backspace 鍵,請驗證「ServerFlags」部分是否包含以下選項

Section "ServerFlags"
       ...
	# Disable VT Switching
	Option    "DontVTSwitch" "yes"
	
	# This disallows the use of the Ctrl+Alt+Backspace sequence
	Option    "DontZap"       "yes"
       ...
EndSection

佈局配置

[編輯 | 編輯原始碼]

使用指令碼

[編輯 | 編輯原始碼]

由於核心進行的輸入裝置檢測(滑鼠、鍵盤)(請參閱“輸入裝置”部分)並不總是遵循相同的順序,因此核心可能會在每次初始化時將相同的裝置與不同的檔案關聯,這可能會“打亂”鍵盤和滑鼠。

為了避免這個問題,我們製作了指令碼來自動執行滑鼠和鍵盤與其相應顯示器的關聯過程。您只需要配置一次佈局(哪個鍵盤和滑鼠與哪個顯示器關聯),指令碼就會將此“佈局”保留在檔案 /etc/X11/devices.conf 中。要使用指令碼,請執行以下步驟

1. 安裝 xdialog 包

apt-get install xdialog

2. 將檔案 xkb-evdev.tar.gz 解壓縮到目錄 /etc/X11。

3. 刪除或重新命名檔案 /etc/gdm/gdm.conf

mv /etc/gdm/gdm.conf /etc/gdm/gdm.conf.backup

[2007 年 11 月 4 日編輯] 也許應該將修改編輯到 /etc/gdm/gdm.conf-custom 檔案中,這樣就不會被更新覆蓋。


4. 解壓縮檔案 public.tgz 並將檔案“configura_layout”和“select.out”複製到目錄“/usr/local/sbin”。然後將檔案“configuracao_automatica”複製到目錄“/etc/init.d”。

5. 配置 configuracao_automatica 以在系統初始化時執行

update-rc.d configuracao_automatica start 70 S .

6. 執行以下命令以配置系統佈局。指令碼將詢問每個顯示器的相關問題,以確定哪個鍵盤和滑鼠與哪個顯示器關聯。

PS:在執行此操作之前,您必須停止“gdm”。以 root 身份登入並輸入“/etc/init.d/gdm stop”。

invoke-rc.d configuracao_automatica start

如果檔案不存在,指令碼將自動生成檔案 /etc/gdm/gdm.conf,以及 XKB 配置檔案(/usr/X11R6/lib/X11/xkb/XX-config.keyboard)。指令碼將在 /dev/input 目錄中建立連結,分別命名為 kbd0mt、kbd1mt 等,分別指向第一個終端的鍵盤、第二個終端的鍵盤等。指令碼還將建立名為 mouse0mt、mouse1mt 等的連結,分別指向第一個終端的滑鼠、第二個終端的滑鼠等。

回答完問題後,指令碼將生成 /etc/X11/devices.conf 檔案,其中包含每個終端的滑鼠和鍵盤關聯,以及鍵盤配置(規則、模型、佈局)。

另一種獲得物理輸入裝置與事件編號之間正確匹配的方法是修改 Xephyr 包裝指令碼。包裝指令碼已修改以從物理裝置地址獲取事件 ID。您可以在此處檢視修改後的指令碼:[1]

手動配置

[編輯 | 編輯原始碼]

如果您使用的是“使用指令碼”部分中的指令碼,請不要執行以下步驟。但是,閱讀本節將有助於您瞭解指令碼的工作原理。

XKB 配置

[編輯 | 編輯原始碼]

為了允許 Xephyr 使用 XKB 擴充套件,您應該將檔案 xkb-evdev.tar.gz 解壓縮到目錄 /etc/X11。之後,需要為每個 Xephyr 建立一個 XKB 配置檔案。第一個 Xephyr 的 XKB 配置應放置在檔案 /usr/X11R6/lib/X11/xkb/X1-config.keyboard 中,第二個 Xephyr 的 XKB 配置應放置在 /usr/X11R6/lib/X11/xkb/X2-config.keyboard 中,依此類推。您可以在下面看到一個 XKB 配置檔案示例。

rules = "evdev"
model = "pc105"
layout = "us"

GDM 配置

[編輯 | 編輯原始碼]

最後一步是配置登入管理器以啟動主 X 伺服器,並執行將開啟 Xephyr 的包裝指令碼。我們將解釋如何在 GDM 上執行此操作,但其他管理器(如 XDM 和 KDM)也可以透過類似的方式進行配置。

編輯檔案 /etc/X11/gdm.conf 中的 servers 部分,新增以下內容

[servers]
0=Hardware
# Hardware is the main X server

1=Xephyr1
2=Xephyr2
3=Xephyr3
.
.
N=XephyrN
# Xephyr{1..N} is each one of the Xephyr servers

[server-Hardware]
name=Hardware
command=/usr/X11R6/bin/X
handled=false	
flexible=false
# The handled=false option hinders the login manager to be loaded on the main X server.

[server-Xephyr1]
name=Xephyr1
command=/usr/sbin/Xephyr.sh -display :0.0 -xauthority /var/lib/gdm/:0.Xauth -geometry 1024x768+0+0
-keyboard /dev/input/event0 -mouse /dev/input/event1,5 -use-evdev -dpi 92
handled=true
flexible=false
#
# The options -keyboard and -mouse identify, respectively, to which keyboard and mouse Xephyr will be associated, 
#as seen in the file /proc/bus/input/devices. If the mouse option finishes with ",5", as in
#the example, the mouse wheel will be activated.
#
# Xephyr.sh is the wrapper that runs Xephyr server.
.
.
.
[server-XephyrN]
name=XephyrN
command=/usr/sbin/Xephyr.sh -display :0.(N-1) -xauthority /var/lib/gdm/:0.Xauth -geometry 1024x768+0+0
-keyboard /dev/input/eventXX -mouse /dev/input/eventYY[,5] -use-evdev -dpi 92
handled=true
flexible=false

參考資料

[編輯 | 編輯原始碼]
  1. 使用 Ubuntu 8.04 的多座計算機
華夏公益教科書