Saturday, September 20, 2025

WSL: Keeping a Pristine (Greenfield) Version of Your Distro

WSL has a limitation. Once you install a distro using wsl --install, you cannot just install a second copy of the same distro. The way to get around this is to install the latest distro, such as Ubuntu 24.04, and then make a backup of the pristine distro so that it can be duplicated later via import. It seems like something that should just be an option in wsl --install, but alas, it is not. 

In this article I will walk you through the steps required to create this pristine copy of a distro. I will also show you how to name your distro in WSL something besides Ubuntu or Ubuntu 24.04. 

To demonstrate a new hence pristine instance of a distro must be installed on WSL. This topic was covered in a previous blog WSL: Always Specify the Distro Version When Installing. Moving forward I will not be doing any work on this distro. See the following demarcated n boldface (courtesy of running wsl -l -v):

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

For example, on the Ubuntu-24.04 distro I will not install any Azure-related packages or Azure AI packages. Ubuntu-24.04 is my pristine/clean/greenfield distro, and any project-specific work will be done by making a copy.

Once a new distro is installed, I like updating the distro to use the latest packages by running:

sudo apt update
sudo apt upgrade -y

Once the packages are installed, clean up any unused packages by running:

sudo apt autoremove -y

On my personal machines I like disabling the sudo prompt, which was covered in this is blog, Ubuntu/Linux: Disable sudo Password Prompt. This means that each copy of the distro instance will also have sudo disabled.

Once the pristine/clean/greenfield distro is patched, make a backup of it by following the steps in WSL: Backing Up and Deleting a Distro, and obviously do not delete the current distro.

When I start a new project, such as my Azure AI Foundry work, I will create a new distro named for the project. It will be a suitable name like AzAiUbuntu-24.04, and I will follow the steps here to import an instance of the distro with the aforementioned name (see WSL: Restoring a Distro from a Backup).

To create (import) a project-specific distro I would use these parameters:

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

Finding the default WSL distro folder path, C:\Users\jann\AppData\Local\wsl, was discussed in WSL: Backing Up and Deleting a Distro.

Using the aforementioned parameters, I can create a per-project WSL distro instance without modifying my pristine master copy:

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

After the project specific distro instance is created (imported) the output from wsl -l -v is as follows where our newly imported/created VM is demarcated in bold:

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


No comments :

Post a Comment