Skip to main content

Windows Subsystem for Linux 2

Windows Subsystem for Linux 2 (WSL 2) requires Windows 10 Insider Preview Build 18917 or higher and Hyper-V hypervisor.

Keep updating

22 September 2020: What’s new in the Windows Subsystem for Linux – September 2020

Check Microsoft Windows version using ver command.

C:\Users\tuyen>ver

Microsoft Windows [Version 10.0.18922.1000]

Install/Enable Microsoft-Windows-Subsystem-Linux feature using Powershell. MUST RESTART.

PS C:\Windows\system32> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
PS C:\Users\tuyen> wsl --status
Default Version: 2
Please enable the Virtual Machine Platform Windows feature and ensure virtualization is enabled in the BIOS.
For information please visit https://aka.ms/wsl2-install
PS C:\Users\tuyen>

Install/Enable VirtualMachinePlatform feature using Powershell. MUST RESTART.

PS C:\Windows\system32> Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

Install Kali Linux

PS C:\Users\tuyen> wsl --install -d kali-linux
Installing: Kali Linux Rolling
Kali Linux Rolling has been installed.
Launching Kali Linux Rolling...
PS C:\Users\tuyen>

List distributions

C:\Users\tuyen>wsl --list --verbose
  NAME            STATE           VERSION
* kali-linux      Stopped         1
  Ubuntu          Stopped         1
  Ubuntu-18.04    Stopped         1

C:\Users\tuyen>wsl -l -v
  NAME            STATE           VERSION
* kali-linux      Stopped         1
  Ubuntu          Stopped         1
  Ubuntu-18.04    Stopped         1

C:\Users\tuyen>
Windows Subsystem Linux 2

wsl command syntax

C:\Users\tuyen>wsl --help
Copyright (c) Microsoft Corporation. All rights reserved.

Usage: wsl.exe [Argument] [Options...] [CommandLine]

Arguments for running Linux binaries:

    If no command line is provided, wsl.exe launches the default shell.

    --exec, -e 
        Execute the specified command without using the default Linux shell.

    --
        Pass the remaining command line as is.

Options:
    --distribution, -d 
        Run the specified distribution.

    --user, -u 
        Run as the specified user.

Arguments for managing Windows Subsystem for Linux:

    --export  
        Exports the distribution to a tar file.
        The filename can be - for standard output.

    --import    [Options]
        Imports the specified tar file as a new distribution.
        The filename can be - for standard input.

        Options:
            --version 
                Specifies the version to use for the new distribution.

    --list, -l [Options]
        Lists distributions.

        Options:
            --all
                List all distributions, including distributions that are currently
                being installed or uninstalled.

            --running
                List only distributions that are currently running.

            --quiet, -q
                Only show distribution names.

            --verbose, -v
                Show detailed information about all distributions.

    --set-default, -s 
        Sets the distribution as the default.

    --set-default-version 
        Changes the default install version for new distributions.

    --set-version  
        Changes the version of the specified distribution.

    --shutdown
        Terminates all running distributions.

    --terminate, -t 
        Terminates the specified distribution.

    --unregister 
        Unregisters the distribution.

    --help
        Display usage information.

C:\Users\tuyen>

Upgrade Ubuntu-18.04 distro from version 1 to version 2

C:\WINDOWS\system32>wsl -l -v
  NAME            STATE           VERSION
* kali-linux      Stopped         1
  Ubuntu          Stopped         1
  Ubuntu-18.04    Stopped         1

C:\WINDOWS\system32>wsl --set-version Ubuntu-18.04 2
Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
Conversion complete.

C:\WINDOWS\system32>wsl -l -v
  NAME            STATE           VERSION
* kali-linux      Stopped         1
  Ubuntu          Stopped         1
  Ubuntu-18.04    Stopped         2
Upgrade Ubuntu distro to version 2

Unregister Ubuntu distro

C:\Users\tuyen>wsl -l -v
  NAME            STATE           VERSION
