Windows

Learn how to use wsl, the windows 10 subsystem for linux

For many years, the only ways to use Linux alongside Windows have been either to install a Dual-Boot with both operating systems (being able to use only one at a time), or to mount a virtual machine with the second operating system on her. Linux and Microsoft have been rivals for many years, and they have been competing for the trust of users. However, and for the good of all, this rivalry has turned into friendship, and for some time we can do what we could never imagine before: install Linux on Windows 10. This is WSL.

WSL, Windows Subsystem for Linux, or Windows Subsystem for Linux, is a feature introduced in Windows 10 that allows us to install a Linux Kernel directly on the Microsoft operating system. This is possible thanks to Microsoft’s Hyper-V virtualization, and by doing so we will be able to access all the commands and all the terminal programs of this operating system directly from a CMD window.

The installation of Bash Linux on Windows is a very fast and simple process that hardly requires any configuration. In addition, it is very safe, since although it can access the Windows file system and interact with the Microsoft operating system, nothing we do in this Linux will be able to make Windows 10 stop working. A simple reinstallation of Linux will get everything back to normal. Also, since only the kernel is loaded, it is a very light implementation that hardly influences the overall performance of the PC.

WSL Advantages

The Windows Subsystem for Linux can be useful both for amateur users who are beginning to take the first steps in this operating system as well as for advanced users and system administrators.

The main purpose of WSL is to allow sysadmins and programmers to use all Linux tools and services directly from Windows without having to virtualize anything else or mount complicated infrastructures. In the end, we will be able to do everything we could do if we installed Linux in a virtual machine or on another PC, and we used it from a terminal or TTY. All Linux commands should work fine on Windows, like apt or dpkg. We can even compile code directly from here with the advantages that Linux provides in this regard.

But this implementation is also useful for users who are taking their first steps within Linux systems. Thanks to it, any user can have all the Linux tools at their fingertips without having to configure or virtualize anything. And furthermore, you can be sure that if something goes wrong, you will only have to reinstall the distro in WSL, as Windows 10 will not be compromised.

Furthermore, although it is not yet available, in the future it will even be possible to run programs with a graphical interface.

Disadvantages and limitations

One of the main limitations of WSL is that it is not a native kernel, but depends on Hyper-V. And this leads to a series of problems and drawbacks, such as scalability and performance when executing certain tasks. We must also note that WSL1 does not have kernel-level support, so some programs, such as Docker, will not work. This has already been fixed in WSL2.

The network connectivity works at WSL, but must go through several layers. This implies a considerable loss of performance when executing processes that work at a low network level. And furthermore, there are peripherals that don’t work properly also due to how Hyper-V controls this Linux.

WSL1 vs WSL2

With the May 2020 Update for Windows 10, Microsoft brought users WSL2, an updated and improved version of WSL1. The main difference between the first version and the second version of this subsystem is that while the first one ran in an intermediate layer between the hardware and the operating system, now WSL2 has its own Hyper-V virtual machine that, together with A kernel specially compiled for this purpose, allows to interact much better with system calls, improving performance and all the possibilities it offers us.

WSL2 has a native hypervisor that allows running a real kernel directly on Windows. With this, all performance problems and compatibility with services and programs are solved, even achieving a performance improvement of up to 500% when performing certain tasks. The input and output of data has also been considerably improved, being able to even access them from the file explorer itself, and it is also now much faster and easier to change distribution.

WSL2 vs virtual machine

So what advantages (and disadvantages) does WSL2 bring compared to installing Linux on a virtual machine like VirtualBox or VMware? The first difference is that while a Linux in a virtual machine is isolated, WSL2 is fully integrated with Windows, so both systems can interact with each other. Furthermore, the Windows Subsystem can load Linux in just one second, whereas a virtual machine is considerably slower to boot.

The consumption of resources is also very considerable. While WSL2 is very light and uses very little RAM, a virtual machine consumes much more resources in this regard.

And, while it is true that a virtual machine offers more control and more customization options, Windows Subsystem for Linux only runs when we need it, and it only loads the processes and services necessary for what we need to do.

If we don’t know which system to use, we recommend using a virtual machine when:

  • We need to get the most out of Linux.
  • Let us have a scalability forecast based on production levels.
  • We want to use an operating system with a graphical environment interface and applications.
  • Let’s go network intensive where performance is essential.

And we can opt for WSL when:

  • We want to run basic Linux commands.
  • We want to spend little memory and few PC resources.
  • We need storage efficiency.
  • We do not want / can / know how to use virtual machines.
  • We want quick access to the file system, and interact with the Windows file system directly.

How to activate Bash in Windows 10

