My work machine used to be a laptop created by Apple. I could do almost anything on it: develop programs, write texts, compose music, and much more. But I was haunted by the thought that I was attached to the Apple ecosystem, that I was dependent on the whims of this company. So I started looking for something new.

I began to assemble a workstation for machine learning tasks. I put in it, among other things, an excellent processor, a lot of memory, a decent graphics card. Almost all of my tasks I solved in Ubuntu. True, I needed Microsoft Office to work with texts. Online Office had not yet appeared, and let's call a spade a spade, LibreOffice is just some kind of horror. For me, the solution was the dual boot in the Ubuntu configuration - Windows 10. I really liked the feeling of freedom that you experience when switching from an Apple OS to Ubuntu. And the possibilities that open to those who assemble their own computer are almost endless.

ITKarma picture

Dual boot for a long time completely suited me. And when I used it a million times, WSL (Windows Subsystem for Linux, Windows Subsystem for Linux) technology appeared. When this happened, I began to solve some of my Linux problems in Windows. True, even so, I still did not have much for full work. But now, with the release of WSL 2, I get the feeling that the new version of WSL is able to radically change the situation. Today I propose to talk about how, using WSL 2, to transfer the task of developing programs from Linux to Windows 10. I will talk about the new features of WSL 2, and what can be expected from this subsystem in the future.

WSL 2 overview


WSL 2 is the new version of the Windows subsystem for Linux. There are some changes in this version that determine how Linux distributions interact with Windows.

ITKarma picture

Microsoft loves Linux

In this WSL release, the user has improved file system performance and full compatibility with system calls. Of course, we have the ability to run Linux either on WSL 1 or on WSL 2, and, moreover, you can switch between different versions of WSL at any time. WSL 2 is the result of a major improvement in the basic architecture of the system; its new features are based on virtualization technology and on the Linux kernel functionality. At the same time, Microsoft takes care of the small details, so the WSL user can simply go about their business without distractions.

Installing


Microsoft promises that in the near future, installing WSL 2 will be very simple and that Linux can be updated using the Windows update mechanism. So far, the process of installing WSL 2 requires some effort, but, in fact, there is nothing wrong with that.

In this example, we will install Ubuntu 20.04 on Windows 10. It should be noted that the installation process will be the same for all Linux distributions available in the Microsoft Store. First you need to enable the Windows Subsystem for Linux component. To do this, open PowerShell as administrator and run the following command:

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

Next, you need to upgrade WSL to WSL 2. For this, Windows 10 must be updated to version 2004. Intel virtualization technology must be enabled in the BIOS. We will use PowerShell again with administrative privileges and run the following command:

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

To complete the WSL installation and upgrade to WSL 2, restart the computer. Then you need to install WSL 2 as the default version of WSL when installing new Linux distributions.To do this, all the same, using PowerShell with administrator privileges, execute this command:

wsl --set-default-version 2 

After you run this command, the following message may appear:

WSL 2 requires an update to its kernel component. For information please visit https://aka.ms/wsl2kernel 

ITKarma picture

Message displayed when trying to install WSL 2 as the default Windows subsystem for Linux

Follow the link and install the appropriate.msi file, thanks to which the Linux kernel for WSL 2 will be installed on your machine. After the kernel is installed, run the above command again. Now it should complete successfully without displaying a similar message.

Now all that remains is to install the required Linux distribution. To do this, open the Microsoft Store and search for Ubuntu 20.04 LTS there. After installing the distribution, a shortcut should appear on the Start menu to start Ubuntu. Start the system and follow the instructions to complete the installation (in general, the installation is completed by creating a new user).

To verify that the distribution is indeed installed on WSL 2, run the following command:

wsl --list --verbose 

If it turned out that you are using WSL 1, then you can switch to WSL 2 using a command of this kind:

wsl --set-version <distribution name> <versionNumber> 

That's all. You now have a full-fledged Ubuntu distribution running on Windows 10.

