Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • 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 2012
    • 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

September 20, 2022 LinuxQuestions and AnswersWindows 10Windows 11

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

Windows Subsystem for Linux (WSL) is a Windows feature that allows developers or testers to run native Linux apps, write scripts, and run bash commands directly from Windows. Starting with Windows 10 (2004) WSL 2 is available which uses a full-featured Linux kernel. It allows running apps or Docker containers, has a high load speed, consumes fewer resources, and supports background management, and kernel updates. Thus, you can run ELF64 apps able to access the Windows file system without using third-party ports (like Cygwin).

A Linux kernel (v4.19) image in Windows 10 is a lightweight virtual machine. To run it, you don’t need to install a full Hyper-V role. Linux system calls are translated into Windows calls on the fly without using any emulator (unlike WSL1).

By default, WSL is disabled. To enable it, open Start -> Control Panel -> All Control Panel Items -> Programs and Features -> Turn Windows features on or off, check Windows Subsystem for Linux, click OK, and restart your computer.

enable Windows Subsystem for Linux

You can enable WSL feature on Windows 10/11 using DISM:

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

or PowerShell:

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

To install WSL in Windows Server 2022 or 2004+ Semi-Annual Channel (SAC), use the Install-WindowsFeature cmdlet:

Install-WindowsFeature -Name Microsoft-Windows-Subsystem-Linux

Then you need to restart your computer.

Intel VT (Intel Virtualization Technology) or AMD-V support must be enabled in the BIOS/UEFI settings of your computer.

Then update WSL to version 2. To do it, go to https://docs.microsoft.com/windows/wsl/wsl2-kernel, download wsl_update_x64.msi, and install it.

Install Windows Subsystem for Linux on Windows 10 and 11

To make WSL2 a default architecture for new Linux distros, run the following command:

wsl --set-default-version 2

Then open Microsoft Store and enter “Linux” in the search bar. Select the distro you need from the list. Ubuntu, Debian, Kali Linux, SUSE Linux Enterprise Server15, openSUSE Leap 15-1, Fedora Remix for WSL, and others are available. In our example, we will use Ubuntu 20.04 LTS. Then click Get.

Install WSL image from Microsoft Store

If you have Microsoft Store disabled or you want to install a WSL on the Windows Server Core edition, you can download an Ubuntu WSL image using the Invoke-WebRequest PowerShell cmdlet:

Invoke-WebRequest https://aka.ms/wslubuntu2004 -OutFile ubuntu-2004.zip –UseBasicParsing

Extract the archive with PowerShell:

Expand-Archive -Path .\ubuntu-2004.zip

Run the installation of the Linux image using the Ubuntu.exe file.

You can also download the image as an appx file and install it using Add-AppxPackage cmdlet.

After the installation, you can view the installed WSL version using this command:

wsl --list –-verbose

wsl get version

If your Linux environment has version 1, you need to change it to WSL2:

wsl --set-version Ubuntu-20.04 2

A virtual hard disk file with the OS Linux Ubuntu 20.04 is located in the user profile: C:\Users\username\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState.

After the distribution has been installed, its icon appears in the Start menu. To start Ubuntu, open the Start menu, click its icon and the Bash shell will open. You can also start WSL using the wsl command. The first time you run the image, you will be prompted to create a user and password. To run commands as root, use an additional key (prefix): sudo. WSL has common commands for Bash and CMD, and you should remember that Linux is case-sensitive.

You can run Linux commands in CMD. To do it, you must first specify WSL. For example, to view the list of files and folders in your Windows directory, run the following commands:

wsl
ls /mnt
ls/mnt/c

access windows file system from wsl

wsl ls ‑la /proc/cpuinfo
wsl ls ‑la “/mnt/c/Program Files”

run bash commands in wsl

You can also open Windows Explorer using explorer.exe, Calculator (calc.exe), Notepad (notepad.exe), Paint (mspaint.exe), Calendar (cal), and Weather (curl wttr.in).

run apps in WSL2

Another useful feature: you can open a WSL file from Windows using its system path. To do it, enter the file path in CMD:

notepad \\wsl$\Ubuntu-20.04\home\1122.txt

You can update the list of Ubuntu packages from the console using the following commands:

sudo apt-get update
sudo apt-get upgrade

After the update, the …/LocalState folder will take up 1.5 GB.

From the Linux command prompt, you can view Windows files and folders, and access them. To make it more convenient to copy files, view directories and their contents, install Midnight Commander using the following command:

sudo apt-get install mc

You can run Midnight Commander both in Bash and in CMD. The screenshot below shows that both MC panels display the list of files from both OSs.

Midnight Commander on WSL

You can display network settings (an IP address) of your WSL subsystem:

ip addr | grep eth0

Apps with graphic interfaces don’t work in WSL. However, you can try to install and use them. To run graphic apps in Linux, download and install VcXsrv Windows X Server (https://sourceforge.net/projects/vcxsrv/) on Windows.

install VcXsrv Windows X Server

Use the apt-get package manager to install graphic apps. For example, a browser, a text editor, or anything else:

sudo apt-get install gedit
sudo apt-get install firefox
sudo apt-get install x11-app

Then create a file in the root directory:

cd /~
vim .bash_login

Add the following line:

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0

and save the file:

Esc -> :wr -> :q

Then you can run graphic Linux apps in WSL using the commands:

firefox

or

gedit

You can install multiple Linux distros on Windows 10/11 and run them simultaneously in different WSL spaces. You can display the list of all installed WSL distros in Windows with the command:

wsl --list –all

To stop all running Linux distributions and the WSL2 kernel, run the following command:

wsl --shutdown

0 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

Using Previous Command History in PowerShell Console

January 31, 2023

How to Install the PowerShell Active Directory Module...

January 31, 2023

Enable Internet Explorer (IE) Compatibility Mode in Microsoft...

January 27, 2023

How to Disable or Uninstall Internet Explorer (IE)...

January 26, 2023

How to Delete Old User Profiles in Windows?

January 25, 2023

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

  • Using Previous Command History in PowerShell Console

    January 31, 2023
  • How to Install the PowerShell Active Directory Module and Manage AD?

    January 31, 2023
  • Finding Duplicate E-mail (SMTP) Addresses in Exchange

    January 27, 2023
  • How to Delete Old User Profiles in Windows?

    January 25, 2023
  • How to Install Free VMware Hypervisor (ESXi)?

    January 24, 2023
  • How to Enable TLS 1.2 on Windows?

    January 18, 2023
  • Allow or Prevent Non-Admin Users from Reboot/Shutdown Windows

    January 17, 2023
  • Fix: Can’t Extend Volume in Windows

    January 12, 2023
  • Wi-Fi (Internet) Disconnects After Sleep or Hibernation on Windows 10/11

    January 11, 2023
  • Adding Trusted Root Certificates on Linux

    January 9, 2023

Follow us

woshub.com
  • Facebook
  • Twitter
  • RSS
Popular Posts
  • 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
  • How to Fix the ‘Too Many Open Files’ Error in Linux?
  • Installing PowerShell Core on Linux Distros
Footer Logo

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


Back To Top