* kali-linux      Stopped         1
  Ubuntu          Stopped         1
  Ubuntu-18.04    Running         2

C:\Users\tuyen>wsl --unregister Ubuntu
Unregistering...

C:\Users\tuyen>wsl -l -v
  NAME            STATE           VERSION
* kali-linux      Stopped         1
  Ubuntu-18.04    Running         2

C:\Users\tuyen>

Upgrade Kali Linux distro to version 2

C:\Users\tuyen>wsl --set-version kali-linux 2
Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
Conversion complete.

C:\Users\tuyen>wsl -l -v
  NAME            STATE           VERSION
* kali-linux      Stopped         2
  Ubuntu-18.04    Running         2

C:\Users\tuyen>wsl --exec kali-linux

C:\Users\tuyen>wsl -l -v
  NAME            STATE           VERSION
* kali-linux      Running         2
  Ubuntu-18.04    Running         2

C:\Users\tuyen>

Set default version for new distros to version 2

C:\Users\tuyen>wsl --set-default-version 2
For information on key differences with WSL 2 please visit https://aka.ms/wsl2

C:\Users\tuyen>

Set Ubuntu-18.04 as default distros

C:\Users\tuyen>wsl -l -v
  NAME            STATE           VERSION
* kali-linux      Stopped         2
  Ubuntu-18.04    Stopped         2

C:\Users\tuyen>wsl -s Ubuntu-18.04

C:\Users\tuyen>wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-18.04    Stopped         2
  kali-linux      Stopped         2

C:\Users\tuyen>
(wsl --export Ubuntu-18.04 e:\wsl\Ubuntu-18.04.tar.gz) -and (Remove-AppxPackage -Package $(Get-AppxPackage -Name *Ubuntu18*).PackageFullName) -and (wsl --import Ubuntu-18.04 e:\wsl\Ubuntu-18 e:\wsl\Ubuntu-18.04.tar.gz)

Unregister a distribution (delete too)

C:\Users\tuyen>wsl -l -v
  NAME                  STATE           VERSION
* kali-linux            Stopped         2
  sles15-1              Stopped         2
  Ubuntu-18.04          Stopped         2
  openSUSE-Leap-15.2    Stopped         2

C:\Users\tuyen>wsl --unregister sles15-1
Unregistering...

C:\Users\tuyen>wsl -l -v
  NAME                  STATE           VERSION
* kali-linux            Stopped         2
  Ubuntu-18.04          Stopped         2
  openSUSE-Leap-15.2    Stopped         2

C:\Users\tuyen>

Known issues

Cannot change file permission: Refer to https://stackoverflow.com/questions/63575988/wsl2-fail-to-change-file-permissions

File /etc/wsl.conf

# Enable extra metadata options by default
[automount]
enabled = true
root = /mnt/
options = "metadata,umask=22,fmask=11"
mountFsTab = false
# Enable DNS – even though these are turned on by default, we'll specify here just to be explicit.
[network]
generateHosts = true
generateResolvConf = true

Popular posts from this blog

Linux command: Check Current Shell

What is your current shell ?

Java: Free Online Courses

The Java™ Tutorials by Oracle The Java Tutorials are practical guides for programmers who want to use the Java programming language to create applications. They include hundreds of complete, working examples, and dozens of lessons. Groups of related lessons are organized into "trails". https://docs.oracle.com/javase/tutorial/ Learn to Program in Java at edX.ogr Get started on the path to becoming a software engineer by learning core coding skills in Java—one of the most popular programming languages. https://www.edx.org/course/learn-to-program-in-java-0 Java Tutorial by javapoint.com https://www.javatpoint.com/java-tutorial Java Tutorial by SoloLearn.com I love SoloLearn because I can learn Java - and other popular programming languages - anywhere, any time on your mobile devices. https://www.sololearn.com/Course/Java/ Java on Azure https://docs.microsoft.com/en-us/learn/paths/java-on-azure/

Powershell: Get-ChildItem

List, search/find files and directories with Get-ChildItem cmdlet.