The process to be able to use Linux from Windows 10 is mainly divided into two parts. The first one is to activate the Linux Subsystem for Windows. To do this, in the Windows 10 search section we must search for ” Windows Features ” to open the tool that allows us to activate or deactivate the advanced tools and services of the system.

In the new window that will appear we will have to activate two boxes. The first one will be Hyper-V, in order to activate the Windows 10 hypervisor, and the second one will be the Windows Subsystem for Linux.

We accept the changes, restart the PC when requested, and when the computer reboots it will be ready to run Linux.

From PowerShell

If we prefer, we can do the same by executing the following commands in a PowerShell window with Administrator permissions. The first step will be to prepare the system to install this optional feature with:

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

We restart the PC and then we will execute this command that will allow us to enable Hyper-V in our system:

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

And the second, activate the Windows subsystem for Linux.

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

With a CMD command

In addition, if we have a version of Windows 10 equal to, or greater than, 2004, or 20H1, with the arrival of WSL2 we can also activate this console with a simple CMD command:

wsl --install

Important: update Ubuntu Kernel for WSL2

It is likely, especially if we have ever used WSL1, that when we move to this new version of the Windows Subsystem for Linux we will see a message like «WSL 2 requires an update to its kernel component. For information please visit https://aka.ms/wsl2kernel ». What this message means is that we must update the Linux Kernel in Windows in order to use the subsystem.

This process is very simple. All we have to do is access this link, download the installer and install it on our PC. Clever. After restarting the computer we will have the updated Kernel, and WSL2 will work without problems.

Download Linux on Windows 10

We already have WSL activated, but at the moment it is useless. In order to start using it, we have to download the distro that we want to install in our Windows 10. Although little by little there are more distros adapted to this subsystem, the number of available alternatives is still quite limited. And it is not worth downloading them from anywhere, but we have to download them from the Microsoft Store.

We can find all the WSL distros from the Microsoft Store by typing “Linux” in the store search engine.

The main distributions that we can find are the following.

Developer: Canonical Group Limited

Developer: SUSE

Developer: Kali Linux

Developer: The Debian Project

Developer: agowa338

We downloaded the distro we want from the store and installed it in Windows 10. It would be ready to start using it. But first of all we are going to make sure that we use version 2 of WSL to be able to enjoy its advantages. We can do this by opening a PowerShell window with Administrator permissions and executing the following command, changing “distro” by the name of the distro that we have downloaded.

wsl --set-version distro 2

If we don’t know the name of the distro, we can see all the ones we have installed with the command:

wsl --list --quiet

This command will take a few minutes to run. When finished, we will have our WSL2 with the distro that we have chosen ready to use.

Upgrade from WSL to WSL2

If we have already created a WSL1 system on the PC, and we want to be able to take advantage of the improvements offered by the new WSL2 subsystem, then what we must do is execute the following command in the CMD window to indicate to the system that we want the current distro from WSL to WSL2.

wsl --set-version nombre_distro 2

We must change “distro_name” to the name of the distro in question. We can see the installed distros (and their names) with the command:

wsl --list --verbose

First use

The first time we open the distro, it will begin an automatic installation and configuration process. This process will not take long, and at one point it will ask us to specify the username and password that we want to give it.

After this initial configuration, our Linux within Windows 10 will be ready to use. But first of all, we must update it. We can do this easily the same as if we updated Linux on a real computer or a virtual machine. Just run:

sudo apt update && sudo apt upgrade

How to open Linux in Windows 10

Thanks to WSL we will be able to use Windows tools and programs directly from CMD or PowerShell. To do this, we simply have to execute the “wsl” command, followed by the command we want to execute, in the PowerShell window. For example, “wsl ls” will show us the content of the current directory.

But if we want to have direct access to the terminal of the Linux distro, then what we must do is look for the launcher of the distro installed in the Windows start menu, and run it from there. We can also run the “bash.exe” command from PowerShell to launch the full Linux deployment on Windows.

The WSL console will have an appearance similar to that of a Linux terminal, and we will differentiate it because, in addition to the distro logo appearing in the title bar of the window, we can see that the lines begin with user @ computer.

Use WSL2 with graphical environment

Microsoft has not yet enabled the WSL graphical environment. This will arrive in the future (not too distant) as part of a WSL2 update. But while it arrives, if we want to be able to use the Windows subsystem for Linux as if it were a virtual machine, with the mouse and the windows, it is necessary to resort to external projects. And the most advanced is Win-KeX.

Win-KeX, or Windows Kali Desktop eXperience, is a graphical environment developed by those responsible for Kali Linux to allow users to use this subsystem in graphical mode. This loads us a remote desktop window (by VNC) and allows us to use the Kali distro as if it were an operating system installed, for example, in VirtualBox. In addition, it has a mode that allows us to integrate it together with the Windows desktop so that we can use Linux and Windows programs at the same time.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button