WSL Linux Distros on Microsoft Store
WSL Linux Distros on Microsoft Store

I recently bought myself a new laptop and found that the process for setting up the Windows Subsystem for Linux (abbreviated to WSL) has changed a lot since I last set it up when it was still in beta. Anyway as my original notes were now out of date and as WSL has now been officially released I thought the process was worth documenting.

What is the WSL?

First up I guess I should at least give a brief description of what the Windows Subsystem for Linux actually is. In short it’s a way of running Linux commands natively on Windows. For now this is restricted to command line based tools but this gives you all of the goodness of a Linux shell from within Windows without the need for a virtual machine.

Microsoft cannot guarantee that it’s 100% compatible with every Linux executable out there but I haven’t come across anything yet that’s caused me any issues.

One thing to watch out for though is you may have to install certain tools within the subsystem even if you already have it installed in Windows. I have been playing with tools like Terrafrom, Vagrant and Ansible recently and have been confused no end installing in both Windows and Linux until I could get them to play nice together…

Anyway some of that will hopefully be detailed in future posts. On to the installation process for WSL.

The installation process varies depending on which version of Windows 10 you are currently running. I found Microsoft’s installation notes very useful. These notes cover the different installation methods so this may be a useful resource if the process changes again. For now though I thought I would detail the process myself on the current version of Windows 10 as of mid 2018.

Removing the beta version of WSL

If, like me, you installed the WSL when it was first released as a beta you need to get rid of it before installing the official version. This is quite simple to do using the lxrun command. Run up PowerShell as Admin, a quick way to do this to hit Windows-X followed by A, and run the following command:

> lxrun /uninstall /full
Warning: lxrun.exe is only used to configure the legacy Windows Subsystem for Linux distribution.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore

This will uninstall Ubuntu on Windows.
This will remove the Ubuntu environment as well as any modifications, new applications, and user data.
Type "y" to continue:

Enter “Y” and it should completely remove the beta installation.

WSL installation process on Windows 10

One thing to bear in mind before starting this process is that you are likely to need a reboot after installation so make sure you’re not in the middle of any unsaved work before you start.

The WSL is now an optional Windows feature than can just be enabled from the PowerShell. The reference to the term optional feature initially confused me though as there is a Manage optional features option within the Apps & features tab of the Apps section in the new Windows Settings screen, but this doesn’t have the option for the WSL and doesn’t even list it once it has been installed.

Ignoring this dual meaning of optional features the process is fairly straight forward. Simply run up PowerShell as Admin and enable the Windows Subsytem for Linux with the following command:

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

This will run through the installation process. Once completed you may be prompted for a restart:

Do you want to restart the computer to complete this operation now?
[Y] Yes [N] No [?] Help (default is "Y"):

If so the just select “Y” to get it out of the way.

Choose your Linux Distro

Now you can install the Linux of your choice from the Microsoft Store. Open the Store app and search for WSL or Run Linux on Windows:

When I first did this I’m sure I saw a Fedora logo but that seems to have disappeared and Fedora still is not available so I chose Ubuntu, which was the only option during the beta anyway so I’ve had a bit of a play with it already. I have used Fedora heavily in the past so it would have been nice to stick to what I know as the little differences can catch you out…

Click on the Get button to install the specific flavour of Linux. Once installed you can pin a link to the start screen and/or the task bar. To achieve the latter you need to click the three dots to the side of the Pin to Start options and click the appropriate item in the sub-menu that pops up.

Now you can launch your chosen Linux. The installation make take while. While this is happening you might want to tweak the properties:

I recommend making these setting changes to both the Defaults and Properties. Choose a suitable font size and turn on QuickEdit Mode, which makes copy and paste much easier:

Then set the Screen Buffer Size to allow for a decent amount of scrolling back. Try 1000 as that seems a reasonable value to start with:

Once the installation is complete the first step is to create a local user. One thing to bear in mind here is that Linux is case sensitive so Pete is a different user to pete. The standard is to use all lower case. Unless you have a regular username then I suggest just using your first name for this.

If you know a bit about Linux then although root is an option it’s best not to use it for security reasons. This does have the downside that you have to sudo everything…

Now you have a version of Linux running on your Windows 10 machine!

Update to the latest version

Typically this may not be the latest version though so there is still one more step (note the -d specifies developer release which occur more frequently):

$ sudo do-release-upgrade -d

The first time you use sudo in a session you will be prompted for your password. You only have to enter your password once though and then you can run sudo commands as much as you like.

This may prompt for various responses during the update. At the time of writing I got a few. One of which was whether or not to replace the config file for the SSH server:

As this is a new install there will not be any manual changes to the config file. This means there is likely no benefit in keeping the local version. I suggest installing the package maintainers version as shown in the above image.

Another prompt will confirm the removal of packages that are no longer relevant to the updated version:

Searching for obsolete software
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading state information... Done

Remove obsolete packages?


28 packages are going to be removed.

 Continue [yN]  Details [d]

It makes sense to get rid so simply enter “Y”. Then the last one is to confirm the update has completed and request a restart:

System upgrade is complete.

Restart required

To finish the upgrade, a restart is required.
If you select 'y' the system will be restarted.

Continue [yN] 

Don’t panic here as this will not restart Windows. It’s meant to restart the Linux system but as that is running inside Windows, rather than on a standalone system as expected, this isn’t actually possible. I would still recommend hitting “Y” and then you should get the following:

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to talk to init daemon.
=== Command terminated normally (Wed Jul 18 21:14:56 2018) ===

Now you should close the bash terminal window and next time you open it you will be running the latest version of Ubuntu.

Apply any package updates

Linux distribution releases only happen once or twice a year. Packages on the other hand can be updated a lot more frequently. The update process can vary between distributions though. To ensure everything is up to date you can run the following commands for Ubuntu:

$ sudo apt update
$ sudo apt upgrade
$ sudo apt auto-remove

This should be done regularly. If you don’t use the WSL frequently then it may be useful to run these commands every time you use it.

Signature

2 comments

Nanu

I’m read sudo apt update all finished. But” System has not been booted with systemd as unit system (PID 1).Can’t operate. ” Message have. How to kill this problem?

    Pete O'Shea

    I have tried the above on a few different PCs without any issue so I’m happy it works, at least it did when I last tried it. I haven’t seen that message before so not sure how to help I’m afraid.

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.