WSL2 | Windows Subsystem for Linux

Hello guys

Hope you and your loved ones are safe and secure during this tough period. I am home stuck from almost 3 months and hoping that the normality will resume very soon.

So, during the lockdown I’ve decided to take some “risks” by upgrading my production computers/laptop with the forthcoming version of Windows 10 2004 for Windows Subsystem for Linux aka WSL2 using Windows Insider preview ISO.

I work with real Linux enterprise servers at work & throughout last 10 years got myself accustomed with writing simple shell scripts and other Linux specific activities, so that I can handle them as comfortable as I interact with Windows Servers. I usually don’t get in to the silly arguments like which OS is better by comparing the features & other aspects. We never had issues with Windows Servers, neither had issues with Linux servers as we maintained them meticulously.

So, why subsystem for linux is important? Well, not many have the luxury of working with Linux servers. Especially students and developers from small business which depend completely on Windows environments. Subsystem for Linux on Windows opens doors for those who desperately need Linux environment & WSL is their friend. Unlike a virtual machine hosted on Oracle VirtualBox or VMWare, the user don’t have to dedicate hardware resources specifically for WSL & environment is always available. The only feature you may lack should be the ability to start the services automatically. Well, I am sure within a short time Microsoft will figureout a way to.

Okay, let us see how we can start availing WSL2 on Windows 10 already!

Please note, if you are not ready to take the responsibility of what you are going to do, please don’t attempt the below instructions which includes upgrading your Windows 10 version with yet to be officially released version of the same OS.

Once you upgraded your Windows 10 to version 2004

You are all ready to go. Please make sure that you have all the cumulative updates applied before proceeding.

Please note, if you are using Oracle VirtualBox on regular basis, I will suggest that you reconsider proceeding further. Enabling few of the Windows 10 features for WSL2 will completely compromise/degrade the performance of the Virtualizer and you will not even able to start your virtual machines (at times)

In order to avail the WSL2 functionality, you will have to enable few additional features of Windows 10.

I am upgrading my existing WSL to WSL2. If you are trying to configure WSL for the first time, Please refer documents explaining how to thoroughly (I have few posts towards enabling WSL with my blog, you may refer them)

You need to enable “Virtual Machine Platform” and restart the computer before upgrading WSL to WSL2.

Alternatively, you may use powershell as administrator to enable these features.

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

Please note, if you are using PowerShell, make sure that after enabling the features, you will restart the computer as both shell commands have /norestart switch

Once you restart the computer, you can try to upgrade your existing WSL to WSL2

Either from elevated PowerShell or CMD issue the following command

wsl --set-default-version 2

This is going to take a while, to complete. Once the upgrade has been completed you can start upgrading your existing WSL distros.

Before upgrading your WSL distros, you need to update the existing WSL kernel. Currently, you need to download and manually install the upgraded kernel, and let us hope Microsoft will include the kernel updates for WSL within their update packages.

Please visit the link https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel and follow instructions to download and install the kernel. Post installation, you can start upgrading your existing distros.

Open a command prompt as administrator and issue the following command

wsl --list --verbos

This should list all the distros you already have on your system and the corrsponding WSL version numbers associated

So, my work laptop has 2 distros and both are already upgraded to WSL2. Regardless, let us see how we can upgrade an existing WSL1 distro to WSL2

Consider my distro listing was showing VERSION information as “1” instead of “2”, then I would have issued the following command to upgrade my Ubuntu-18.04 distro

wsl --set-version Ubuntu-18.04 2

That’s all. Your distro will be upgraded to version 2.

My personal takes on WSL2

Well, my interest towards new features are limited to getting them installed and configured. I’ve had very limited handson with the upgraded Ubuntu distro and I was able to have a buttery smooth experiece with XRDP this time. To my utter surprise, Mozilla Firefox loaded without crashing & I felt I was truly interacting with a real Linux machine.

Please refer my previous posts towards WSL about installing XRDP, MySQL and other software those are usually configured on Linux environments.

Guys, almost every other tip and tricks I have listed are coming from many sites and I encourage you to visit those sites for further reading. All I have done was to put them in single place and to post this consolidated thread.

