Sunday, July 8, 2018

Running Linux on Windows (WSL)

Running Linux on Windows (WSL: Windows Subsystem for Linux)

The Windows Subsystem for Linux is fully available in Windows 10 release 1709 (Fall Creators Update). This lets you drop into bash from a Windows command prompt. The default distributions available in the Microsoft Store are Ubuntu, openSuse Leap, SUSE Linux Enterprise Server, Debian, and KALI. But what if you want to run another version like CentOS or similar? That's where RoliSoft's WSL Distribution Switcher comes into play. This python based set of scripts allows you to download Docker hub versions of Linux and run them from the WSL command line. Here's what I had to do to get CentOS 7 running on my Windows 10 machine.


Installing WSL Feature in Windows 10

From the Windows search bar type Windows Feature and you should see the "Turn Windows Features On and Off" program.

Scroll all the way to the bottom of the list and you should now see the "Windows Subsystem for Linux". Check the box to the left and click OK to install. Please note, this will require a reboot of your computer to complete.

Install Python3 for Windows

I have written a separate blog post on installing Python 3.7 for Windows. You can view that here.

Install WSL Distribution Switcher

Before you can run the WSL Distribution Switcher Python scripts, you'll need to prep the WSL environment so everything will work properly. The two basic commands related to WSL you'll need to run are lxrun.exe and wslconfig. By default there isn't a Linux distribution loaded after the WSL feature is enabled. If you only wanted to run one of the distributions available from the Microsoft Store you could simply go there and download/install your flavor of choice. However if you want to run a distribution not currently available on the store, this is what you'll need to do.

Install the Legacy WSL Ubuntu distro:
lxrun.exe /install

Next run the following to verify that the distribution is installed:
wslconfig /list /all

You'll see where any previously installed distributions from the Microsoft Store (Ubuntu in this example) are installed and set to the default. In order for the Distribution Switcher scripts to run however, we need the Legacy distro as the default.

wslconfig /s legacy

In order for everything to install smoothly, the root account needs to be the default user for the bash shell. To set this run:
lxrun /setdefaultuser root

Now that everything is properly prepared for the Distribution Switcher scripts, the installation should run normally. CD to the directory where you downloaded the WSL Distribution Switcher Scripts, in this example E:\Linux and run the installer:
python3 centos:latest

You can see from the above screenshot CentOS 7.5 is installed and I was able to update via a yum update command. To get to the Linux shell from a Windows command prompt simply type bash.

You can now install other Linux distributions from the WSL Distribution Switcher as necessary.

Here's a repository list they support:

1 comment: