WSL first experience
WSL Linux subsystem experience native docker, really fragrant!
The Linux subsystem of windows has been out for a long time. Have you experienced it?
I’ll take you to the trouble today,After all, they want to get rid of the massive VMS that take up too much hardware resources, such as VMware
This article is dedicated to you who love to toss, toss it, after wave!
Briefly, the main points of this article are as follows:
- The whole process of WSL installation
- The whole process of selective upgrade to WSL 2
- Experience native docker in WSL 2
What is WSL?
WSL is the abbreviation of windows subsystem for Linux, which means the windows subsystem of Linux version.
Quoted from: Microsoft official website https://docs.microsoft.com/zh…
The Windows Subsystem for Linux lets developers run a GNU/Linux environment — including most command-line tools, utilities, and applications — directly on Windows, unmodified, without the overhead of a virtual machine.
- Choose your favorite GNU/Linux distributions from the Microsoft Store.
- Run common command-line tools such as
awk, or other ELF-64 binaries.
Run Bash shell scripts and GNU/Linux command-line applications including:
- Install additional software using own GNU/Linux distribution package manager.
- Invoke Windows applications using a Unix-like command-line shell.
- Invoke GNU/Linux applications on Windows
In short, Linux’s windows subsystem lets developers
No virtual machine requiredYou can run Linux environment directly on windows, including most command-line tools, programs and applications.
The benefits of using WSL are:
- Compared with Linux under virtual machine, WSL takes less resources and is more fluent;
- WSL can read and write files under Windows file system directly, which makes file transmission more convenient;
- Clipboards interworking, you can directly copy the text content in other places under windows and paste it to WSL;
Note: in fact, I like virtual machine. After all, it simulates the hardware, which is relatively mature and stable.
Turn on WSL support
A shell with administrator rights can install WSL.
Press Win + X to find windows PowerShell (administrator) and copy the execution command.
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
The above command activates the WSL service and then needs to restart the system
After restart, win + R, enter appwiz.cpl , find “start or close windows functions” in the upper left corner, and you will see that this option is selected.
In fact, the above command is equivalent to manually checking this function.
Direct command execution may be more efficient.
Install WSL distribution
Search in the windows store
ubuntu, select the version you like and install it.
What I choose here is
Ubuntu 20.04 LTSAfter that, all the content is also written based on WSL Ubuntu.
After downloading and installing, the first time it is opened will be initialized for a while
Then set a user name and password
At this point, our WSL is installed.
Let’s make it work better!
Apt source change
The official source of Debian / Ubuntu is very slow to visit in China, so let’s replace it with the software source image of Tsinghua University
PS: you can also use the image of alicloud. If I experience it not so fast (maybe my posture is wrong), I don’t recommend it.
- Execute the following command to backup the apt installation source:
$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
- VIM editor sources.list :
$ sudo vim /etc/apt/sources.list
- Will sources.list Replace with the following
Note: here it is
Ubuntu 20.04 LTSOf course,
For other versions of Ubuntu, visit [Tsinghua University open source software image station] to find the corresponding version of the image configuration
#The source image is annotated by default to improve the apt update speed. If necessary, you can uncomment it yourself deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse #Pre release software source, not recommended # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
- Update the software source in all the software list, you can see the fast in the screen, Hua Hua Hua Hua
$ sudo apt-get update
- Update software
$ sudo apt-get upgrade #Update content a little more, about a few minutes, play with the mobile phone...
Configure ssh server
We are used to Using SSH tools like xshell and SecureCRT to connect Linux, so we can get through the SSH function by the way. After all, PowerShell is not very convenient!
The ssh server on WSL is not configured automatically and needs to be re installed manually. First, run the following command to check
$ sudo service ssh stop $ sudo /usr/sbin/sshd -d
If the output information includes the above information, that is, the key cannot be found, the problem can be solved by re installing openssh server
$ sudo apt purge openssh-server $ sudo apt install openssh-server
Then you need to configure / etc / SSH / sshd_ Config, run VIM with sudo permission, and modify the following three keywords
Remember to delete#
Port 22 #These two lines allow the root account and password to log in PermitRootLogin yes PasswordAuthentication yes
Then remember to restart the SSH service
$ sudo service ssh restart $ sudo service ssh status
If you need to log in to the root account with a password, you also need to set the password
$ sudo passwd root
Then you can use SSH tools to connect, local direct localhost
OK, so far, our WSL has been configured.
Enjoy the experience, install nginx, redis, MySQL!
Yeah, it’s almost over.
The above is all about WSL installation.
My guest, do you want to experience wsl2?
Wsl2 was officially launched at the build conference last year.
Wsl2 comes with a real Linux 4.19 kernel, which can bring complete system call compatibility, and can upgrade and maintain directly with the help of automatic update without updating the entire subsystem of Windows Linux.
At the same time, wsl2 will run faster than the first generation of wsl1, improve the I / O performance of file system and compatibility with Linux, and can run docker container directly on the machine（
I like that, hehe）。
Let’s take a look at the WSL version we installed above,
Execute the order
wsl -l -vIf this is the result, Congratulations, WSL 1!
what? My result is not so??? How do I execute command console promptsInvalid command option？？？？
Like the following results, it’s OK. I know you will. After all, I crawled over step by step and continued to look down with me.
So, let’s move on,There are barriers to the use of wsl2。
Your system needs to meet the versionBuildTo emphasize that the build is actually a preview (unstable) version.
Therefore, there are two aspects to consider when upgrading to wsl2,
- One is whether your Windows version can keep up with it
- Can you take the risk of upgrading the preview version?
If you can’t satisfy it, then toss WSL 1 is also very good, at least experience the progress of windows.
Upgrade to internal preview first
The steps will not be written
How to get the internal preview version of windows win10
be careful:It’s not that you can use the internal preview immediately after you fill in the information application. I have to wait for windows to push it to you. I’ve been waiting for about three or four days. I find that there is an update, and then I will execute the update
wsl -l -vIt’s normal.
After the update, the main interface, the lower right corner, there will be some internal preview version of the logo…
are you ready? Now let’s start updating to wsl2 and restart the computer with me…
Update to WSL 2
Enable virtual machine platform optional components
Before installing WSL 2, the virtual machine platform optional feature must be enabled.
Open PowerShell as an administrator and run:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
RestartComputer to complete the WSL installation and update to WSL 2.
Set WSL 2 as the default version
Set WSL 2 to the default version by running the following command from within shell:
#1. WSL provides version conversion tools to convert wsl1 to wsl2, #Note that the conversion time may be long and wait patiently. If the time is too long and no response, press enter from time to time to see if there is any update wsl --set-version Ubuntu-20.04 2 #2. Set wsl2 as the default version wsl --set-default-version 2
Now we run
wsl -l -v, see that version is already 2!
Congratulations again, we have successfully upgraded WSL 1 to WSL 2!!!
A real Linux kernel system is already in your Windows!
Installing docker CE in wsl2 subsystem Ubuntu
In fact, the purpose of upgrading WSL 2 is to experience the original docker. Ha ha, come on. Since we have all followed here, let’s start!
Installing docker CE
$ curl -skSL https://mirror.azure.cn/repo/install-docker-ce.sh | sh -s -- --mirror AzureChinaCloud
Start docker and check the docker version
$ sudo service docker start $ sudo docker version
Run an app?
You said you installed it, but you ran an app to have a look at it?
There are also steps like installing docker on the official website,Verify that the docker engine is installed correctly by running the Hello world image.
$ sudo docker run hello-world
I made it. How about you?
If you are interested, you can follow up with the actual operation. After all, I have this article only after a little pit climbing up. In order to restore the real steps, WSL was installed twice.
Just like or collect is learning? It doesn’t exist!