logoPonyTechLab

马兆鑫的AI与深度学习博客

jetson orin nx ubuntu设置虚拟显示器

步骤 1|安装虚拟输入驱动

远程登录时若没有物理键鼠,需要挂载一对“虚拟鼠标”“虚拟键盘”才能让 NoMachine 接收输入。

sudo apt update sudo apt install -y xserver-xorg-input-void

步骤 2|生成“假 EDID”文件

EDID 描述显示器能力,用来告诉 X Server  “我有一台 1920×1080@60Hz 的屏”。

若手头无法导出真实 EDID,直接用业界通用的 128 字节 1080p EDID 即可:

# 1. 创建固件目录 sudo mkdir -p /lib/firmware/edid # 2. 将十六进制 EDID 写入文件 cat <<'HEX' | xxd -r -p | sudo tee /lib/firmware/edid/headless_1080p.bin >/dev/null 00ffffffffffff0010ac12304c303130201e0103803420782aee95a3544c99260f5054a54b008180 a940814081809500a9c0b30001010101565e00a0a0a029503020350055502100001a000000ff00534e 304a45373030353531330a000000fd00384c1e5311000a2020202020000000fc0044454c4c20553234 30310a20007e HEX # 3. 确认文件大小(128 字节即正常) ls -l /lib/firmware/edid/headless_1080p.bin

步骤 3|在引导参数里打开 DRM KMS

sudo vim /boot/extlinux/extlinux.conf #找到找到类似:APPEND ${cbootargs} quiet splash #在行尾 加上空格和 nvidia-drm.modeset=1,变成: APPEND ${cbootargs} quiet splash nvidia-drm.modeset=1

步骤 4|创建唯一的 Xorg 配置文件

先清理旧的 Xorg 片段,确保只有下面一份生效:

sudo rm -f /etc/X11/xorg.conf.d/10-*.conf /etc/X11/xorg.conf.d/20-*.conf

然后新建并写入 /etc/X11/xorg.conf.d/20-nvidia-headless.conf

sudo tee /etc/X11/xorg.conf.d/20-nvidia-headless.conf <<'EOF' ################################################################### # Jetson Orin NX — Headless / 有屏双模式统一配置 ################################################################### ########## GPU + 假 EDID ############################################ Section "Device"     Identifier  "GPU0"     Driver      "nvidia"     Option      "AllowEmptyInitialConfiguration" "True"     # 绑定到 Jetson 的外部口 DFP-1 (xrandr 里通常显示为 DP-1)     Option      "ConnectedMonitor" "DFP-1"     Option      "CustomEDID"       "DFP-1:/lib/firmware/edid/headless_1080p.bin" EndSection ########## 主屏 #################################################### Section "Screen"     Identifier  "Screen0"     Device      "GPU0"     DefaultDepth 24     SubSection "Display"         Depth   24         # 根桌面分辨率(虚拟输出),1080p 占用显存更少         Virtual 1920 1080     EndSubSection EndSection ########## 虚拟输入 ############################################## Section "InputDevice"     Identifier "DummyMouse"     Driver     "void"     Option     "CorePointer" "true" EndSection Section "InputDevice"     Identifier "DummyKeyboard"     Driver     "void"     Option     "CoreKeyboard" "true" EndSection ########## 布局 #################################################### Section "ServerLayout"     Identifier "Layout0"     Screen      "Screen0"     InputDevice "DummyMouse"     InputDevice "DummyKeyboard" EndSection EOF

步骤 5|禁用 Wayland、固定 Xorg 会话

sudo sed -i 's/^#WaylandEnable=false/WaylandEnable=false/' /etc/gdm3/custom.conf sudo sed -i 's|^#DefaultSession=.*|DefaultSession=gnome-xorg.desktop|' /etc/gdm3/custom.conf

如果系统里没有 gnome-xorg.desktop,可以改用 ubuntu-xorg.desktopxfce.desktop 等,确保指向一个 Xorg 会话。

步骤 6|重建 initramfs 并重启

sudo update-initramfs -u sudo reboot


验证与常见操作

  1. 不插物理屏 → SSH 登录后执行:

export DISPLAY=:0 export XAUTHORITY=$(grep -oP '(?<=-auth )\S+' /var/log/Xorg.0.log) # 驱动 modeset 是否生效 dmesg | grep nvidia-drm | head -n1   # → 应含 "nvidia-drm ... modeset=1" # 输出口状态 xrandr | grep "^DFP-1"   # → DFP-1 connected 1920x1080+0+0 # 虚拟输入是否挂载 xinput --list | grep -E "DummyMouse|DummyKeyboard"
  • 此时通过 NoMachine 远程登录,可看到 Ubuntu 登录界面,输入正确密码即可进入桌面,鼠标键盘均可操作。

  • 插上显示器 → 本地按 Ctrl+Alt+F2 切到控制台(或 SSH),运行:

export DISPLAY=:0 export XAUTHORITY=$(grep -oP '(?<=-auth )\S+' /var/log/Xorg.0.log) xrandr --output DFP-1 --auto
export DISPLAY=:0 export XAUTHORITY=$(grep -oP '(?<=-auth )\S+' /var/log/Xorg.0.log) xrandr --output DP-0 --auto

显示器即可点亮并使用本地输入;远程会话不受影响,与本地并存。

  1. 拔掉显示器 → 本地黑屏,但远程桌面仍保持 1920×1080 可操作。

常见变体

  • 想要 4K 虚拟桌面:把 Virtual 1920 1080 改为 Virtual 3840 2160

  • 物理口为 HDMI:将 DFP-1 全文替换为 HDMI-A-1(或 DP-0DP-1,以 xrandr 输出为准)。

  • 更换远程工具:VNC / Xpra 等同样支持,无需改动。


avatar

Pony

深度学习爱好者和技术研究者。专注于人工智能、边缘计算及计算机视觉领域的开发与应用。

现居地:陕西省-西安市

Email:zhaoxin.ma@chd.edu.cn

Categories