Windows Subsystem for Linux 2.0

in #windows4 years ago

image.png

Microsoft released Windows Subsystem 2.0 to the general public. Although it has been available for a while to insider builds it has been a long wait to reach the main release channels.

What is Windows Subsystem For Linux

Before I talk about 2.0, let me explain what Windows Subsystem For Linux is (WSL)

Microsoft Windows has always maintained some form of Linux compatibility, but it has always been very basic until WSL was announced.

WSL enables support for a full-blown Linux install inside your Windows Desktop. What makes WSL stand out is that it is not an emulator. WSL runs native Linux binaries right in Windows.

There are some limitations to WSL though you should be aware of, it does not have direct access to the hardware so you cannot do things like run X Windows GUI programs, gaming, GPU machine learning, or anything that needs direct access to devices. While this is a big limitation, for 98% of use cases this is not a roadblock.

WSL runs a full distribution of Linux, you can choose from any of the following:

  • Ubuntu
  • openSUSE Leap
  • SUSE Linux Enterprise Server
  • Kali Linux
  • Debian Linux

You can find the actual distribution in the Windows Store but first, you need to install WSL support before you can use it.

What is new with Windows Subsystem for Linux 2.0

While WSL 1.0 works great and will allow you to have a full Linux based development environment inside of Windows, 2.0 adds some nice features.

Full Linux Kernel

Microsoft has built a full kernel for WSL 2.0 with optimizations for WSL. This allows for greater speed and smaller size than WSL 1.0. It also allows Microsoft to provide updates to the kernel automatically.

Managed VM

This is the feature I have been really excited about. While on the surface it isn't a huge change, combined with a full Linux kernel, you can now run Linux containers (i.e. Docker) with full native support.

Docker was always wonky on Windows, with WSL 2.0 this becomes seamless and efficient.

Full System Call Compatibility

While WSL 1.0 was natively executing Linux binaries, it still required a translation layer to manage system calls. WSL 2.0 now supports a full Linux kernel avoiding the need for a translation layer.

This allows you to use a wider range of Linux applications and quicker access to newer Linux kernels.

These three features allowed for native Docker support to be added.

I/O Performance

I/O performance has been greatly improved with WSL 2.0. Performance has been increased as much as 20x over WSL 1.0. One of the things I hated about WSL 1.0 is how slow things like git, npm, and apt were. This improves these types of applications dramatically.

If you haven't used WSL yet, it is really one of the greatest things Microsoft has done in the last 10 years (outside of VS Code).

I'll continue this tutorial in future posts over the next few days to cover installation, upgrading, and using WSL. I got a really cool trick that will blow your mind in the 2nd or 3rd post in this series.

If you use Windows and you are a developer, you owe it to yourself to check out WSL.


Securely chat with me on Keybase

Why you should vote me as witness

Sort:  

what should my build number say to know if its supported?

  1. Look in Program and Features and if you see “Virtual Machine Platform” as an installable option then you have WSL 2 support. I’ll make a post tomorrow on how to install and upgrade.

well what i really meant is im still on 1909 and from what i remember reading you need version 2004 or something.

I typed 2004 but looks like it auto corrected on my iPhone. But yes you are right, build 2004.

and I will say you are right on it being released but so far it seems to be a phased roll out. where it may take time for it to reach everyone

Do a forced Windows Update, you should have it.

so far i only found KB4497165 but i still need to restart to install it

I am about checking if mine suppoets it. Thanks for getting us informed.

This is something new to me. I have banged my head hard many times to deploy and maintain my microservices in windows. This can get handy for me and make my life easier. Thanks for the heads-up. Let me explore and see.

I really looking forward to WSL2!

But this happens if you bought a Microsoft Surface Pro 7 and want to upgrade 😆
image.png

That happened when you ran the upgrade assistant?
https://www.microsoft.com/en-us/software-download/windows10

Same, Microsoft messed up with their own Hardware incompatible with the 2004 update.