https://docs.microsoft.com/en-us/windows/wsl/install-win10

https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel

https://www.bleepingcomputer.com/news/microsoft/windows-10-2004-to-upgrade-wsl2-linux-kernels-via-windows-update/

I will be investing more time for WSL2 once after I get back to Office & hoping to post more interesting stuffs based on my findings. Until then, please stay safe and healthy.

regards,

rajesh

Advertisements

Windows Subsystem for Linux | Backup & restore

Hello guys

WSL 2 is almost here! and if you are here, reading this post. Please consider reading about WSL 2

During one of the recent chit-chats, few of my contacts were asking me about the “real” business sense behind Linux on Windows. It is simple. Microsoft is:

Going to integrate LINUX so deep within Windows that, in the very near future, one don’t have to run a separate LINUX Server. Simple like that.

After experimenting with KALI Linux WSL, I managed to install Xfce & XRDP on Ubuntu 18.04 WSL & the only few things I couldn’t do with the WSL was starting services automatically when the subsystem starts. There are hacks, well, I don’t think they really worth a try soon as Microsoft will BE bringing it on to WSL pretty soon.

Now, let us get back to the topic. I’ve installed Ubuntu 18.04 WSL nothing less than half dozen times. Every time something goes wrong & I am forced to uninstall and re-install the WSL to continue with additional experiments. My last attempt was to install Kubuntu desktop, that screwed my Xfce & after 2 days of continuous efforts to “fix” few “unknown” things, I had to uninstall one Ubuntu WSL that had a fully functional WordPress instance :(

So, I decided to learn how to backup a functional WSL, so that if something goes wrong, I can restore & continue

I’ve ready at few places that Windows 10 version 1903 comes with WSL backup functionality out of the box. Until you decide to upgrade your box to 1903, you may use the below for backing up your dear WSL instance.

I came across a pretty decent thread here & a user Jaime’s answer is the apt ONE, missing only few details like /tmp folder.

Make a tar ball as mentioned by Jaime

# cd /
# sudo tar vzcpf /mnt/c/tmp/ubuntu_`date +%Y%m%d_%H`.tar.gz --exclude=/proc --exclude=/dev --exclude=/mnt --exclude=/media --exclude=/lost+found  --exclude=/tmp --exclude=/sys  --exclude=/run / > /mnt/c/tmp/ubuntu_`date +%Y%m%d_%H`.log 2> /mnt/c/tmp/ubuntu_`date +%Y%m%d_%H`.error

Where /mnt/c is C:\> drive of your Windows Machine. You may change /mnt/c/ to /mnt/d/ or /mnt/e/, based on how your partitions are laid. Closely watch the excluded directories. You MUST exclude them.

My tar ball was around 1.5GB in size & I moved the tar ball to another machine which didn’t have WSL activated.

First you have to enable Window Subsystem for linux from Turn Windows Features on or off (If you are not restoring the backup to same Windows Machine). This will ask you to restart your Windows Machine.

Copy the tar ball to a folder, say, D:\wsl

Download launcher.exe from https://github.com/yuk7/wsldl

Copy launcher.exe to D:\wsl

If you are going to restore a Ubuntu 18.04 WSL rename launcher.exe to Ubuntu1804.exe & rename your tar ball to rootfs.tar.gz

Open an elevated command prompt & switch to D:\wsl

and just execute, for example “Ubuntu1804.exe”

It will take a while for the installation to complete. As the superuser thread states, it installs and opens the WSL for you. From next time, all you need to do is to start Ubuntu1804.exe & your WSL instance is up and running!

However, I had an issue with the restored instance. It was related to missing /tmp folder. I found a solution for it with nixcraft article.

https://www.cyberciti.biz/faq/mysqld-innodb-error-unable-to-create-temporary-file/

Prior trying to start any sevices, those you were using with your backed up instance, make sure you create the /tmp folder like below

$sudo chown root:root /tmp
$sudo chmod 1777 /tmp

Now, try to start your services, start xrdp & enjoy!

regards,

rajesh