Setting up the work environment for the programmer


Now that you have working Ubuntu at your disposal, you can install everything you may need. For example, if you are a data scientist, you can install the latest Anaconda distribution. If you are a front-end developer, then you, for example, may be interested in Angular, npm, and much more. Here I would like to focus on two tools. This is Visual Studio Code and a bunch of Docker + Kubernetes.

▍Visual Studio Code


VS Code is a code editor that many developers prefer. One of the strengths of this editor is its support for an infinite number of extensions. And now that we have enabled WSL 2, the absolutely necessary extension for VS Code is Remote Development .

This extension allows you to remotely work on code that is available in an environment created by WSL 2, in a container, or even on a remote virtual machine accessed via SSH. This extension allows, for example, creating a project in Linux running WSL 2 and using the VS Code editor installed in Windows 10 to work on this project.

As a matter of fact, VS Code differs in huge opportunities. This is the IntelliSense intelligent system, and integration with git, and a debugger, and a terminal, and a lot more. I believe that you will manage to configure VS Code and very soon you will be able to make exactly what you need from this editor.

▍Docker + Kubernetes


Docker for Windows is "good", but not "excellent." In fact, it was Docker that made me constantly “jump” between Windows and Ubuntu. For example, I had to do this when I needed to create a new Docker image. But WSL 2 has full Docker support. This, I believe, is such a feature of the new subsystem that makes working with Docker even more convenient than in Linux.

To enable this feature, go to the Docker Desktop settings and enable the CDMY0CDMY option.

ITKarma picture

Enabling Docker Support for WSL 2

Moreover, by going to the Kubernetes settings section, you can enable the ability to start a local Kubernetes cluster by simply checking the corresponding box.

ITKarma picture

Enabling Kubernetes

Now you can restart Ubuntu in WSL 2 and run the following commands:

docker version  kubectl version 

The results of these commands will show that you now have Docker and Kubernetes at your disposal.

ITKarma picture

Docker and Kubernetes work in the WSL 2 environment

Bonus: new Windows terminal


As an additional useful program, you can install the new Windows terminal from the Microsoft Store /a>. The description of it says that we have a new modern application - fast, effective and powerful. It is intended for users who work with command-line tools and related environments, like PowerShell. Among its main features are the following: support for tabs and panels, support for Unicode and UTF-8, acceleration of text output using GPU, support for custom themes, styles and settings.

Here video about the new Windows terminal.

Moreover, the new terminal looks very good, and its appearance is customizable. Settings can be made using a special JSON file. Here you can find themes for the terminal. Here is a material where you can read more about the terminal.

WSL development plans


WSL 2 still lacks some features, but the Windows subsystem for Linux is developing in the right direction. In the near future, you can install WSL with a single command. To do this, it will be enough to open the Windows terminal and do the following in it:

wsl.exe --install 

In addition, WSL 2 will be the version of the subsystem that, when you first install WSL, is installed by default.

It should be noted that developers are looking forward to the following features from WSL: support for graphics cards and support for applications with a graphical interface.

Since the release of WSL 1, the development team of this subsystem has most often asked to implement CUDA or GPU Compute support in WSL. In the latest code, the development team of WSL, virtualization systems, DirectX, Windows Driver are working on this feature. Therefore - stay tuned.

ITKarma picture

Training a model using deep learning technology in WSL 2 (using CUDA)

Moreover, on the way and support for graphical applications for Linux. For example, on Linux systems installed on WSL, you can use text editors or IDEs. You can even develop GUI applications for Linux on a Windows machine!

ITKarma picture

Linux GUI Support in WSL 2

Summary


Today we talked about how, using WSL 2, you can turn a Windows computer into a workstation of a programmer using Linux. At the disposal of such a programmer is high performance and many useful features, a set of which, over time, will replenish. Therefore, I can say that the dual boot is dead.

А вы пользуетесь WSL 2?

ITKarma picture

ITKarma picture.

Source