As the word 'Windows Subsystem for Linux' is partially self explanatory, lets Dive deep into it!
What actually it is?
It is a layer of linux over windows that allows you to run a Linux file system, along with Linux command-line tools and GUI apps, directly in Windows OS without any need of dual boot or Virtual Machines!
If you're new to Linux and don't want to deal with installing a Linux system and dual-booting, WSL is a fantastic option. It's a simple method to get started with the Linux command line without having to master the entire operating system. Running WSL has a considerably lower overhead than running a full VM.
WSL offers choice of distributions but they are very few available in Microsoft Store.
Running WSL has a considerably lower overhead than running a full VM. While WSL 2 runs on the Linux kernel under Hyper-V, you won't see as much of a performance drop as you would with a VM because you won't be running most of the other Linux processes. You can need less memory to operate WSL than you would for a virtual machine.
WSL may be great for you if you only need command-line programs such as languages or compilers. WSL is aimed for developers, particularly those in the web development field, who don't need kernel access very often.
Difference Between WSL 1 & WSL 2
The common concept between WSL 1 & WSL 2 is same, ie running Linux Binary Executables,
WSL 1
In WSL 1 there ain't Linux,
Wonder How its running?
Between the Linux distribution and the Windows Kernel, there is a translation layer. This layer is in charge of handling all kernel-level actions and translating them into instructions that the Windows kernel can understand. Once the Windows kernel has completed its task, it will return the results to the WSL translation layer.
Here, the Linux Distribution have no idea that all its requests are handed by Windows kernel
Issues
Lets understand this with a help of an example:
Suppose on some directory DIR you have a text document named as you.txt, you open the respective document in a notepad, while the notepad is still open and if you want to change the directory DIR the windows won't allow it, it would throw some errors (like some programs are using the directory so you are not allowed to perform this operation), but in Linux you can Perform this action.
WSL 2
WSL 2 doesn't have translation layer like WSL1, instead it has full blown Linux Kernel.
Wonder how is it working without VM and having 2 Kernels?
The concept of a lightweight utility virtual machine appears. This is an extremely small virtual machine that starts in less than a second and uses very little computing power. When you install the optional feature Windows Subsystem for Linux on Windows, this virtual machine is created.
It has specially Customised Kernel that is Tuned to Run for WSL, the fantastic part is, it is Managed by Microsoft and its Open Source.
Unlike WSL 1, when a binary programme issues an instruction in WSL 2, the instruction is not translated. It's more or less turned over to the Linux kernel. Any command that the Linux kernel cannot handle is forwarded to Windows.
Steps to Install WSL in Windows
-Open Windows Power Shell as an administrator
Press Windows+R to open Run, and then type “powershell” in the text box. Now, press Ctrl+Shift+Enter. Windows PowerShell will open in admin mode.
- Copy and paste the following code in power shell admin.
Enable-WindowsOptionalFeature -Online -FeatureName
You need to Restart the computer after running the abover command
- Download your Favorite Linux Flavour from Microsoft Store!!
Install windows Terminal App from Store, it makes easier to work with command line.
Update your Linux kernel, run this command once or twice a week, updated kernel shall set your life!
sudo apt update
sudo apt upgrade -y
- The fun part!!! To get the feel of Linux, run the famous Linux Shell Train
sudo apt-get install sl
sl
- NEXT? TIME TO HAVE FUN WITH LINUX!!!! LESSSSS GO
Top comments (4)
Nice write-up 👍
And yes one point wsl 2 become useful when we want to run docker containers on windows.
Awesome, thanks for letting me know
Very Interesting !! Nice work!!
Thank You!