使用 XLaunch 一键启动 WSL 中的 Gnome 3

升级到 Windows 1803 后可以跑更多的桌面应用了。虽说 WSL 完全不是为此设计的,但我就是乐此不疲地看着热闹,一次次地试探 WSL 的最大潜力(误,只是好玩而已)。虽然还是存在一些问题,Gnome 3 也不意外地可以运行。这篇文章将讲述如何使用 XLaunch 一键启动 WSL 中的 Gnome 3。这篇文章便是在 WSL 上的 Gnome 中完成并发布的。

由于我未能可复现地安装 Gnome 3,暂时就不详细讲怎么安装了。首先需要升级 Ubuntu 至 18.04 LTS。需要安装的包有 ubuntu-desktop 和 mesa-utils,前者包含 Gnome 3 后者包含软件渲染器(因为 WSL 不支持直接硬件访问)。


手动启动

安装完成后可以先尝试手动启动 Gnome。方法是先启动 dbus 服务:(每次启动 Gnome 前都建议重启 dbus 服务,以防 dbus 挂了)

然后使用 XLaunch 打开一个 One large window 的 X Server 并前台启动 Gnome:(或其他 Windows 上的 X Server 实现,并请根据实际 X Server 的端口修改 DISPLAY 的值)

不像之前版本的 WSL,现在使用 dbus 不需要任何的修改,因为 Windows 1803 的 Win32 及 WSL 子系统已经全部支持 Unix Domain Socket 了。对于 Gnome 3,则需要指定其以 x11 的方式启动。效果大概如图:

关闭 vcxsrv 的窗口即可关闭 Gnome session。


配置声音(可选)

在 Windows 上安装 PulseAudio 的服务端,可以参考我以前写的文章

接下来需要将 PulseAudio 的服务端配置成一个可以在 WSL 中启用的服务。复制这份模板代码并以 root 用户,755 权限保存为 /etc/init.d/pulseaudio:https://github.com/fhd/init-script-template/blob/master/template。然后修改其中的 cmd=”” 为 cmd=”/mnt/c/your/path/to/pulseaudio”(请自行更改路径)。

配置完毕后可以这样测试:执行 sudo service pulseaudio start,然后打开 Windows 的音量混合器查看是否有一个 pulseaudio 程序,如图:


一键启动

接下来就要配置一键启动了。首先需要无密码执行 sudo 的权限。方法可以搜索“sudo ubuntu 免密码”。

接下来复制下面的代码并保存为 gnome.xlaunch,双击即可启动 Gnome。

其中 WindowMode 代表 vcxsrv 的窗口模式,一般使用 Fullscreen 或 Nodecoration。区别在于前者不会显示 Windows 任务栏,不过这个模式对 Windows 虚拟桌面的支持并不好因此我选择了后者。

Display 代表 X Server 的端口,可以改成任何想要的值,但后面的 DISPLAY 环境变量请一并更改。

在 Shell 命令中有很多 > /dev/null。这些是用来将 shell 的 stdout 和 stderr 除去,否则 vcxsrv 会经常弹窗问用户要输入。

如果不需要声音,请将 sudo service start pulseaudio 以及 PULSE_SERVER=tcp:127.0.0.1 删除。


已知问题

dbus 十分不稳定,比如说在 nautilus 中使用了回收站功能后 dbus 就会崩溃,而且是静默崩溃,Gnome 从此就会变得几乎无法使用。因此如果出现了任何异常,尝试重启 dbus 与 Gnome。

其次,ibus 无法使用。我仍未找到原因与解决办法。ibus-daemon 仅仅是提示 Child exited,没有有用的输出,也并没有 log 来 debug。不过,Fcitx 完全没有问题,安装方法与正常的 Ubuntu 相同。因此依然可以使用输入法,只不过是失去了 ibus 与 Gnome 的高度集成而已。

此外,由于是纯软件渲染没有硬件加速,导致图形界面,尤其是播放视频,会有卡顿,不过并不影响开发任务。

