WSL2 ~ Linux on Windows ~ (Part 1: Introduction)

WSL2 is an abbreviation of "Windows Subsystem for Linux2", which runs Linux on Windows. Since Linux (WSL2) was very easy, I summarized the installation procedure.

1.First of all

Summary of this article

  1. WLS2 installation procedure
  2. How to avoid the error you encounter

Basically, I introduced WSL2 by the procedure of Microsoft. At that time, there was a terminal that caused an error when installing the Linux distribution (Ubuntu-20.04), so write down the workaround.

The environment that is the premise of the article

--Distribution to be introduced Ubuntu-20.04 (introduced from Windows Store)

--Host to be installed (an error occurred) --Windows10 Pro 64bit 1909 (OS build 18363,1198) --Result of uname -r: 4.19.128-microsoft-standard - CPU:Core-i7 5500U --Program: Windows Subsystem for Linux Update 4.19.128 --Winodws10 Pro 20H2 (OS build 19042,630)

--Host to be installed (No error occurred here) --Windows10 Pro 64bit 1909 (OS build 18363,1198) --Result of uname -r: 4.19.128-microsoft-standard - CPU:Core-i7-7500U --Program: Windows Subsystem for Linux Update 4.19.128 - KB4023057

I didn't clearly understand the environmental difference that led to the error, but I feel that it was caused by antivirus software. It is posted for your reference.

WSL overview

--Linux is available on Windows. --Easy to link with Windows. --WSL2 runs on a lightweight virtual machine and has high system call compatibility. - https://docs.microsoft.com/ja-jp/windows/wsl/about - https://www.atmarkit.co.jp/ait/articles/1906/14/news019.html

2. Introduction main part

Introduction of WSL2

(1) Start the prompt with administrator privileges

Start the prompt with administrator privileges.

powershell start-process cmd -verb runas

(2) Check if the system requirements are met

For x64 systems: version 1903 and above, build 18362 and above. For ARM64 systems: Version 2004 and above, build 19041 and above. Builds prior to 18362 do not support WSL 2. And that.

Run "winver" at the prompt to see the version and build number. You can also run "winver" by pressing the Windows logo key + R key.

winver

image.png

(3) Enable the Windows subsystem for Linux

C:\>dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Deployment image services and management tools
version: 10.0.18362.1139

Image version: 10.0.18363.1198

The function is enabled
[==========================100.0%==========================]
The operation completed successfully.

(4) Enable the virtual machine function

C:\>dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Deployment image services and management tools
version: 10.0.18362.1139

Image version: 10.0.18363.1198

The function is enabled
[==========================100.0%==========================]
The operation completed successfully.

(5) Reboot

Restart.

C:\>shutdown /r /t 0 

(6) Installation of Linux kernel update program

--Download below. - https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi --Run and install.

(7) Set WSL2 as the default version

wsl --set-default-version 2
For the main differences from WSL 2, https://aka.ms/See wsl2

(8) Install the Linux distribution

  1. Access the Windows Store. → Windows Store
  2. Select [Ubuntu 20.04 LTS] and install.

(9) Start WSL.

Press the Ubuntu 20.04 TLS launch button in the Windows Store.

Hopefully you'll be asked for a username and you'll be prompted for Linux. ** In my case, I ran into the following error: ** **

Installing, this may take a few minutes...
WslRegisterDistribution failed with error: 0x80370114
Error: 0x80370114 ???????????????????????????????????

Press any key to continue...

Below are two ways to avoid the error.

3. Troubleshooting

Introducing two methods.

Workaround 1 (change vmcompute settings)

This workaround is a method posted in the Microsoft Community. https://answers.microsoft.com/en-us/insider/forum/all/wsl-2-installing-linux-failed-error-code/bae391d1-4215-4d93-b0c4-3d96404a7c74?auth=1

(1) [Start] → [Settings] → [Update and Security]

image.png

(2) [Windows Security] → [Open Windows Security]

image.png

(3) [Apps and Browser Controls] → [Exploit Protection Settings]

image.png

(4) [Program Settings] → [vmcompute.exe] → [Edit]

image.png

(5) [Control Flow Guard (CFG)]

** Turn off Override System Settings ** image.png

(6) Start the service.

net start vmcompute

(7) Personally, restart the OS just in case

(The procedure does not tell you to restart, but just in case)

C:\>shutdown /r /t 0

(8) Start Ubuntu again

Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: dev
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

dev@pc:~$

Workaround 2 (Introduced in WSL1)

If you install in WSL1 mode, you do not need to change vmcompute.

(1) Set to WSL1 mode.

C:\> wsl --set-default-version 1

(2) Start up.

Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 4.4.0-18362-Microsoft x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Fri Nov 27 12:15:55 JST 2020

  System load:    0.52      Users logged in:       0
  Usage of /home: unknown   IPv4 address for eth0: 172.16.91.38
  Memory usage:   41%       IPv4 address for eth2: 172.18.78.193
  Swap usage:     0%        IPv4 address for eth3: 172.17.234.113
  Processes:      7

1 update can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable


The list of available updates is more than a week old.
To check for new updates run: sudo apt update


This message is shown once once a day. To disable it please create the
/home/dev/.hushlogin file.

Check the installed distribution with the WSL command. (Check from Windows command prompt)

C:\> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Stopped         1

Did you install it with the above?

4. Operation example

WSL operation

List of distributions

C:\> wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu-20.04           Running         2

Start by specifying a distribution

