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:-
- Export and Import
- Export the distribution to a tar file
- Import specified tar file as a new distribution
- List Distributions
- List all distributions
- List running distributions
- Set default distribution
- Target Specific distribution
- Status Inquiry
- Terminate a running distribution
- 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
- We have two Linux distributions installed:-
- CentOS8-Stream
- Ubuntu
- 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
- 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
- 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
- Default Distribution
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
- 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
- LSB Version
References
- Microsoft
- WSL
- Basic Commands
Link
- Basic Commands
- WSL