发表评论?

16 条评论。

  1. 請問您是由16.04升上18.04才安裝ubuntu-desktop的嗎? 還是直接在Windows Store 安裝18.04?

    • 16.04 升级的,需要执行 sudo do-release-upgrade -d。这是因为 Ubuntu 的 LTS 升级有些特殊,16.04.x 不能升级到 18.04,只能升级到 18.04.1,而后者需要今年七八月份才会发布。因此从 16.04.x 升级到 18.04 必须走 dev 分支。

  2. 请教一下,如果使用非root权限打开桌面,当一些设置需要用到root权限时(比如更改语言),WSL里似乎并不会像原生ubuntu一样弹出一个输入root密码的框来提升权限,而是直接失败,这个有什么办法解决吗?

    • 很遗憾,据我目前所知,Ubuntu 那个类似 UAC 一样的提权系统依赖于 systemd,而 WSL 用的是自己的一个类似 SysV 的建议实现。因此需要提权的 GUI 应用无法正常使用。如果有需要的话还是命令行 sudo 吧。

    • 你装个kde的polkit试试?

      • WSL1 的 polkit 几乎是没戏了,对 systemd 的依赖没法解除。WSL2 马上要有 GPU 支持,回头可以试试看。

  3. 你好,我尝试启动 gnome 时遇到如下问题

    (gnome-session-check-accelerated:5931): dbind-WARNING **: 08:42:43.089: Couldn't register with accessibility bus: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
    X Error of failed request: BadValue (integer parameter out of range for operation)
    Major opcode of failed request: 147 (GLX)
    Minor opcode of failed request: 3 (X_GLXCreateContext)
    Value in failed request: 0x0
    Serial number of failed request: 19
    Current serial number in output stream: 22
    gnome-session-check-accelerated: GL Helper exited with code 256

    (gnome-session-check-accelerated-gles-helper:5933): dbind-WARNING **: 08:42:43.233: Couldn't register with accessibility bus: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

    ** (gnome-session-check-accelerated-gles-helper:5933): WARNING **: 08:42:43.244: eglGetDisplay() failed
    gnome-session-check-accelerated: GLES Helper exited with code 256

    (gnome-session-check-accelerated:5934): dbind-WARNING **: 08:42:43.319: Couldn't register with accessibility bus: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
    X Error of failed request: BadValue (integer parameter out of range for operation)
    Major opcode of failed request: 147 (GLX)
    Minor opcode of failed request: 3 (X_GLXCreateContext)
    Value in failed request: 0x0
    Serial number of failed request: 19
    Current serial number in output stream: 22
    gnome-session-check-accelerated: GL Helper exited with code 256

    (gnome-session-check-accelerated-gles-helper:5936): dbind-WARNING **: 08:42:48.444: Couldn't register with accessibility bus: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

    ** (gnome-session-check-accelerated-gles-helper:5936): WARNING **: 08:42:48.452: eglGetDisplay() failed
    gnome-session-check-accelerated: GLES Helper exited with code 256
    gnome-session-binary[5922]: WARNING: software acceleration check failed: Child process exited with code 1
    gnome-session-binary[5922]: CRITICAL: We failed, but the fail whale is dead. Sorry....

    请问有什么解决办法吗

  4. 折腾了一夜,网上的各种教程都是16版本的,还在用unity,进入后桌面各种异常。商店直接下载最新的是18。04版本的,某些文件已经没了,只有你的方法正常进入正常!!!赞!!!

  5. 还是有些异常部分。。。新立得感觉怪怪的,火狐插件永远是安装中。。。方便的话能帮忙看一下吗

  6. 感觉可能是我什么软件或者组件没有安装全,贴主能给一份支持系统运行的完整软件目录吗?还有就是之前的关于声音的软件有一个安装源404了

  7. WSL2 + Ubuntu 18.04 + GNOME 3.28没问题,我试过了

    WSL2 + Ubuntu 20.04 + GNOME有问题,图形界面起不来。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据