如何在 WSL 上运行 X.org 和 GNOME?

如何在 WSL 上运行 X.org 和 GNOME?

经过多年的徒劳尝试和谷歌搜索后,我终于决定来这里。作为 Linux 的初学者,我真的什么都不懂。在学习了无数教程后,除了一个问题,我已经解决了所有问题。(尽管之后可能还会有更多问题)

我运行时出现此错误startx

X.Org X Server 1.20.13
X Protocol Version 11, Revision 0
Build Operating System: linux Ubuntu
Current Operating System: Linux DESKTOP-2DV5IQB 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64
Kernel command line: initrd=\initrd.img panic=-1 pty.legacy_count=0 nr_cpus=8
Build Date: 14 December 2021  02:14:13PM
xorg-server 2:1.20.13-1ubuntu1~20.04.2 (For technical support please see http://www.ubuntu.com/support)
Current version of pixman: 0.38.4
        Before reporting problems, check http://wiki.x.org
        to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
        (++) from command line, (!!) notice, (II) informational,
        (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Thu Apr 28 21:10:03 2022
(==) Using system config directory "/usr/share/X11/xorg.conf.d"
xf86EnableIOPorts: failed to set IOPL for I/O (Function not implemented)
xf86EnableIOPorts: failed to set IOPL for I/O (Function not implemented)
(EE)
Fatal server error:
(EE) no screens found(EE)
(EE)
Please consult the The X.Org Foundation support
         at http://wiki.x.org
 for help.
(EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information.
(EE)
(EE) Server terminated with error (1). Closing log file.
xinit: giving up
xinit: unable to connect to X server: Connection refused
xinit: server error
Couldn't get a file descriptor referring to the console

当我尝试运行时xinit

X.Org X Server 1.20.13
X Protocol Version 11, Revision 0
Build Operating System: linux Ubuntu
Current Operating System: Linux DESKTOP-2DV5IQB 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64
Kernel command line: initrd=\initrd.img panic=-1 pty.legacy_count=0 nr_cpus=8
Build Date: 14 December 2021  02:14:13PM
xorg-server 2:1.20.13-1ubuntu1~20.04.2 (For technical support please see http://www.ubuntu.com/support)
Current version of pixman: 0.38.4
        Before reporting problems, check http://wiki.x.org
        to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
        (++) from command line, (!!) notice, (II) informational,
        (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Thu Apr 28 21:11:39 2022
(==) Using system config directory "/usr/share/X11/xorg.conf.d"
xf86EnableIOPorts: failed to set IOPL for I/O (Function not implemented)
xf86EnableIOPorts: failed to set IOPL for I/O (Function not implemented)
(EE)
Fatal server error:
(EE) no screens found(EE)
(EE)
Please consult the The X.Org Foundation support
         at http://wiki.x.org
 for help.
(EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information.
(EE)
(EE) Server terminated with error (1). Closing log file.
xinit: giving up
xinit: unable to connect to X server: Connection refused
xinit: server error

我现在真的不知道该做什么。我只想按照“简单”的说明去做在 ubuntu 网站上安装 GNOME!

我的问题基本上是,我这样做对吗?如果是这样,为什么我会收到这些错误,我该怎么做才能修复它们?如果不对,我该怎么做?

我正在使用 WSL,我的许多疑问让我怀疑这可能是问题的一半。我对此的判断可能也是错的。

任何帮助,将不胜感激!

答案1

您可以安装 VcXsrv 以便在 Windows 中运行 X 服务器。我留给你本指南

在WSL中更新系统,安装桌面环境:

sudo apt update
sudo apt upgrade
sudo apt install lxde

在您的案例中为 GNOME。然后设置环境变量 DISPLAY,您需要提供 Windows WSL IP 地址,如下所示:

export DISPLAY=<address>:0

替换为相应的值。您可以转到 PowerShell 并执行来获取地址ipconfig。您会在 WSL 部分 (IPv4) 下看到它。

这里解释为什么可能需要设置 LIBGL_ALWAYS_INDIRECT。

export LIBGL_ALWAYS_INDIRECT=1

在 Windows 上运行 XLaunch 时(由 VcXsrv 提供):

  1. 显示设置:选择“一个大窗口”
  2. 显示编号:0(设置 DISPLAY 时 IP 地址旁边的数字)
  3. 选择如何启动客户端:选择“不启动客户端”
  4. 额外设置:默认和“禁用访问控制”(我不知道这是否会导致任何安全问题)

然后您可以在 WSL 上使用startx和启动桌面环境。

当我这样做时,我也安装x11-apps并运行xeyes以测试它是否有效。

编辑:您可能需要尝试按如下方式设置 DISPLAY 以自动获取 IP 地址:

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0

相关内容