C:\> wsl -d Ubuntu-20.04
dev@pc:/$ ps
  PID TTY          TIME CMD
  262 pts/2    00:00:00 bash
  275 pts/2    00:00:00 ps
dev@pc:/$ uname -r
4.19.128-microsoft-standard
dev@pc:/$ cat /etc/issue
Ubuntu 20.04.1 LTS \n \l

View Windows files from Linux

The C drive is mounted at/mnt.

C:\> wsl -d Ubuntu-20.04
dev@pc:/$ cd /mnt
dev@pc:/$ ls -l
total 4
drwxrwxrwx 1 dev     dev     4096 Dec 10 08:15 c
drwxrwxrwx 1 dev     dev     4096 Dec 10 08:14 d
drwxrwxrwx 2 root    root    4096 Nov 25 22:24 m
drwxrwxrwt 5 root    root     100 Dec 12 21:16 wsl

Convert WSL version

An example of creating WSL2 after creating it with WSL1.

C:\> wsl --set-version Ubuntu-20.04 2

Export distribution

wsl --export

C:\> wsl --export Ubuntu-20.04 c:\work\Ubuntu-20.04.tar

Distribution import (copy)

wsl --import [optional]

C:\> wsl --import MyUbuntu-20.04-dev c:\work\MyUbuntu-20.04-dev c:\work\Ubuntu-20.04.tar
C:\> wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu-20.04           Stopped         2
  MyUbuntu-20.04-dev     Stopped         2
C:\> dir /B c:\work\MyUbuntu-20.04-dev
ext4.vhdx

Deletion of distribution

C:\> wsl --unregister <Distribution>

How to check if WSL is enabled.

Start Powershell with administrator privileges.

powershell start-process powershell -verb runas

Execute the command to check the validity of WSL.

Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Execution result

FeatureName      : Microsoft-Windows-Subsystem-Linux
DisplayName      :Windows subsystem for Linux
Description      :Provides services and environments for running native user-mode Linux shells and tools on Windows
I will serve you.
RestartRequired  : Possible
State            : Enabled
CustomProperties :
                   ServerComponent\Description :Linux shells and tools in native user mode on Windows
It provides the services and environment to do it.
                   ServerComponent\DisplayName :Windows subsystem for Linux
                   ServerComponent\Id : 1033
                   ServerComponent\Type : Feature
                   ServerComponent\UniqueName : Microsoft-Windows-Subsystem-Linux
                   ServerComponent\Deploys\Update\Name : Microsoft-Windows-Subsystem-Linux

Reference: https://docs.microsoft.com/ja-jp/windows/wsl/troubleshooting

5. Summary

I think you can use Linux on Windows quite easily. When installing Docker Desktop, please install it with WSL2 instead of WSL1. The number of distributions available in the Windows Store is limited, but we expect more.

6. References

--WSL document

--Introduction of WSL

--Comparison of WSL1 and WSL2. VHD (Disk Space) expansion with WSL2.

--WLS support on Windows 10-1903

Recommended Posts

WSL2 ~ Linux on Windows ~ (Part 1: Introduction)
Linux (WSL) on Windows
Linux on Windows -1-: debian introduction
Use Linux on Windows 10 (WSL2)
Install wsl2 and master linux on windows
Organize files on Windows with Linux commands-using WSL-
Linux environment construction (on WSL environment)
Create a Linux environment on Windows 10
pykintone on Windows Subsystem for Linux
[UE4] Build DedicatedServer on Windows and Linux
WSL2-Linux on Windows- (Part 2: Introduce basic tools)
WSL2 (Windows Subsystem for Linux) installation procedure
Create a Linux virtual machine on Windows
Python on Windows
[Linux] Introduction to Linux
Open a ZIP created on Windows in Linux
Cross-compile windows version from nim on arch | linux
Build Oracle Database 19c on Oracle Linux 8.3 (DB Build Part 2)
Daemonizing processes on Linux
Install python on WSL
Introduction of trac (Windows + trac 1.0.10)
Run Kali Linux on Windows with GUI (without VirtualBox)
Problems with windows python being called on pipenv on WSL
jblas on Arch Linux
Pylint on Windows Atom
[For memo] Linux Part 2
When Windows Subsystem for Linux (WSL) cannot be started
Linux standard textbook part 5
Use pyvenv on Windows
[Part 2] Let's build a web server on EC2 Linux
Linux, Windows proxy settings
Anaconda on Windows Terminal
New Linux commands! !! Part 2
Install Anaconda on Windows 10
python basic on windows ②
Install python on windows
Develop .NET on Linux
[Part 1] Let's set up a Minecraft server on Linux
Introduction to PyQt4 Part 1
Wake on lan on Linux
Install pycuda on Windows10
Build TensorFlow on Windows
Monitor traffic on Linux
Try FEniCS on Windows!
Build XGBoost on Windows
Install pygraphviz on Windows 10
Update vscode on linux
Use Ansible on Windows
Introducing WSL (Ubuntu 18.04) to WIndows10 ~ Proxy environment second part ~
Linux standard textbook part 4
Try Poerty on Windows
Try NeosVR on Linux
Install Chainer 1.5.0 on Windows
Use QuTiP on Windows
Use pip on Windows
Check capacity on Linux
A story about a Linux beginner putting Linux on a Windows tablet
Cross development environment (developing programs for windows on linux)
LiveUSB creation on Linux
Linux operation on Win10
How to set up WSL2 on Windows 10 and create a study environment for Linux commands