WSL2: I play Linux on native Win10

Original address: Liang Guizhao's blog

Blog address: http://blog.720ui.com

Welcome to the official account: "Server Thinking". A group of people with the same frequency, grow together, improve together, and break the limitations of cognition.

WSL2: I play Linux on native Win10

Today, I share with you a fun thing: WSL 2 (Windows Subsystem for Linux 2). WSL 2 is interesting because it provides a " true Linux kernel " based on a subset of Hyper-V features . How to understand this sentence? Everyone imagines that our usual research and development office environment needs Windows, and the development environment needs Linux system. What will we do?

  • Option 1: Install dual host systems to achieve physical isolation.
  • Option 2: Install a virtual machine, such as using VMware to achieve a complete user experience.
  • Option 3: Use Docker containers.

Among them, scheme 1 has the highest cost and requires more than two physical machines, while scheme 2 consumes a lot of resources and has low operation efficiency, and scheme 3 "containerization" is the scheme we use more at present. The latest Windows versions (for x64 systems: version 1903 or later, and build 18362 or later) support the use of the Linux kernel on native systems through WSL2 technology to implement Linux subsystemization.

WSL 2 usage tour

Now, let's find out. To update to WSL 2, we must be running Windows 10. Here, the official version for Windows 10 is requested by.

  • For x64 systems: Version 1903 or later, and build 18362 or later.
  • For ARM64 systems: 2004 or later, build 19041 or later.
  • Builds below 18362 do not support WSL2. Use Windows Update Assistant to update your Windows version.

We can Windows徽标键+ R type by selecting winver and then selecting OK.

The picture below shows the version number of my computer. If you're running Windows 10, version 1903 or 1909, open Settings from the Windows menu, navigate to Update & Security, and select Check for Updates.

Next, we need to make sure to enable 适用于 Linux 的 Windows 子系统 and 虚拟机平台 configure items.

Here, we can also open PowerShell as an administrator to install by command.

First enable the 虚拟机平台function .

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

Then reboot and enable the 适用于 Linux 的 Windows 子系统function .

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

Then, we also need to download the latest Linux kernel update package. Download address: https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

After installation, set WSL 2 as the default version.

wsl --set-default-version 2

Finally, we install the Linux distribution we need.

I am more familiar with using CentOS, and CentOS in the app store is a paid version, and there is an official open-source installation package of CentOS on github. We use the installation package on github for installation. Address: https://github.com/CentOS/sig-cloud-instance-images/

After the installation is complete, enter the command line to view the version list.

wsl -list -verbose

wsl You can enter the CentOS7 system by entering commands.

At this point, we can play the Linux system on the native Windows 10.

Docker Desktop WSL 2

Now, let me talk about a more fun feature. Because, WSL 2 introduces significant architectural changes, it is a full Linux kernel built by Microsoft that allows Linux containers to run natively without emulation. Therefore, with Docker Desktop running on WSL 2, users can take advantage of Linux workspaces. Additionally, WSL 2 improves filesystem sharing, startup times, and allows Docker Desktop users to access some cool new features. Docker Desktop uses the dynamic memory allocation feature in WSL 2 to dramatically reduce resource consumption. This means that Docker Desktop uses only the required amount of required CPU and memory resources, while making CPU- and memory-intensive tasks such as building containers run faster. Also, with WSL 2, the time required to start the Docker daemon after a cold boot is significantly faster. It takes less than 10 seconds to start the Docker daemon, compared to almost a minute in previous versions of Docker Desktop.

Before installing Docker Desktop WSL 2, the following steps must be completed:

  • Download Docker Desktop Stable 2.3.0.2 or later.
  • Install Windows 10 version 1903 or later.
  • Enable WSL 2 functionality on Windows.

references

write at the end

[Server-side thinking]: Let's talk about the core technology of the server side, and discuss the project structure and practical experience of the first-line Internet. Let all the R&D personnel working alone find their own circle to communicate and discuss together. Here, we can upgrade our cognition, connect with the top technology giants, connect with excellent ways of thinking, connect with the shortest path to solve problems, connect with all excellent methods, and break the limitations of cognition.

More exciting articles, all in "Server Thinking"!

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324175220&siteId=291194637