ubuntu20修改xorg.conf实现双屏幕输出

如果显卡工作正常是不需要自己手动编写xorg.conf的(这个文件一般不存在或者是空的),系统会根据xorg.conf的缺省自动设置屏幕。

但有时候有的屏幕输出不对,想手动固定一下配置。比如我的ROG想设置内屏用intel驱动(集显),外屏用nvidia独显驱动,那么可以这么写(虽然因为显卡驱动的bug目前不支持这种搭配,我的xorg.conf没有发挥应有的作用,但还是记录一下):

bash 复制代码
# 没有/etc/X11/xorg.conf文件的话先生成一个(已经安装了nvidia显卡驱动)
nvidia-xconfig
sudo gedit /etc/X11/xorg.conf

我把xorg.conf修改为:

bash 复制代码
# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig:  version 535.154.05

Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "ScreenIntel" 0 0 #表示从(0,0)像素坐标开始
    Screen      1  "ScreenExternalNvidia" RightOf "ScreenIntel" # 表示屏幕关系
EndSection


Section "Monitor"
    Identifier     "Monitor0" # 必需
    VendorName     "Unknown"
    ModelName      "Unknown"
    Option         "DPMS"
EndSection

Section "Device"
    Identifier  "CardIntel" # 必需
    Driver      "intel" # 必需
    BusID          "PCI:0:2:0" # 为了区分显卡,必需
    Screen      0 # 为了区分屏幕,可能需要加上
EndSection

Section "Screen"
    Identifier "ScreenIntel" # 必需
    Device "CardIntel" # 必需
    Monitor        "Monitor0" # 为了区分monitor
EndSection


Section "Monitor"
    Identifier     "Monitor1"
    VendorName     "Unknown"
    ModelName      "Unknown"
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "CardNvidia"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BusID          "PCI:1:0:0"
    Screen      1
    Option "IgnoreDisplayDevices" "CRT"
EndSection

Section "Screen"
    Identifier     "ScreenExternalNvidia"
    Device         "CardNvidia"
    Monitor        "Monitor1"
    DefaultDepth    24
    SubSection     "Display"
        Depth       24
    EndSubSection
    # Option          "metamodes" "DFP-2: nvidia-auto-select"
EndSection

其中Identifier可以自己命名,区分开就行,Driver其实没那么重要,因为系统会根据插槽上实际的显卡来安排Driver,里面也不是所有参数都是必须的,缺省的系统会自动安排。具体说明可参考https://www.x.org/releases/current/doc/man/man5/xorg.conf.5.xhtml

其中BusID是根据自己电脑来设置的:

bash 复制代码
lspci | grep VGA

我的电脑输出是01:00.0是nvidia显卡,0:2.0是intel集显,注意是十六进制,busID是十进制。

一些常用指令:

bash 复制代码
# 查看xorg启动日志,方便发现问题
gedit /var/log/Xorg.0.log
# 系统日志导出到txt
dmesg > log.txt
# 查看xorg的补充配置文件
ls /usr/share/X11/xorg.conf.d/

每次修改xorg后,不需要重启电脑,只需要重启图形界面服务就行:

bash 复制代码
# 如果你用的是gdm3(ubuntu20默认)
sudo systemctl restart gdm3.service
# 如果你用的是lightdm(兼容性更好)
sudo systemctl restart lightdm.service
# 安装lightdm替代gdm3
sudo apt install lightdm

如果修改xorg.conf不当导致黑屏,可以按Ctrl+Alt+F1~F7登录命令行,然后用vim或者vi来修改xorg

bash 复制代码
sudo vim /etc/X11/xorg.conf

一般不要手动修改固定xorg.conf,出了问题想恢复,可以:

bash 复制代码
# 清空xorg.conf
echo '' | sudo tee /etc/X11/xorg.conf
# 或者删除xorg.conf
sudo rm /etc/X11/xorg.conf
相关推荐
电商API_1800790524719 分钟前
构建高效可靠的电商 API:设计原则与实践指南
运维·服务器·爬虫·数据挖掘·网络爬虫
晓枫-迷麟1 小时前
【nano与Vim】常用命令
linux·编辑器·vim
tianyuanwo1 小时前
Ansible自动化运维全解析:从设计哲学到实战演进
运维·自动化·ansible
LucienShui1 小时前
Webhook 配置备忘
linux·运维·webhook
LanLance1 小时前
ES101系列09 | 运维、监控与性能优化
java·运维·后端·elasticsearch·云原生·性能优化·golang
Clownseven1 小时前
“轻量应用服务器” vs. “云服务器CVM”:小白入门腾讯云,哪款“云机”更适合你?(场景、配置、价格对比解析)
运维·服务器·腾讯云
Leo.yuan2 小时前
API是什么意思?如何实现开放API?
大数据·运维·数据仓库·人工智能·信息可视化
超级土豆粉2 小时前
从0到1写一个适用于Node.js的User Agent生成库
linux·ubuntu·node.js
PH_modest2 小时前
【Linux跬步积累】—— 网络编程套接字(二)
linux·运维·网络
itachi-uchiha2 小时前
使用vsftpd搭建FTP服务器(TLS/SSL显式加密)
运维·服务器·ssl