Windows:- WSL – Managing distributions in Windows Subsystem for Linux – Setting Default Distribution

Background

Obviously, my working OS is MS Windows.

But, I have very brief moments with Linux.

Once every couple of moments or so.

 

Managing Distributions in Windows Subsystem for Linux

Outline

Management-wise, here are some of what we can do with WSL:-

  1. Export and Import
    • Export the distribution to a tar file
    • Import specified tar file as a new distribution
  2. List Distributions
    • List all distributions
    • List running distributions
  3. Set default distribution
  4. Target Specific distribution
  5. Status Inquiry
  6. Terminate a running distribution
  7. Unregister a distribution and delete the root file system

 

Objective

In this post, we will set our default distribution.

 

Tasks

List Distributions

List all distributions

Syntax

wsl --list

 

Sample

wsl --list -all

Output
Output – Image

Output – Textual

>wsl --list --all
Windows Subsystem for Linux Distributions:
CentOS8-stream (Default)
Ubuntu

 

Explanation
  1. We have two Linux distributions installed:-
    • CentOS8-Stream
    • Ubuntu
  2. Default Distribution
    • The default distribution is CentOS8-Stream

Default Distributions

In our particular case, our initial default install was Ubuntu.

Later, we added CentOS8-Stream.

To switch our default distro we will invoke “wsl –set-default“.

 

Syntax

wsl --set-default [distribution]

 

Sample

Let us set our default distro to CentOS8-stream.


wsl --set-default CentOS8-stream

Output
Output – Image

Output – Textual

>wsl --set-default centOS-stream

 

Explanation
  1. We were able to successfully switch our default Linux distro from Ubuntu to CentOS

 

Status Inquiry

Let us perform a quick status inquiry.

 

Syntax

wsl --status

 

Sample

Let us set our default distro to CentOS8-stream.


wsl --status

Output
Output – Image

Output – Textual
>wsl --status
Default Distribution: CentOS8-stream
Default Version: 2

Windows Subsystem for Linux was last updated on 2/21/2022
WSL automatic updates are on.

Kernel version: 5.10.16

>

 

Explanation
  1. Using “wsl –status” to query our wsl install confirmed the following
    • Default Distribution
      • CentOS8-Stream
    • Default Version
      • 2
    • WSL
      • Last Update:- 2022-Feb-21st
      • WSL is being automatically updated
    • Kernel Version
      • 5.10.16

WSL Execute Command

It is worth knowing that we do not have to start a WSL Session and manually invoke command from the WSL Shell.

We can deliver payload right from the WinOS Shell.

 

Syntax

wsl --exec [command]

 

Sample

Issue Linux command from MS Windows Shell.

In this instance, we issue a simple request.

What release version are you?


wsl --exec lsb_release -a

Output
Output – Image

Output – Textual
</pre>

>wsl --exec lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOSStream
Description: CentOS Stream release 8
Release: 8
Codename: n/a

>

 

Explanation
  1. Using “wsl –exec” to ask the Linux Substem to run the lsb_release command returns
    • LSB Version
      • core-4.1-amd64:core-4.1-noarch
    • Distribution ID
      • CentOSStrea
    • Description
      • CentOS Stream release 8
    • Release
      • 8
    • Codename: n/a

 

References

  1. Microsoft
    • WSL
      • Basic Commands
        Link

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s