Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Windows 10 / Install Windows Subsystem for Linux (WSL 2) on Windows 10/11

October 25, 2023 LinuxWindows 10Windows 11

Install Windows Subsystem for Linux (WSL 2) on Windows 10/11

Windows Subsystem for Linux (WSL) allows you to run native apps, write scripts, and run bash Linux commands and scripts directly from within Windows without the need for emulators or separate virtual machines. The current version of the environment is WSL 2, which uses the full Linux kernel (version 5.15) and provides full system call compatibility. The WSL Linux kernel image is a lightweight virtual machine that doesn’t require the full Hyper-V role to be installed to run.

Contents:
  • How to Install Windows Subsystem for Linux (WSL2)
  • Installing Linux Distros on Windows (WSL)
  • Basic Commands for WSL on Windows
  • How to Use Windows Subsystem for Linux (WSL)

You can run WSL 2:

  • On Windows 10 1903+, Windows 11, and Windows Server 2022;
  • Hardware virtualization support must be enabled in the computer’s BIOS/UEFI settings: Intel VT (Intel Virtualization Technology) or AMD-V (SVM Mode).

How to Install Windows Subsystem for Linux (WSL2)

WSL is disabled by default on Windows. In the latest versions of Windows 10 and Windows 11, you can install the WSL environment with just a single command:

wsl --install

This command will automatically enable all the necessary Windows features required for WSL, install the Linux kernel update for WSL2, download the Ubuntu distribution (by default), and install it in WSL.

wsl --install windows command

All that remains is for you to restart your computer and your WSL environment is ready for use!

You can install a different Linux distro for WSL. List valid distribution available for WSL:

wsl --list --online

Specify the Linux distribution name you want to install to WSL. For example:

wsl --install -d kali-linux

list available wsl linux images

If virtualization is not enabled in your computer’s BIOS/UEFI, there will be an error message during WSL installation:

Installation failed with error 0x80070003 or error 0x80370102” it means that Bios Level Virtualization is not enabled on your computer.

You can manually install WSL2 on Windows. To do this, you must manually perform all the steps that the wsl –install command performed automatically:

  1. Install WSL and VirtualMachinePlatform features;
  2. Install the WSL 2 kernel;
  3. Download and install the Linux distribution for WSL.

First, install the following optional Windows components

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

Install Microsoft-Windows-Subsystem-Linux command

Then you need to restart your computer.

Download and install the WSL2 Linux kernel update package for x64 machines (https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi). You can download the update manually or with PowerShell:

Invoke-WebRequest -Uri https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi -OutFile "$($env:userprofile)\Downloads\wsl_update_x64.msi" -UseBasicParsing
Invoke-Item "$($env:userprofile)\Downloads\wsl_update_x64.msi"
rm "$($env:userprofile)\Downloads\wsl_update_x64.msi"

Install Windows Subsystem for Linux on Windows 10 and 11

Restart your computer and set WSL 2 as the default environment:

wsl --set-default-version 2

set wsl2 as default subsystem

Installing Linux Distros on Windows (WSL)

Once the WSL kernel has been installed on Windows, you will be able to install one or more Linux distros on your computer.

You can install a package with a Linux distribution from the Microsoft Store. The following Linux versions are available for download:

  • Ubuntu
  • Debian
  • Kali Linux
  • OpenSUSE
  • Oracle Linux
  • SUSE Linux Enterprise Server
  • Fedora

Find the Linux version you want in the Store and install it by clicking the Get button.

Install WSL image from Microsoft Store

If you have disabled the Windows Store, and want to install WSL on a Windows Server Core instance, or on an offline computer (disconnected from the Internet), you can use the Invoke-WebRequest PowerShell cmdlet to download the Ubuntu WSL image file:

Invoke-WebRequest https://aka.ms/wslubuntu2204 -OutFile ubuntu-2204.appx –UseBasicParsing

Install the WSL package as a regular APPX application:

Add-AppxPackage .\ubuntu-2204.appx

Once installed, a window will appear asking for a username and password for your Linux distro.

set wsl linux password

A separate app shortcut for starting WSL Linux will appear in the Start menu after installation.

open wsl from windows start menu

Basic Commands for WSL on Windows

