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

nmap - The Network Mapper

WARNING : It is ILLEGAL to scan hosts without permission.

VMware Workstation: vmrun.exe

Using vmrun.exe to manage VMs on VMware Workstation

Linux command: lspci

Linux command: lspci - list pci devices tuyendq@ubuntu001:~$ man lspci NAME        lspci - list all PCI devices SYNOPSIS        lspci [options] DESCRIPTION        lspci is a utility for displaying information about PCI buses in the system and devices connected to them.        By  default,  it  shows a brief list of devices. Use the options described below to request either a more verbose output or output intended for parsing by        other programs.        If you are going to report bugs in PCI device drivers or in lspci itself, please include output of "lspci -vvx" or even better  "lspci  -vvxxx"  (however,        see below for possible caveats).        Some  parts of the output, especially in the highly verbose modes, are probably intelligible only to experienced PCI hac...