X Sever —— Xorg

Xorg:基于X11协议的服务端。管理硬件设备(驱动),键盘鼠标显示器等

Xorg配置文件

生成配置文件

1
# Xorg -configure :0

:0显示窗口,在Xorg启动的情况下,无法获取当前的Xorg配置文件,可以随意指定数字

多显示器

multiple X screens on a single X display (:0.0 and :0.1, where the notation is :.

xorg.conf

具体参数说明:man xorg.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
Section "ServerLayout"
Identifier "X.org Configured"
Screen 0 "Screen0" 0 0
Screen 1 "Screen1" RightOf "Screen0"
InputDevice "Mouse0" "CorePointer"
InputDevice "Keyboard0" "CoreKeyboard"
EndSection

Section "Files"
ModulePath "/usr/lib/xorg/modules"
FontPath "/usr/share/fonts/X11/misc"
FontPath "/usr/share/fonts/X11/cyrillic"
FontPath "/usr/share/fonts/X11/100dpi/:unscaled"
FontPath "/usr/share/fonts/X11/75dpi/:unscaled"
FontPath "/usr/share/fonts/X11/Type1"
FontPath "/usr/share/fonts/X11/100dpi"
FontPath "/usr/share/fonts/X11/75dpi"
FontPath "built-ins"
EndSection

Section "Module"
Load "glx"
EndSection

Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
EndSection

Section "InputDevice"
Identifier "Mouse0"
Driver "mouse"
Option "Protocol" "auto"
Option "Device" "/dev/input/mice"
Option "ZAxisMapping" "4 5 6 7"
EndSection

Section "Monitor"
Identifier "Monitor0"
VendorName "Monitor Vendor"
ModelName "Monitor Model"
EndSection

Section "Monitor"
Identifier "Monitor1"
VendorName "Monitor Vendor"
ModelName "Monitor Model"
EndSection

Section "Device"
### Available Driver options are:-
### Values: <i>: integer, <f>: float, <bool>: "True"/"False",
### <string>: "String", <freq>: "<f> Hz/kHz/MHz",
### <percent>: "<f>%"
### [arg]: arg optional
#Option "Accel" # [<bool>]
#Option "SWcursor" # [<bool>]
#Option "EnablePageFlip" # [<bool>]
#Option "SubPixelOrder" # [<str>]
#Option "ZaphodHeads" # <str>
#Option "AccelMethod" # <str>
#Option "DRI3" # [<bool>]
#Option "DRI" # <i>
#Option "ShadowPrimary" # [<bool>]
#Option "TearFree" # [<bool>]
#Option "DeleteUnusedDP12Displays" # [<bool>]
Identifier "Card0"
Driver "amdgpu"
BusID "PCI:1:0:0"
EndSection

Section "Device"
### Available Driver options are:-
### Values: <i>: integer, <f>: float, <bool>: "True"/"False",
### <string>: "String", <freq>: "<f> Hz/kHz/MHz",
### <percent>: "<f>%"
### [arg]: arg optional
#Option "Accel" # [<bool>]
#Option "SWcursor" # [<bool>]
#Option "EnablePageFlip" # [<bool>]
#Option "SubPixelOrder" # [<str>]
#Option "ZaphodHeads" # <str>
#Option "AccelMethod" # <str>
#Option "DRI3" # [<bool>]
#Option "DRI" # <i>
#Option "ShadowPrimary" # [<bool>]
#Option "TearFree" # [<bool>]
#Option "DeleteUnusedDP12Displays" # [<bool>]
Identifier "Card1"
Driver "amdgpu"
BusID "PCI:1:0:1"
EndSection

Section "Screen"
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
SubSection "Display"
Viewport 0 0
Depth 1
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 4
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 8
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 15
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 16
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 24
EndSubSection
EndSection

Section "Screen"
Identifier "Screen1"
Device "Card1"
Monitor "Monitor1"
SubSection "Display"
Viewport 0 0
Depth 1
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 4
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 8
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 15
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 16
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 24
EndSubSection
EndSection

注意:在xorg.conf中配置显卡总线地址BusID时,必须以十进制表示,比如lspci总线地址(以十六进制显示)为91:00.0,将其转换为十进制145:00:0(16x9+1)配置在xorg.conf中。
细节有两点:

  1. 总线地址的进制转换(十六进制转十进制)
  2. 总线地址的分隔符,在xorg.conf中,地址均为:分隔
  • Driver的选择必须根据使用的显卡和系统的支持情况配置,在系统不支持的情况下可以使用modesetting代替测试,不一定配置成功
    • centos系统支持的驱动在/lib64/xorg/modules/drivers/
      1
      2
      # ls /lib64/xorg/modules/drivers/
      ati_drv.so dummy_drv.so fbdev_drv.so modesetting_drv.so nouveau_drv.so qxl_drv.so radeon_drv.so v4l_drv.so
    • ubuntu系统支持的驱动在/usr/lib/xorg/modules/drivers/
      1
      2
      ls /usr/lib/xorg/modules/drivers/
      amdgpu_drv.so ati_drv.so fbdev_drv.so intel_drv.so modesetting_drv.so nouveau_drv.so qxl_drv.so radeon_drv.so vesa_drv.so vmware_drv.so

在用户空间驱动不在系统默认路径下时,可以通过Section "Files"ModulePath参数指定

1
2
3
Section "Files"
ModulePath "/usr/local/lib/xorg/modules/"
EndSection

参数

1
2
3
4
5
6
7
8
9
10
11
$man Xorg
$man xorg.conf
$man Xserver
$man modesetting
$man fbdevhw
$man Xwrapper.config

$man Xephyr
$man exa
$man cvt
$man gtf
  • Xephyr: X服务器输出到预先存在的X显示器上的窗口

应用示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# nvidia-settings: X configuration file generated by nvidia-settings
# nvidia-settings: version 440.82

Section "ServerLayout"
Identifier "Layout0"
Screen 0 "Screen0" 0 0
InputDevice "Keyboard0" "CoreKeyboard"
InputDevice "Mouse0" "CorePointer"
Option "Xinerama" "0"
EndSection

Section "Files"
EndSection

Section "InputDevice"
# generated from default
Identifier "Mouse0"
Driver "mouse"
Option "Protocol" "auto"
Option "Device" "/dev/input/mice"
Option "Emulate3Buttons" "no"
Option "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"
# generated from default
Identifier "Keyboard0"
Driver "kbd"
EndSection

Section "Monitor"
# HorizSync source: edid, VertRefresh source: edid
Identifier "Monitor0"
VendorName "Unknown"
ModelName "Philips PHL 237E7"
HorizSync 30.0 - 83.0
VertRefresh 56.0 - 76.0
Option "DPMS"
EndSection

Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BoardName "Quadro P6000"
EndSection

Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
Option "Stereo" "0"
Option "nvidiaXineramaInfoOrder" "DFP-8"
Option "metamodes" "DP-5: nvidia-auto-select +1920+0, DP-7: nvidia-auto-select +0+0"
Option "SLI" "Off"
Option "MultiGPU" "Off"
Option "BaseMosaic" "off"
SubSection "Display"
Depth 24
EndSection

启动

1
startx -- -layout seat0 -seat seat0 -novtswitch -sharevts

参数详解: man Xorg

  • -novtswitch : 如果操作系统支持,请禁用自动启动服务器时将X服务器重置和关机自动切换到激活的VT的功能
  • -sharevts: 如果操作系统支持,则与另一个X服务器共享虚拟终端。

xinitrc

$HOME/.xinitrc指定启动的桌面环境,比如xterm

~/.xinitrc由xinit执行,通常通过startx调用。 登录后将执行该程序:首先登录文本控制台,然后使用startx启动GUI。.xinitrc的作用是启动会话的GUI部分,通常是通过设置一些与GUI相关的设置,例如键绑定(使用xmodmap或xkbcomp),X资源(使用xrdb)等,以及启动会话管理器或窗口管理器(可能是桌面环境的一部分)。

1
2
# xinit /etc/X11/xinitrc -- /usr/bin/X :1 -config /etc/X11/xorg.conf.new -novtswitch -sharevts vt2 -keeptty -listen tcp
# X :1 -config /etc/X11/xorg.conf.new -novtswitch -sharevts vt2 -keeptty -listen tcp

窗口管理器

  • fvwm:虚拟窗口管理器,占用资源少
  • twm:(Tab Window Manager for the X Window System)

驱动模块——Driver

1
2
$ls /usr/lib/xorg/modules/drivers/
amdgpu_drv.so ati_drv.so fbdev_drv.so intel_drv.so modesetting_drv.so nouveau_drv.so qxl_drv.so radeon_drv.so vesa_drv.so vmware_drv.so

每一个驱动模块的详细信息,可以通过man手册进行查看,比如man modesettingman intelman amdgpu

modesetting

modesetting is an Xorg driver for KMS devices.

The modesetting driver supports all hardware where a KMS driver is available. modesetting uses the Linux DRM KMS ioctls and dumb object create/map.

modesetting是KMS设备的Xorg驱动程序。 该驱动程序支持在帧缓冲区深度为15、16、24和30的TrueColor视觉效果。multi-head配置支持RandR 1.2。 对于至少支持OpenGL ES 2.0或OpenGL 2.1的设备,可以通过glamor进行加速。 如果未启用魅力,则根据KMS驱动程序的偏好配置阴影帧缓冲区(除非帧缓冲区为每像素24位,在这种情况下始终使用阴影帧缓冲区)。

vesa

vesa是用于通用VESA视频卡的Xorg驱动程序。 它可以驱动大多数与VESA兼容的视频卡,但仅使用这些卡通用的基本标准VESA内核。驱动程序支持深度8、15、16和24。

Driver配置的缺失

如果在xorg.conf的配置中将Driver字段的配置缺失,系统会默认选择加载modesetingfbdevvesa驱动。

1
2
3
4
5
6
Section "Device"
Identifier "devname"
#Driver "modesetting" #将该字段注释掉,Xorg将自动进行加载
BusID "pci:bus:dev:func"
...
EndSection
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
...
(II) xfree86: Adding drm device (/dev/dri/card2)
(II) Platform probe for /sys/devices/pci0000:ae/0000:ae:00.0/0000:af:00.0/0000:b0:10.0/0000:bb:00.0/0000:bc:01.0/0000:bd:00.0/drm/card2
(II) "glx" will be loaded. This was enabled by default and also specified in the config file.
(II) LoadModule: "glx"
(II) Loading /usr/lib64/xorg/modules/extensions/libglx.so
(II) Module glx: vendor="X.Org Foundation"
compiled for 1.20.4, module version = 1.0.0
ABI class: X.Org Server Extension, version 10.0

(==) Matched modesetting as autoconfigured driver 0
(==) Matched fbdev as autoconfigured driver 1
(==) Matched vesa as autoconfigured driver 2
(==) Assigned the driver to the xf86ConfigLayout

(II) LoadModule: "modesetting"
(II) Loading /usr/lib64/xorg/modules/drivers/modesetting_drv.so
(II) Module modesetting: vendor="X.Org Foundation"
compiled for 1.20.4, module version = 1.20.4
Module class: X.Org Video Driver
ABI class: X.Org Video Driver, version 24.0
(II) LoadModule: "fbdev"
(II) Loading /usr/lib64/xorg/modules/drivers/fbdev_drv.so
(II) Module fbdev: vendor="X.Org Foundation"
compiled for 1.20.1, module version = 0.5.0
Module class: X.Org Video Driver
ABI class: X.Org Video Driver, version 24.0
(II) LoadModule: "vesa"
(II) Loading /usr/lib64/xorg/modules/drivers/vesa_drv.so
(II) Module vesa: vendor="X.Org Foundation"
compiled for 1.20.1, module version = 2.4.0
Module class: X.Org Video Driver
ABI class: X.Org Video Driver, version 24.0
(II) modesetting: Driver for Modesetting Kernel Drivers: kms
(II) FBDEV: driver for framebuffer: fbdev
(II) VESA: driver for VESA chipsets: vesa
(II) modeset(0): using drv /dev/dri/card2

DISPLAY环境变量

1
2
export DISPLAY=:0
export DISPLAY=192.168.1.1:0
1
export DISPLAY=[hostname][:number[.screen_number]]
  • hostname: 指定物理连接显示器的主机的名称, 主机名后加上单冒号(:)或双冒号(::)。
  • number: 指定该主机上Xserver的编号,在此显示编号后加上句点(.),一个CPU可以有多个显示器, 多个显示通常从零开始编号。
  • screen_number: 指定要在该服务器上使用的屏幕,单个Xserver可以控制多个屏幕,screen_number设置一个内部变量,如果使用的是C以外的语言,则可以使用DefaultScreen()宏或XDefaultScreen()函数进行访问(请参见“(Display Macros)[https://tronche.com/gui/x/xlib/display/information.html#display]”)。

无显示器启动X Server

安装Nvidia驱动后,如果没有接显示器,那么X Server在启动的时候会报错:

1
NVIDIA(0): Failed to assign any connected display devices to X screen 0. Set AllowEmptyInitialConfiguration if you want the server to start anyway

方法一:

重新生产xorg.conf配置文件

1
sudo nvidia-xconfig --allow-empty-initial-configuration
1
2
3
4
5
6
7
8
9
10
Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
Option "AllowEmptyInitialConfiguration" "True"
SubSection "Display"
Depth 24
EndSubSection
EndSection

主要添加配置:Option "AllowEmptyInitialConfiguration" "True"

方法二: Nvidia显卡启动Xorg使用虚拟设备连接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Section "Device"
Identifier "Card0"
Driver "nvidia"
BusID "PCI:26:0:0"
#for NVIDIA Xorg configure
Option "ConnectedMonitor" "DFP-0"
Option "MetaModes" "DFP-0: 1920x1080"
Option "HorizSync" "DFP-0: 40-70"
Option "VertRefresh" "DFP-0: 60"
Option "ConnectToAcpid" "false"
Option "UseEDID" "false"
Option "UseEDIDDpi" "false"
Option "ModeValidation" "NoEdidModes"
EndSection

方法三:

1
2
3
4
5
6
Section "Device"
Identifier "Card0"
Driver "nvidia"
BusID "PCI:59:0:0"
Option "UseDisplayDevice" "none"
EndSection

Option “UseDisplayDevice” “string”

The “UseDisplayDevice” X configuration option is a list of one or more display devices, which limits the display devices the NVIDIA X driver will consider for an X screen. The display device names used in the option may be either specific (with a numeric suffix; e.g., “DFP-1”) or general (without a numeric suffix; e.g., “DFP”).

When assigning display devices to X screens, the NVIDIA X driver walks through the list of all (not already assigned) display devices detected as connected. When the “UseDisplayDevice” X configuration option is specified, the X driver will only consider connected display devices which are also included in the “UseDisplayDevice” list. This can be thought of as a “mask” against the connected (and not already assigned) display devices.

Note the subtle difference between this option and the “ConnectedMonitor” option: the “ConnectedMonitor” option overrides which display devices are actually detected, while the “UseDisplayDevice” option controls which of the detected display devices will be used on this X screen.

Of the list of display devices considered for this X screen (either all connected display devices, or a subset limited by the “UseDisplayDevice” option), the NVIDIA X driver first looks at CRTs, then at DFPs. For example, if both a CRT and a DFP are connected, by default the X driver would assign the CRT to this X screen. However, by specifying:

  Option "UseDisplayDevice" "DFP"

the X screen would use the DFP instead. Or, if CRT-0, DFP-0, and DFP-1 are connected, the X driver would assign CRT-0 and DFP-0 to the X screen. However, by specifying:

  Option "UseDisplayDevice" "CRT-0, DFP-1"

the X screen would use CRT-0 and DFP-1 instead.

Additionally, the special value “none” can be specified for the “UseDisplayDevice” option. When this value is given, any programming of the display hardware is disabled. The NVIDIA driver will not perform any mode validation or mode setting for this X screen. This is intended for use in conjunction with CUDA or in remote graphics solutions such as VNC or Hewlett Packard’s Remote Graphics Software (RGS).

“UseDisplayDevice” defaults to “none” on GPUs that have no display capabilities, such as some Tesla GPUs and some mobile GPUs used in Optimus notebook configurations.

Note the following restrictions for setting the “UseDisplayDevice” to “none”:

OpenGL SyncToVBlank will have no effect.

None of Stereo, Overlay, CIOverlay, or SLI are allowed when “UseDisplayDevice” is set to “none”.

http://http.download.nvidia.com/XFree86/Linux-x86/390.144/README/xconfigoptions.html

参考

  • X,X11,Xorg,XServer,XClient,Xlib
  • Linux学习-X Server 配置文件解析与设定
  • xorg的配置文件
  • xorg.conf 配置详解
  • nvidia gpu fan speed control
  • Nvidia-Appendix D. X Config Options
  • Nvidia-Appendix B. X Config Options Part II. Appendices – 驱动版本390.144
  • xorg.conf
  • Difference between .xinitrc, .xsession and .xsessionrc
  • Chapter 13. Configuring Multiple Display Devices on One X Screen
  • Opening the Display
  • How do I get X to start without a monitor attached while using NVIDIA drivers?
  • How to tell intel graphics to use my custom EDID file?