@TOC

WSL1 and WSL2

Check whether it is WSL1 or WSL2

Open PowerShell and type

wsl -l -v
Copy the code

Comparing WSL 1 and WSL2, WSL1 was compared to WSL2.

For the installation window interface, wSL1 and Win10 use the same IP address, so in the DISPLAY setting, you can directly use localhost, that is, export DISPLAY=:0, but WSL2 has its own IP address, and inside WSL2, There is an IP address pointing to Win10 that can be passed

cat /etc/resolv.conf
Copy the code

To look at it.This IP address is the IP address of Windows 10 in WSL2.

Upgrade wSL1 to WSL2

If you run wSL-l -v to display Ubuntu as WSL1, you can update it to WSL2 if you like it.

Open PowerShell (Administrator) and execute

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
Copy the code

Reboot if you need to.

Replace ubuntu-18.04 in the following command with the name displayed after WSL-L.

Wsl-l WSL --set-version Ubuntu-18.04 2 Wsl-l-vCopy the code

Performing this will use WSL2 by default.

wsl --set-default-version 2
Copy the code

The WSL1 installation page is displayed

Both methods require Xming to be installed on Windows first.


Method 1: Use xFCE4 desktop to directly display the entire Ubuntu desktop

Cons: With Xming, XFCE and Windows display together. Because the entire desktop is displayed, the latency is slightly higher. Advantages: Using WSL, it can fully use all cpus compared to virtual machines, and in build versions after Win10 20145, it will support GPU. You can start the Windows Preview program, install the Dev channel version, and enjoy the new version in advance, but note that the 20211 version dries up WSL (2020-9-16).

Installation method

1. Install WSL Ubuntu subsystem

2. Run the command on Ubuntu

sudo apt install xfce4
sudo apt install xfce4-session
echo "Export DISPLAY = : 0.0">> ~/.bashrc
# or
# echo "export DISPLAY=localhost:0">> ~/.bashrc
source ~/.bashrc
Copy the code

3. Start Xming

4. Run the command in Ubuntu

xfce4-session
Copy the code

Method 2: Use x11-apps

Advantages: You can only open the corresponding software with less load and delay. Disadvantages: For like complete desktop partners, not too comfortable.

Installation method

1. Reinstall OpenSSH

WSL is minimal OpenSSH by default, which requires a full openSSH installation

sudo apt-get remove  openssh-server
sudo apt-get install  openssh-server
Copy the code

2. Set up SSH

Windows 10 ships with an SSH server and you need to disable it or change the port that will be used for SSH on the WSL. I chose the latter and used port 2200 for WSL SSH.

sudo apt install vim
sudo vi /etc/ssh/sshd_config
Copy the code

The default sshd_config file should have all entries annotated, add the following code to the file. If not all of them are commented, look for duplicates between uncommented entries and the ones below.

PermitRootLogin no
AllowUsers yourusername
PasswordAuthentication yes
UsePrivilegeSeparation no
ListenAddress 0.0.0.0
Port 2200
Copy the code

Then restart the SSH service

sudo service ssh --full-restart
Copy the code

3. Install x11 – apps

sudo apt-get install x11-apps
Copy the code

X11-apps also needs to set export DISPLAY=:0. If it has been installed and set according to mode 1, it does not need to be set again. If mode 2 is directly adopted, you need to set this parameter

echo "export DISPLAY=:0" >> ~/.bashrc
source ~/.bashrc
Copy the code

4. Open the Xming

5. Run the following command

xeyes
Copy the code

If this occurs, the configuration is successful.

Again, try Gedit.

sudo apt install gedit
gedit
Copy the code


The WSL2 installation window is displayed

For details, see: WSL2 using VcXsrv to implement XFCE4 GUI + Sound transmission

The author modified:

  1. The disadvantage is that the host win10 machine restarts every time, nameserver IP address will change, the original SET of IP can not connect to Xserver, can not display. Therefore, the system automatically outputs the NAMeserver IP address.

Note: if it has been set according to the author of Zhihuexport DISPLAY=xx.xx.xx.xx:0Please comment it out first.

Last added in ~/.bashrc

export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
Copy the code

Then run source ~/. Bashrc to ensure that nameserver’s IP address will not be disconnected due to computer restart.


  1. The original author did not save the configuration file of VcXsrv software, so that every time you open the software, you need to click several times for configuration. We can save the configuration file and add the configuration parameters for quick startup, so that you can directly click the icon of VcXsrv to open the correct window.

We save the following steps as a configuration file: Click Save Configuration.Put the config.xlaunch file on your desktop first.

Locate xlaunch.exe. Copy the config.xlaunch file to the same directory. Then create a shortcut to xlaunch.exe,

Add -run “config.xlaunch” after “Target” to fix the shortcut to the start screen or desktop. In this way, click the shortcut directly to open the configured window in one step.

Ubuntu xFCE4 desktop Chinese display may be abnormal, attached: solve ubuntu Chinese garble problem


reference

  1. www.jianshu.com/p/9fdea59ae…
  2. Virtualizationreview.com/articles/20…
  3. www.liumingye.cn/archives/32…
  4. zhuanlan.zhihu.com/p/137618871
  5. www.h3v.net/blog/index….