Saturday, September 20, 2025

WSL: Restoring a Distro from a Backup

This article discusses restoring a WSL distro from a backup TAR file. In a previous entry, the backup process for a WSL distro was presented: WSL: Backing Up and Deleting a Distro. Restoring from a backup is a bit more complicated because the wsl --import command requires that the "install location" be specified, but knowing where the default path used by WSL to install virtual disks (*.vhdx files) is important.

Microsoft documentation, Import any Linux distribution to use with WSL, presents the full wsl --import command as follows:

wsl.exe --import <Distro> <InstallLocation> <FileName> [Options]
Options:
    --version <Version>
    --vhd

To see the location where virtual disks are stored, run the following from a PowerShell console window:

$regKeyPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss'
Get-ChildItem $regKeyPath |
  Get-ItemProperty |
  Select-Object DistributionName, BasePath

An example of the output from the above command is as follows:

DistributionName    BasePath
----------------    --------
docker-desktop      \\?\C:\Users\jann\AppData\Local\Docker\wsl\distro
docker-desktop-data \\?\C:\Users\jann\AppData\Local\Docker\wsl\data
Ubuntu-24.04        C:\Users\jann\AppData\Local\wsl\{e3757a3a-1cb5-4208-b9c2-5f6f7490cda8}

From the above output, the default location used by WSL is:

C:\Users\jann\AppData\Local\wsl

Notice the GUID in the path, meaning WSL creates a random folder name — a GUID (e.g., {e3757a3a-1cb5-4208-b9c2-5f6f7490cda8}) — for the distro instance.

C:\Users\jann\AppData\Local\wsl\{e3757a3a-1cb5-4208-b9c2-5f6f7490cda8}

For the sake of example, the following InstallLocation could be used when importing an instance of Ubuntu-24.04:

C:\Users\jann\AppData\Local\wsl\Ubuntu-24.04Host00

The distro name must be unique so run the following comment to see the current distros installed.

wsl -l -v

An example of the output generated by wsl -l -v is as follows:

  NAME                   STATE           VERSION
* docker-desktop         Stopped         2
  docker-desktop-data    Stopped         2
  Ubuntu-24.04           Running         2

From the list of names, choosing Ubuntu-24.04 as the name for the imported distro would be invalid.

For our example, the following parameters will be used:

  • Distro Ubuntu-24.04Host00
  • InstallLocation: C:\Users\jann\AppData\Local\wsl\Ubuntu-24.04Host00
  • FileName: C:\Backups\20250921Ubuntu-24.04.tar

In the blog, WSL: Backing Up and Deleting a Distro, a backup TAR file named 20250921Ubuntu-22.04.tar was created. The steps described in the blog were used to create a backup of a clean Ubuntu-24.04 WSL distro and the full back up file was placed at:

C:\Backups\20250921Ubuntu-24.04.tar

The full command to import the back up is as follows:

wsl --import Ubuntu-24.04Host0 'C:\Users\jann\AppData\Local\wsl\Ubuntu-24.04Host00' 'C:\Backups\20250921Ubuntu-24.04.tar'

The import took tens of seconds compared to the export, which took minutes. Once complete, wsl --import displays status:

The operation completed successfully.

After import, always verify by running, wsl -l -v, which shows Ubuntu-24.04Host0 was created:

  NAME                   STATE           VERSION
* docker-desktop         Stopped         2
  Ubuntu-24.04Host0      Stopped         2
  docker-desktop-data    Stopped         2
  Ubuntu-24.04           Stopped         2

Friday, September 19, 2025

WSL: Backing Up and Deleting a Distro

Before deleting a WSL distro and , say, upgrading to a new version**,** it is often wise to back up the existing distro. This blog covers the steps to perform this task.

Step 1: List Installed Distros

From a PowerShell console run the following:

wsl -l -v

This will show you the name, version, and state of each distro. One of my WSL instances shows the following when wsl -l -v is run:

  NAME                   STATE           VERSION
* docker-desktop         Stopped         2
  Ubuntu-22.04           Stopped         2
  docker-desktop-data    Stopped         2
  Ubuntu-24.04           Running         2

For this example, the distro Ubuntu-22.04 will be backed up and then deleted.

Step 2: Export the Distro (Backup)

The wsl command’s --export option allows a backup of a distro to be saved to a file in TAR format. The command is as follows for my distro, Ubuntu-22.04:

wsl --export Ubuntu-22.04 C:\Backups\20250921Ubuntu-22.04.tar

Once initiated, the export operation will display a message such as the following:

Export in progress, this may take a few minutes.

Once completed, the export operation will display a message including the size of the exported TAR file:

Export in progress, this may take a few minutes. (1167 MB)

The backup TAR file can be imported later using the wsl command. The exporting process can take several minutes, unlike deleting a distro which is instantaneous.

Step 3: Delete the Distro

The distro is backed up, so it can safely be deleted as follows with wsl:

wsl --unregister Ubuntu-22.04

Although the command-line option is --unregister, it completely deletes the distro from WSL. No warning prompt will be given. The command just runs nearly instantly:

PS C:\blogs\wslscratchpad> wsl --unregister Ubuntu-22.04
Unregistering.
The operation completed successfully.



WSL: Always Specify the Distro Version When Installing

The distros on my WSL courtesy of running wsl -l -v from PowerShell are as follows:

  NAME                   STATE           VERSION
* Ubuntu                 Running         2 
  docker-desktop         Stopped         2 
  docker-desktop-data    Stopped         2

I know from experience that the named Ubuntu is actually: Ubuntu 22.04 LTS (Jammy Jellyfish). It would be helpful if the distro name actually contained information such as the version 22.04.

When I installed a few years ago, I used the following command, where the name Ubuntu means “install the latest distro”:

wsl --install -d Ubuntu

The problem with this generic/latest approach is that the distro is simply named Ubuntu. 

It makes more sense to install the distro by specifying the version, such as:

wsl --install -d Ubuntu-22.04
wsl --install -d Ubuntu-24.04

Running wsl -l -v again from PowerShell shows the distros with their version numbers:

  NAME                   STATE           VERSION
* docker-desktop         Stopped         2
  Ubuntu-22.04           Stopped         2
  docker-desktop-data    Stopped         2
  Ubuntu-24.04           Running         2


QED: Quod Erat Demonstrandum


Visual Studio: Finding Using Statements Added to Source Code by Visual Studio

In a previous post (Visual Studio: Disabling Add Using Statements on Paste), I showed that Visual Studio has a feature that adds using statements to C# files even when a project takes advantage of project-level global usings. And yes, this feature does turn itself back on (see below -- it's back):



Periodically, in a large project, I like searching for these superfluous using statements. The way to do this is to use a regular expression. From Visual Studio, select Find in Files, which is under Edit → Find and Replace → Find in Files (CTRL+SHIFT+F). In the search textbox, paste the following regular expression:

(?m)^using\s+

Make sure you select the "Use regular expressions" checkbox in the "Find and Replace" dialog (see below):


File types can be *.* or *.cs. Click on "Find All" and purge away.

Below is ChatGPT's breakdown of the regular expression,  (?m)^using\s+ :


Thursday, September 18, 2025

Windows 11: Updating WSL to the Latest Verson

In this vlog I will show you how to update your WSL (Windows Subsystem for Linux) on a Windows host.

I found myself using a backup laptop for a project. I ran the following to check the WSL version from a PowerShell terminal window running as administrator:

wsl --version

The output was as follows:

WSL version: 2.3.26.0
Kernel version: 5.15.167.4-1
WSLg version: 1.0.65
MSRDC version: 1.2.5620
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.26100.6584

ChatGPT Pointed out my WSL was released November 2024: 

WSL 2.3.26 with kernel 5.15.167.4

The latest version is WSL 2.5.10 , released August 2025.

I ran the following from the PowerShell terminal:

wsl --update

Which installed WSL 2.6.1, so ChatGPT was incorrect saying 2.5.10 was the latest.

Out of caution I ran:

wsl --shutdown

The double-checked with:

wsl --version 

This showed I was up to date with WSL 2.6.1:

WSL version: 2.6.1.0
Kernel version: 6.6.87.2-1
WSLg version: 1.0.66
MSRDC version: 1.2.6353
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.26100.6584






Monday, July 14, 2025

Removing Windows News Widget using PowerShell

Even on a professional laptop Microsoft places a news widget that forces unwanted political content and inane celebrity news on its users. In a previous post I showed how to remove this unwanted feature from Windows: Windows 11: Remove Microsoft News Widget. In the aforementioned blog, the winget command was used to remove the widget. Unfortunately winget is not available on every corporate version of Windows.

To remove this widget for the current user, perform the following PowerShell command:

Get-AppxPackage MicrosoftWindows.Client.WebExperience | 
    Remove-AppxPackage


To remove for all users, perform the following PowerShell command while running as an administrator:

Get-AppxPackage -AllUsers MicrosoftWindows.Client.WebExperience |
    Remove-AppxPackage -AllUsers

Tuesday, June 24, 2025

Azure: Web App Viewing Deployed Files

I have a web app that needs to invoke an executable. Said executable is missing. So in Azure I must:

1. Open portal.azure.com
2. Navigate to the specific Web App
3. For Web App, use the left menu and select Development Tools | Advanced Tools | Go


4. If warned that you are leaving portal.azure.com, select Continue.

This opens the Kudu site at:

https://<your-app-name>.scm.azurewebsites.net/

Kudu is an advanced deployment and management engine behind Azure App Services, which also covers Web Apps.

From the menu select Debug Console and pick your favorite console: CMD or PowerShell




Under Linux navigate to:

site/wwwroot/

Under Windows navigate to:

C:\home\site\wwwroot