Waiting for a fix 😀

Source:
https://www.computerworld.com/article/3561635/bumps-on-the-road-to-the-win10-version-2004-rollout.html

I still haven't tried this. I have Win10 on my PC, but hardly ever use it as Ubuntu does all I need. It is good that Windows users have access to the power of Linux, but is anyone other than developers using it?

Probably not. It really shines for development, but I don't think it's really a big deal for most other users since you can't use GUI applications natively. (well you can, but not directly.)

I've been a user of WSL v1 since it was pre-release and they got it to a nice place. For performance, I found disabling Windows Defender entirely or on specific folders like node_modules really sped things up.

I tried WSL and have been following along with the earlier releases. Sadly, I've noticed that WSL 2 is a lot slower for certain operations. For instance, try deleting a node_modules folder using rm -rf and it takes a lot longer than WSL, noticeably.

Running Npm commands like install or Git commands is also noticeably slower. Not sure what they did to screw things up, but if you check out the issues on GitHub the slowness is widespread. Many (including myself) have gone back to WSL v1. The lack of constant FS interop seems to be the issue, but it's probably a few things causing the problems.

Thankfully, I have a MacBook Pro I do a majority of my development on with a nicer shell and better performance.

Are you sure? WSL 2 claims to be 2-5x faster for git/npm style I/O ops and up to 20 times faster for things like apt.

I noticed a huge performance boost with WSL 2.
Apt and npm was dog shit slow on WSL 1. Just doing apt update && apt dist-upgrade made me want to throw my computer out the window.

In fact, it's pretty close to native performance on Windows.

Full disclosure, I run a fast machine. Quad 4.8Ghz, 32GB Ram, NVME drives.

Are you using the older insider edition of WSL 2? Maybe try the latest mainstream release in 2004.

EDIT:

Another thing, you want to use the Linux file system for the best performance, if you are using Windows file system via WSL, you will have a penalty on I/O performance.

I still don’t like it.. just because spinning a VM is faster and more performant in short term.

But things might change.

It's as fast as a VM if not faster, but with the Windows integration, there is a lot of cool stuff you can do that you can't do with a VM.

I agree with that... but for me still a play toy to support their agenda.

They need to complete the integration so that Windows users give it a try.

I like it... but due to the way things are... would not build an infrastructure based on it yet. But definitely worth to experiment with.

Have you seen the integration they have done within Windows, it is quite slick.

Full native explorer integration and file system allow you to do some really seamless productivity. Especially when you start using VS Code.

Yeap... that's basically Cygwin =) Same thing to me.

I am not against it... and forgive me if I did not make the right impression, it looks good... but because I know what's bellow... I am basically "bahhh" still...

Probably going to be very nice for 90% of people. But as UNIX Engineer... I find this not yet ready for enterprise-level stuff...

For development and people wanting to do experiments... 100% there! For security and business infrastructures? Nahhhh... not yet.

Ahhhhh. I got about 9 kinds of excited but then realized this is a MS product and allows the running of Ubuntu in Windows.

Alas, I need to go the other way. About 10 years ago I'd had all of MS that I could take (a 2 hour update in the midst of an important to me project) sent me to Linux to stay. My desktops and laptops from then on were strictly Linux.

I really like that MS is doing this, people can and will find the utility of open source OS. For me, I'd really like access to a few bits of software that simply isn't available to me.

Wow, this is great now I don't have to worry much about if something is supported in Windows or not. But Windows always have this licensing cost and thus even if it gives great features people will still go towards linux.

I think it is better to have a Linux VM using Vmware Workstation..

I think I need to try this, thx for share 😎

Love WSL!

Don't forget to upgrade your VMs, wsl --set-version 2, and wsl --set-default-version 2

vscode with 'remote' integration into WSL is an excellent combination. Just steer clear of windows-mounted filesystems for now, performance is awful in WSL2

Does this mean I can finally run a Hive node on my Windows Home server?
Last time I tried with VMs it was a nightmare.