It’s less like Power Rangers clicking rings, more like living among expats in a foreign country
- Got 64-bit?
- Windows 10 Build
- Windows Insider Build
- Enable WSL Windows Feature
- Windows Terminal
- Download installer
- Where is WSL?
- Profile to define prompt
- Linux commands
- pwd file storage mounts
- Folders and variables
- Visual Studio Code
- VHD size adjustment
- More on DevOps
I began looking into Microsoft’s WSL (Windows Subsystem for Linux) at its first “beta” release on June 2017.
Around May 2019, Microsoft released WSL2.
WSL is so much simpler than Cygwin
Here is the diagram for WSL1:
Lxcore.sys is the driver that recognizes Bash commands and other Linux utilities such as chmod to change permissions.
VFS is the Virtual File System.
From inside Bash, DrvFS gets to Windows.
From inside Windows, VolFS gets to Linux symbolic files and its case sensitivity.
NTFS (New Technology File System) is the file system controlling hard drives.
WSL provides no GPU support, so it can’t run Linux GUI programs such as Gnome, KDE, etc.
Verify your PC’s CPU architecture and Windows version/build number:
Start: Click the Windows icon or keyboard key to open Settings, System, About.
If your System type is not “64-bit”, get a computer that is. The technical explanation is that WSL currently runs ELF64 Linux binaries.
Windows 10 Build
Alternately, if you have configured PowerShell to run commands, get your Windows Server build number within PowerShell:
systeminfo | Select-String "^OS Name","^OS Version"
If your OS Build is not 18917 or higher, update.
Windows Insider Build
- Go to Settings > Update & Security > Windows Insider Program and click Get Started to access the latest build.
- Enter the account you used to sign into the Windows Insider Program.
Follow the prompts to install.
As of this writing, Windows Insider version 19041.1 was available on the slow ring. You don’t need a fast ring build to get WSL 2.
Go to Settings > Update & Security > Windows Update and click Check for updates to install.
Docker Desktop Edge 220.127.116.11 + requires Windows 10 Pro or Enterprise Insider Preview build 19018 or higher to integrate with WSL Linux.
Virtualization must be enabled in the computer bios, instructions for this vary between manufacturers but it’s usually a simple on/off listing in the BIOS.
Enable WSL Windows Feature
Press the Windows Start button and immediately type in the search box that appears:
Turn Windows features on or off
Type enough until the option appears in the menu, then click on the option.
Wait a while for all items to appear.
Scroll down to check “Windows Subsystem for Linux”, then click OK to exit dialog, then Restart your computer.
(This option was added since the “Anniversary” and “Creators Update” of Windows 10.)
Click the Windows Start and get in the Microsoft Window Store to install the new Windows Terminal. It is like tmux - it makes it easy to open multiple panes with different prompts for bash, command prompt and PowerShell.
Following instructions at https://docs.microsoft.com/en-us/windows/wsl/wsl2-install, in PowerShell, enable the ‘Virtual Machine Platform’ optional component (whatever that means):
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Confirm whether Windows Subsystem for Linux is enabled in PowerShell:
Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Set Linux distro to be backed by WSL 2
PROTIP: WSL provides a choice of Linux distributions.
- Ubuntu-18.04 - CanonicalGroupLimited.Ubuntu18.04onWindows_1804.2018.817.0_x64__79rhkp1fndgsc
- Ubuntu 18.04 ARM for running on Raspberry Pi?
- Ubuntu-16.04 - Ubuntu_1604.2019.523.0_x64.appx
- Debian GNU/Linux - DebianGNULinux_1-1-3-0_x64__76v4gfsz19hv4
- Kali Linux
- OpenSUSE Leap 42
- SUSE Linux Enterprise Server 12
- Fedora Remix for WSL (licensed)
- Pengwin is paid/licensed. Based on Debian.
- WLinux ???
PROTIP: Ubuntu was the first distro tested with WSL, so it’s probably the most well tested. But it’s not supported by Windows 10 S. Both Ubuntu and Debian make use of the apt-get (Advanced Packaging Tool) package manager and dpkg command.
BTW Ubuntu is a Linux distribution from Canonical, Inc. which also created Virtualenv for Python.
Kali Linux is used by security researchers.
From the Start menu, select the Microsoft Windows Store. Search for “Linux”. Click Ubuntu, then ‘Install’:
Once installed, the ‘Install’ button will change to ‘Launch’, click the ‘Launch’ button.
Alternately, download the “.appx” installer by constructing the curl command for the Ubuntu version listed above, such as:
curl -L -o ubuntu-1604.appx https://aka.ms/wsl-ubuntu-1604
This is instead of the Invoke-WebRequest PowerShell command or Microsoft Store for Business used within enterprises.
In PowerShell, construct the command using the name of the .appx file downloaded:
Set the distribution code for the Linux distro downloaded (I don’t know why):
wsl --set-version Ubuntu 2
Verify what versions of WSL your distros are using:
wsl -l -v
Make WSL 2 your default architecture (as if you’ll ever want to go back):
wsl --set-default-version 2 ## Launch and configure
Launch the new instance of WSL by from the Start menu section titled “WSL Linux Distros”.
The first time a newly installed distro runs, a Console window opens, and you’ll see
Installing, this may take a few minutes...
BTW: In previous versions, you had to go to Open Settings -> Update and Security -> For developers to check the Developer Mode radio button to “install any signed app”.
Installation successful Please create a default UNIX user account. The username does not need to match your Windows username. For more information visit: https://aka.ms/wslusers Enter new UNIX username: _
Enter a username your make up.
PROTIP: The WSL user is not “root” with admin priviledges.
PROTIP: Type the password in 1Password or other Password Manager, then copy it to paste in the screen.
A shortcut is added to your start menu named:
Bash on Ubuntu on Windows
Click the shortcut so you don’t have to type “bash”.
By default, the prompt is your Linux user name @ your machine name:/mnt/c/Users/%USERNAME%$
Where is WSL?
PROTIP: WSL runs within the Vemmem process.
Open Task Manager to see it.
Read the FAQ for known weirdness.
Bugs with WSL are reported to developers at https://github.com/microsoft/WSL
Profile to define prompt
Open the Bash command prompt</strong> (click Windows Start and type Bash until you can select it from the list that arises).
Open the Visual Studio Code text editor to the file in the $HOME folder, which is what ~ stands for, just like in macOS:
By default, WSL reads and executes commands from the file /etc/profile if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. It skips the other files if one is found.
Define keyboard aliases in a .bash_aliases file in the .bashrc file *
My list is in https://github.com/wilsonmar/git-utilities/master/aliases.sh
Get to know the built-in Linux commands: cat, cd, chmod, chown, curl, df, diff, echo, exit, find, finger, grep, groups, gzip, head, history, kill, less, ls, man, mkdir, mv, passwd, ping, ps, pwd, shutdown, ssh, sudo, tail, tar, top, uname, w, whoami. There’s also cp.
Rather than a translation layer built by the WSL 1 team, WSL 2 includes its own open-sourced Linux kernel with full system call compatibility with the LTS Linux kernel. WSL2 does not work under HyperV.
Sean Dearnaley points out that since macOS currently doesn’t have good GPU support, if Windows introduces GPU support for WSL, Windows machines could become a very powerful machine learning development platform when running Nvidia CUDA based apps.
pwd file storage mounts
To list drives mounted:
The response is the drives:
c d f
For the purpose of this tutorial, create folder dev/project for use by both Windows and Linux tools:
cd /mnt/c/dev/ mkdir project
You can also make whatever directory name you want.
PROTIP: Use $HOME or ~ to reference your home folder:
cd ~ pwd
Unlike/users on macOS, the folder above user accounts is:
Open Windows Explorer to view files from both Windows and from Bash:
Access files from both Windows and from Bash as:
Run a Linux utility such as disk usage of the current folder (represented by a dot):
The response is like 56K .
View the manual on the du command:
PROTIP: Remember this move whenever you see that “:” in the lower-left corner:
type q to quit out.
Folders and variables
See where Ubuntu is installed using a Windows system variable referenced using a Windows % wrapper rather than Bash $ prefix:
Note the directory is marked as a hidden system folder. That’s a clue that you should not modify files in your bash environment using Windows File Explorer, console, or apps.
Creating and/or modifying files in this location using Windows tools and apps corrupts the system because it is read-locked. Here is an explanation.
Install the LinuxBrew fork of Homebrew for macOS*
“I found some apps that didn’t work well from apt-get worked flawlessly when installed with brew, like zplug. Inversely, I couldn’t get ranger to work with brew but got it working with apt-get. This very conveniently gives you multiple options for installing a package, potentially skipping the step of Googling vague errors.
To fix the patchelf error:
sudo apt-get update sudo apt-get install build-essential
TODO: Use brew to install Docker Desktop Edge, in Technical Preview as of this writing.
Sean Dearnaley provides pointers. It now supports Kubernetes, offers VPN-friendly networking, provides an updated Docker daemon, and many new features.
Visual Studio Code
VIDEO: Run and debug your Linux-based applications from within VSCode in Windows. Edit files in WSL or the mounted Windows filesystem (/mnt/c) without worrying about pathing issues, binary compatibility, or other cross-OS challenges.
TODO: Use brew to install additional utilities: git, Python/pip, tree, jq, etc.
Use pip to install Virtualenv.
Install keyboard aliases to use custom commands:
NOTE: To run Python for Selenium controlling Firefox, install Xming with gekoDriver.
VHD size adjustment
WSL 2 stores Linux files inside of a VHD (Virtual Hard Disk) using the ext4 file system. VHD has an initial max size of 256GB. If your distro grows beyond that you will see errors stating that you’ve run out of disk space. To expand VHD size:
Terminate all WSL instances:
Find your distro installation package name ‘PackageFamilyName’.
In a powershell prompt (where ‘distro’ is your distribution name) construct:
Get-AppxPackage -Name "*distro*" | Select PackageFamilyName
Locate the VHD file fullpath used by your WSL 2 installation, this will be your ‘pathToVHD’:
Resize your WSL 2 VHD:
Open a command prompt Window with admin privileges and run the following commands:
In the dialog:
Select vdisk file=”pathToVHD”
expand vdisk maximum=”sizeInMegaBytes”
Launch your WSL distro.
Make WSL is aware that it can expand its file system’s size by running these commands in your WSL distro:
sudo mount -t devtmpfs none /dev mount | grep ext4
Copy the name of this entry, which will look like: /dev/sdXX (with the X representing any other character), making sure to use the value you copied earlier.
sudo resize2fs /dev/sdXX
You may need to use:
apt install resize2fs
Links and issues for this:
published 15 June 2016 by Jack Hammons, who writes:
https://blogs.msdn.microsoft.com/wsl, the home page of WSL.
https://medium.com/free-code-camp/how-to-set-up-docker-and-windows-subsystem-for-linux-a-love-story-35c856968991 “Yeah, it seemed to have uninstalled linuxbrew as soon as I closed the Ubuntu shell. Although my path references in .profile seemed to persist”
More on DevOps
This is one of a series on DevOps:
- ci-cd (Continuous Integration and Continuous Delivery)
- Git and GitHub vs File Archival
- Git Commands and Statuses
- Git Commit, Tag, Push
- Git Utilities
- Data Security GitHub
- GitHub API
- Choices for DevOps Technologies
- Java DevOps Workflow
- AWS DevOps (CodeCommit, CodePipeline, CodeDeploy)
- Cloud services comparisons (across vendors)
- Cloud regions (across vendors)
- Azure Cloud Onramp
- Azure Cloud
- Azure Cloud Powershell
- Digital Ocean
- Packer automation to build Vagrant images
- Terraform multi-cloud provisioning automation
Hashicorp Vault and Consul to generate and hold secrets
- Powershell Ecosystem
- Powershell on MacOS
- Jenkins Server Setup
- Jenkins Plug-ins
- Jenkins Freestyle jobs
- Docker (Glossary, Ecosystem, Certification)
- Make Makefile for Docker
- Docker Setup and run Bash shell script
- Bash coding
- Docker Setup
- Dockerize apps
- API Management Microsoft
- Scenarios for load