尝试WSL2

很突然地发现WSL(Windows Subsystem for Linux)2,了解到windows预览版上可以运行 Linux GUI 应用,所以想尝试一下,解决之前调取Ubuntu图形界面的难点。

前言

你现在可以在完全集成的桌面体验中预览适用于 Linux 的 Windows 子系统 (WSL) 支持,用于在) 上运行 Linux GUI 应用程序 (X11 和 Wayland Windows。
WSL 2 使 Linux GUI 应用程序能够感受到 Windows 上使用的本机和自然。
从 Windows 启动 Linux 应用 "开始"菜单
将 Linux 应用固定到 Windows 任务栏
使用 alt-tab 在 Linux 与 Windows 应用之间切换
跨 Windows 和 Linux 应用进行剪切和粘贴
你现在可以将 Windows 和 Linux 应用程序集成到工作流中,以获得无缝的桌面体验。


一、关于Windows版本的问题

1. 只是使用WSL2

参考官网安装 WSL
先决条件:
必须运行 Windows 10 版本 2004 及更高版本(内部版本 19041 及更高版本)或 Windows 11。

2. 如果要使用 Linux GUI 应用

参考官网Run Linux GUI apps on the Windows Subsystem for Linux (preview)
先决条件:

  • 需要 Windows 11 版本22000或更高 版本才能访问此功能。 可以加入 Windows 预览体验计划,以获取最新的预览版。

  • 安装了 vGPU 的驱动程序

    若要运行 Linux GUI 应用,你应该首先安装与你的系统匹配的预览驱动程序。 这使你能够使用虚拟 GPU (vGPU) 以便你可以从硬件加速 OpenGL 呈现中获益。

Intel WSL 的 GPU 驱动程序
AMD WSL 的 GPU 驱动程序
NVIDIA WSL 的 GPU 驱动程序

二、启用BIOS虚拟化(不然没法把WSL1下的ubuntu转换成WSL2下的ubuntu)

启用“虚拟机平台”可选组件并确保启用了 WSLEnable the 'Virtual Machine Platform' optional component and make sure WSL is enabled
你需要确保同时安装了”适用于 LinuxWindows 子系统”和”虚拟机平台”可选组件。可以通过在PowerShell 中运行以下命令来执行该操作:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

启用 ‘Virtual Machine Platform’ 可在控制面板或在PowerShell 中运行以下命令来执行该操作:

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

请重启计算机来完成两个组件的安装。

三、使用命令行设置要由 WSL 2 支持的Ubuntu发行版

如果尚未安装Ubuntu发行版,请参阅在 Windows 10 上安装文档页,以获取有关进行安装的说明。

若要设置Ubuntu发行版,请在cmd窗口运行:

wsl --set-version Ubuntu-18.04 2

并且确保将Ubuntu-18.04替换为你的Ubuntu发行版的实际名称。 (可使用以下命令找到这些内容:wsl -l)。可以随时更改回 WSL 1,方法是运行与上面相同的命令,但将“2”替换为“1”。.

此外,如果要使 WSL 2 成为你的默认体系结构,可以通过此命令执行该操作:

wsl --set-default-version 2

这会使你安装的任何新发行版均初始化为 WSL 2 发行版。

四、完成验证Ubuntu发行版使用的 WSL 版本

若要验证每个发行版使用的 WSL 版本,请使用以下命令(仅在 Windows 版本 18917 或更高版本中可用):

wsl --list --verbose
wsl -l -v

上面选择的Ubuntu现在应在“version”列下显示“2”。既然已经完成,便可以随时开始使用 WSL 2 发行版了!
在这里插入图片描述

五、在 Windows 上访问 WSL2

在资源管理器中输入\\wsl$

六、WSL2中使用VcXsrv实现xfce4图形界面

1. Steps to setup the server-side on windows:

2. Configure the client:

  • Open a terminal and find the IP of the windows host machine with this command:
export DISPLAY=$(/sbin/ip route | awk '/default/ { print $3 }'):0

https://github.com/microsoft/WSL/issues/4106#issuecomment-634778111.

  • run: echo $DISPLAY to see the IP.

  • run netcat to check if you’ve got connectivity:

nc -v IP_FROM_PREVIOUS_STEP 6000 #make sure to remove the appended ":0" after the IP.

If you get Connection…succeeded! you are set.

  • Open your .bashrc and add the “export …” command there in order to get it automatically every time you open a terminal. (Don’t use static IP here because it’s subject to change. Use the awk-ed export statement as is.)
  • Run an application and a window will pop-up on your host OS.
    Source: alextsil/ steps_gui_wsl2_xserver.txt
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值