Windows Subsystem for Linux (WSL) 2 is the latest version of the WSL family that completely changed how Linux distros interact with Windows. WSL lets you run most of the command-line tools, applications, and utilities directly on Windows without going to dual boot or traditional vm setup over Windows. With WSL 2, you can do more on your Windows by running ELF64 Linux binaries directly. There are many new improvements, such as file system performance and full system call compatibility. In this article, we shall be going through further enhancements in WSL 2.
Improvements in WSL 2:
The WSL 2 has been developed on a new stable branch, based on the source from kernel.org. This kernel was tuned explicitly for WSL2, resulting in an excellent Linux experience in Windows.
Increased file I/O performance, file intensive operations such as git clone/check out, apt update, apt upgrade is noticeably faster in WSL 2. Linux users would be happy to know that the operations mentioned above are around five times faster in WSL2 as compared to WSL 1.
Full system call compatibility, WSL 2 makes use of the Linux native system calls to perform all the operations such as accessing files, creating namespaces and accessing memory. Instead, WSL 1 makes use of the translation layer developed by the WSL team.
- Apps such as docker and kubernetes can be installed and used inside the WSL 2.
- Any updates to the Linux kernel are immediately ready for use.
WSL 2 is very lightweight, i.e. makes use of utility vm on a stable Linux kernel with very less memory on startup.
Access the Linux networking apps on Windows, and it has been confirmed for Windows that you can now access networking apps such as My SQL or Node is deployed app in your host machine using localhost.
Please note that if you are running WSL on an earlier version of Windows such as 18945 build or less, then you need to get the IP address of the virtual machine to access the n/w apps in your host machine,
- Inside your WSL distro, type “ip addr” to get the networking info.
- Under eth0 interface, find the address aside of the inet tag.
- If you have the grep tool installed, then you can quickly get the details by using “ip addr | grep eth0”
- Connect to the networking app using the IP address.
Access the Windows networking apps in Linux WSL distro; If you want to access any of the networking apps/services deployed in Windows, then you need to make use of the IP address of the host machine.
If you are not sure about the IP address of the host machine, then you need to use the below command in your Linus distro to get the address “cat /etc/resolv.conf”
Expanding the WSL 2 VHD, You can expand the size of the Virtual Hardware Disk of the WSL 2 distro easily by following the steps,
- Turn off the WSL 2 instance. (wsl –shutdown)
- Open power shell and type “Get-AppxPackage -Name “*<distro>*” | Select PackageFamilyName” to get the package name.
- Locate the VHD full path; it should be in this format “%LOCALAPPDATA%\Packages\<PackageFamilyName>\LocalState\<disk>.vhdx”
- Resize the WSL 2 VHD by executing the below commands in CMD(admin),
- Select vdisk file=”<pathToVHD>”
- expand vdisk maximum=”<sizeInMegaBytes>”
- Now launch the WSL 2 distro and run below commands to let the WSL know about the changes,
- sudo mount -t devtmpfs none /dev
- mount | grep ext4
- Copy the name, which will look like: /dev/sdXX (with the X representing any other character)
- sudo resize2fs /dev/sdXX
- You may also need to install resize2fs: apt install resize2fs
In this article, we have discussed many new improvements and features of WSL 2 over WSL 1. Currently, WSL 2 might not be available for all Windows versions. Even though it has many improvements, still you cannot access the GPU, serial or USB devices in WSL 2. In our upcoming article, we shall be discussing more on Docker and Kubernetes support in WSL 2.