Wsl2: Windows native Linux subsystem

Song Baohua 2021-09-15 09:48:49


In the last article , We mainly talked about : stay Windows In the system , install WSL Subsystem .

In this paper :WSL: stay Windows Development in the system Linux Another artifact of the program

however WSL It just looks like Linux nothing more , Although in this subsystem , We can execute Linux Program , But at the bottom ,WSL The call is still win32 API.

in other words :WSL Just an adaptation layer .

later , Microsoft finally released WSL2 This real Linux Subsystem , This is a real Linux Full kernel , With traditional virtual machines VitualBoxVMWare equally , But it has better interoperability with the host .

For completeness , Let's continue to finish the process .

Problems encountered in this process 、 Required installation software and other resources , Has been uploaded to the network disk , There is a download address at the end of the text .

install WSL2 The premise of

Before we start , Let's take a look at the current computer WSL Version of .

stay Windows Command line window , Input instruction : wsl --list --verbose( Or enter a simplified version : wsl -l -v), Get the results :

You can see what we installed in our last article Ubuntu-18.04, and WSL The version is 1.

If you want to upgrade to WSL2,Windows The kernel version of the operating system must meet certain requirements , as follows :

We will follow the official requirements , Check if your computer meets your needs : choice Windows Winkey Win + R, Then type. winver, choice “ determine ”.

It seems that my system can meet the requirements , Then go on to the next step !

If your kernel version does not meet this requirement , Can search for keywords “WIN10 Get internal preview version ”, You can find a solution .

install WSL2

Continue to start as Administrator PowerShell, Then execute the command :

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

here , It's time to restart the computer again !

After reboot , Continue to PowserShell in , hold Ubuntu-18.04 Set to WSL2 edition .

The command entered is :

wsl --set-version Ubuntu-18.04 2

This step may encounter such problems :

resolvent : Download from Microsoft's official website WSL2 Linux Kernel upgrade package , Download address is :

WSL2 Linux Kernel upgrade package

You can also download it from the network disk at the end of the text

After downloading , All the way Next Can be installed .

here , stay PowerShell Re execute in wsl --set-version Ubuntu-18.04 2 Instructions ( Need to wait for a while , Probably 1 About minutes ):

meanwhile , hold WSL The default version of is changed to 2wsl --set-default version 2.

here , Let's execute the instructions wsl -l -v Let's have a look at , It becomes WSL2 Version of the :

Now? , Restart Ubuntu-18.04 System , Although it is still a dark window , But it's a complete 、 Pure Linux operating system !

Install desktop environment

The operation of this part , Reference resources :https://autoize.com/xfce4-desktop-environment-and-x-server-for-ubuntu-on-wsl-2/.

About Linux Desktop environment for , It is associated with Windows There are some differences in the concept of desktop environment .

stay Linux In the system , The desktop environment is a stand-alone application , Not part of the operating system .

In other words , Even without a desktop environment , You can also have a good time Linux System , Such as those servers and other devices .

Linux The desktop in consists of client and server , They communicate through a protocol , Be commonly called :X11.

Server side : Responsible for graphic display ;

client : According to the system settings DISPLAY environment variable , Send the request to display graphics to the server ;

therefore , To make our Ubuntu Display the graphical interface , We need to install a server software and client software .

Be careful : The server software here is installed in Windows In the system , The client is installed in Ubuntu-18.04 In the system .

Install client

stay Ubuntu-18.04 In the terminal window , Execute the following instructions to install the client software xfce4

sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install xfce4

To configure DISPLAY environment variable

because Ubuntu Client in xfce4 You need to send the display request , Send to... Over the network Windows The server on , So we need to know Windows Systematic IP Address , stay Windows View... In the command line window in the system :ipconfig

And then in Ubuntu-18.04 Middle handle this IP Address , Configure... In the home directory .bashrc In file :

$ cd
$ vi .bashrc

Add at the end of the file :

export DISPLAY=192.168.192.1:0

preservation 、 After closing the file , perform :source ~/.bashrc Update can .

Install server

The graphical interface has VcXsrv and Xming Two software , We choose the front VcXsrv.

alike , I have already put vcxsrv-64.1.20.9.0.installer.exe Put it in the net disk , Download all the way Next install .

After installation , start-up Windows On the table XLaunch Program :

then , Follow the configuration in the reference document , as follows :

In the last step , You can save the configuration information on the desktop .

Start client

stay Ubuntu-18.04 Command line window in the system , Execution instruction :startxfce4

At the moment , The artifact happened : Yours Windows Does the system jump out of the following window :

You can open it on the desktop File System, Did you see many familiar figures ?

In the open mnt Catalog , Did you see Windows Drive letter in the system ?

however , Chinese information is displayed in garbled code ! Then let's install the Chinese language support package .

Chinese support

stay Ubuntu-18.04 System command line window , Set up locale:

here , Windows in our desktop environment can be used , As shown in the figure below :

sudo vi /etc/locale.gen

Copy the blue line in the figure below , Then remove the front # and Space , Then save 、 sign out .

Then execute instructions in the terminal :sudo locale-gen

The user name in the upper right corner of the stand-alone , choice 【Log Out..】

here ,Ubuntu The virtual machine WSL Window xfce4 The client will exit , Re execution startxfce4 Start client :

Again , In the terminal window on the desktop , hold locale Change to Chinese :

sudo vi /etc/default/locale

hold LANG=C.UTF-8 Change it to LANG=zh_CN.UTF-8

then , Install the following Chinese language packs into it :

sudo apt install language-pack-zh-hans
sudo apt install language-pack-gnome-zh-hans
sudo apt install language-pack-kde-zh-hans

At the moment , Look at those random codes just now , Have you displayed Chinese correctly ?


------ End ------

Next , You can also install various IDE, Explore how they share files ...

The software to be installed in this article , It has been uploaded to the network disk .

Please reply in official account. 721( It's not a message area ), You can receive the download address , thank you !

Recommended reading

【1】C Language pointer - From basic principles to fancy techniques , With graphics and code to help you explain thoroughly
【2】 Step by step analysis - How to use C Implement object-oriented programming
【3】 original gdb The underlying debugging principle is so simple
【4】 Is inline compilation terrible ? After reading this article , End it !

Other series : Selected articles C Language Linux operating system Application design The Internet of things


Official account of star standard , You can find me faster !

Please bring the original link to reprint ,thank
Similar articles

2021-09-15