Skip to the content.

CentOS WSL2

Enabling WSL2

  1. Enable WSL

    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    
  2. Enable Virtual Machine Platform feature

    Required for WSL2.

    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
    
  3. Set default WSL version

    (Optional)

    wsl --set-default-version 2
    

Import CentOS image

  1. Download latest image named CentOS-8-Container-8*.x86_64.tar.xz from http://cloud.centos.org/centos/8/x86_64/images/.

  2. Extract layer.tar file from the downloaded archive.

  3. Import the image

    wsl --import centos8 opt\wsl\centos8 layer.tar --version 2
    

    The first argument centos8 is name that will be later used to reference this distribution.

    The second argument opt\wsl\centos8 is path to a directory (it may not exist, the parent directory must) where the distribution will be installed in.

    The third argument layer.tar is path to the extracted system image.

    Import can be verified by listing all available distributions:

    PS > wsl -l -v
    NAME            STATE           VERSION
    centos8         Stopped         2
    

Running the distribution

wsl -d centos8

The centos8 is distribution name used when importing the image.

Provided a distribution is marked as default by

wsl --set-default centos8

it can be later invoked just by

wsl

Custom user

The image doesn’t define any extra users so bash will start under root user. If you create your own user, WSL can be configured to be start using this user - see guide Add your user part of Using Fedora 33 with Microsoft’s WSL2 article.