Let’s look at the basic commands for managing the Linux kernel and distributions in WSL.

Check the current WSL core version:

wsl --version

check wsl version

You can manually update the WSL kernel:

wsl --update

Rollback to the previous WSL kernel:

wsl --update rollback

List the Linux versions installed:

wsl --list

Get the default Linux distribution:

wsl --status

Change the default Linux distro in WSL:

wsl --setdefault Ubuntu

list installed linux versions in wsl

Run a specific Linux distribution in WSL:

wsl -d kali-linux

Terminate the WSL environment:

wsl --shutdown

You can login to WSL Ubuntu as root and reset its password:
ubuntu config --default-user root
passwd

Restore default user for WSL:
ubuntu config --default-user your_username

Config files can be used to configure parameters for WSL and Linux distros:

  • wsl.conf – a file with settings for a specific Linux distro (located in the /etc directory)
  • .wslconfig – global settings that are common to all WSL distros (located in the user profile folder %UserProfile%)

For example, to limit computer RAM and CPU usage for all Linux distributions in WSL, create the file %UserProfile%\.wslconfig, contains the following config:

[wsl2]
memory=4GB
processors=2

How to Use Windows Subsystem for Linux (WSL)

The Linux distribution that is installed in the WSL is a fully-fledged operating system. It is therefore recommended to update the packages after installation. On Ubuntu, run the command:

$ sudo apt-get update && sudo apt-get upgrade -y

apt update in ubuntu wsl image

The file system of the WSL Linux distribution is stored in the user profile as a VHDX file. For example, Ubuntu’s virtual disk is in %USERPROFILE%\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState.

wsl ext4 vhdx disk image file

If there is no free space on the system drive, you can move the WSL image file to another disk.

The Linux file system in the WSL is mounted as a shared folder and can be accessed directly from File Explorer.

access wsl file system from windows file explorer

You can also have direct access to WSL files from Windows via a UNC path. For example:

notepad \\wsl$\Ubuntu\sysops\home\mytext.txt

Conversely, WSL will mount local Windows drives to /mnt directory. You can list files on the C: system drive from Linux:

wsl
ls /mnt
ls/mnt/c

run bash commands in wsl

Other examples of running Linux commands from Windows:

dir | wsl grep Sa
wsl ls ‑la > 123.txt
wsl ls ‑la /proc/cpuinfo
wsl ls ‑la "/mnt/c/Program Files"

You can install any package on Linux. For example, install the Midnight Commander file manager:

$ sudo apt-get install mc

Midnight Commander on WSL

You can use the usbipd-win package to access host USB devices from WSL.

The modern version of WSL 2 lets you run any Linux GUI application (X11 and Wayland) from Windows. For example, you can install the GIMP graphics editor in Ubuntu WSL:

$ sudo apt install gimp -y

Now you can start Gimp on Windows using the command:

wsl gimp

1 comment
0
Facebook Twitter Google + Pinterest
previous post
How to Remove RD Session Host from Remote Desktop Services Deployment
next post
Manage VPN Connections with PowerShell in Windows

Related Reading

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

How to Increase Size of Disk Partition in...

October 5, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

Installing Language Pack in Windows 10/11 with PowerShell

September 15, 2023

1 comment

Jason September 20, 2023 - 1:09 pm

I am unable to enable Windows Subsystem for Linux on my machine as get the following error code. “windows could not complete the requested changes. An illegal character was encountered. For multibyte character…

error code =0x80070246”.

Moreover, i am unbale to run sfc /scannow command which gives the following error.
“C:\Windows\system32>sfc /scannow

Beginning system scan. This process will take some time.

Windows Resource Protection could not perform the requested operation.”

Also, i am unable to install some updates too. Error Code = 0x80070246

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Fixing ‘The Network Path Was Not Found’ 0x80070035 Error Code on Windows
  • Recovering Files from BitLocker Encrypted Drive
  • How to Access VMFS Datastore from Linux, Windows, or ESXi
  • Using iPerf to Test Network Speed and Bandwidth
  • Installing an Open Source KMS Server (Vlmcsd) on Linux
  • How to Enable Two-Factor Authentication (2FA) for SSH on Linux
  • Install and Configure SNMP on RHEL/CentOS/Fedor
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top