Automated deployment with WSL –import: from zero to production

Last update: 29/10/2025
Author Isaac
  • Import distros from tar with wsl --import and standardize environments.
  • Automate with wsl.conf and, where appropriate, with cloud-init.
  • Export/Import for quick backups and restores.
  • Integrates Docker and WSL 2 for reproducible and efficient workflows.

Automated deployment with WSL import

If you work in Windows But you want the tools of Linux, WSL and the wsl –import command allow you to import any distro in tar format and leave it ready to work without going through the Microsoft StoreThis approach opens the door to truly rapid deployments, reproducible environments, and backups that are restored in a flash.

Furthermore, with WSL 2 you can Automate system settings with wsl.conf and, in certain distributions, with cloud-initYou can also export and share images, integrate Docker, and even run Linux GUI applications natively. In the following lines, you'll see how to build the tar archive, import it, fine-tune the distribution (default user, DNS, mounts), create and restore backups, resolve the common issue of missing "import" in the WSL help, and set up a production-ready hybrid WSL 2 + Docker workflow.

What does wsl –import solve and when to use it

The command wsl –import allows you to install any distribution from a tar fileEven if no package exists in the Store. Ideal for: teams seeking centralized control, enterprise deployments, custom images that already include packages and dotfiles, or rapid recovery scenarios following a system failure.

The basic syntax is straightforward and flexible, pointing to an installation directory and a tar file with the rootfs from the distro:

wsl.exe --import <NombreDistro> <RutaInstalacion> <ArchivoTar>  

If you organize yourself well, You can save your distros under E:\wslDistroStorage\ to maintain order and separate data from the system disk, minimizing surprises in reinstalls or breakdowns.

Import Linux distributions into WSL using tar

How to obtain the tar file of a distribution

To import something, you first need the tar file. You have two easy paths: download an official rootfs (for example, the Mini Root Alpine Filesystem) or generate the tar by exporting a Docker container from the distro you are interested in.

The Docker path is very practical because It guarantees you a clean, reproducible, and easy-to-version system. with your minimal dependencies. Below is an example with CentOS running within a WSL distro using Docker.

Example: Creating a CentOS tar archive with Docker

Boot a Linux distro installed from the Microsoft Store (for example, Ubuntu in WSL) and Make sure you have Docker running. (Docker Desktop or the Docker service within the distro itself).

# Inicia Docker si lo tienes en la distro WSL
sudo service docker start

# Lanza un contenedor CentOS con un nombre identificable
docker run -t --name wsl_export centos ls /

# Exporta el contenedor a un tar en C:\temp
docker export wsl_export > /mnt/c/temp/centos.tar

# Limpieza
docker rm wsl_export

By the end, You will now have centos.tar ready to import into WSL.This method works for virtually any distro available as a container image.

Importing the tar file into WSL: step-by-step example with CentOS

With the tar file prepared, it's time to load it into WSL. From PowerShellFirst, create a folder where the rootfs will reside.

# En PowerShell
cd C:\temp
mkdir E:\wslDistroStorage\CentOS

Now the tar matters: The first argument is the logical name of the distroThe second is the path where the rootfs will be saved, and the third is the tar file you generated.

wsl --import CentOS E:\wslDistroStorage\CentOS .\centos.tar

Check that it appears as installed and, if you wish, pull it out directly to verify that everything is OK.

wsl -l -v
wsl -d CentOS

After an import, WSL starts as root. If you prefer to log in with your normal user accountIn the next section you will see how to declare it as the default.

  Ultimate Basic Hardening Guide for Windows 11: Key Tricks to Strengthen Your System

Configure the default user and adjust WSL with wsl.conf

After importing any distro, By default, you log in as root.In CentOS you can create a user, add it to wheel and configure it as the default user with wsl.conf.

# Dentro de la distro CentOS
yum update -y && yum install -y passwd sudo

myUsername=caloewen
adduser -G wheel $myUsername

echo -e "\ndefault=$myUsername" >> /etc/wsl.conf

passwd $myUsername

To apply the change, Shut down the instance and restart it from PowerShell:

wsl --terminate CentOS
wsl -d CentOS

Beyond the user, /etc/wsl.conf allows the assembly regulationnetworks and other options, very useful when several people share the same distro or when you want to standardize behaviors.

Basic example of wsl.conf

This example mounts Windows drives with metadata, prevent WSL from regenerating resolv.conf (useful if you manage DNS manually) and sets the default user.


enabled = true
options = "metadata,umask=22,fmask=11"


generateResolvConf = false


default = tu_usuario

Apply changes with wsl –shutdown and restart the distro so that the new adjustments can take effect.

Additional automation with cloud-init (when the distro supports it)

Some distributions in WSL 2, such as Ubuntu, They can run cloud-init to provision packages, users, and files during the initial setup. It's a tool designed for cloud environments, but it's very convenient for standardizing installations on development teams.

A minimal example that installs packages and creates a user It might look like this:

#cloud-config
packages:
  - git
  - curl
  - build-essential
users:
  - name: dev
    groups: 
    sudo: ALL=(ALL) NOPASSWD:ALL
    shell: /bin/bash
runcmd:
  - echo "alias ll='ls -la'" >> /home/dev/.bashrc

Combined with wsl.conf and post-provisioning scripts, You'll get distros that are ready to go right out of the box. with your tools, dotfiles and preferences.

Typical automated deployment flow

If you want everything measured, a reasonable flow would: create the base distro with wsl –import, inject wsl.conf and (if the distro allows it) cloud-init, run the provisioning and finally export it for sharing.

  1. Create a base distro with wsl --import.
  2. Setup /etc/wsl.conf and, if the distro allows it, add files from cloud-init.
  3. Execute the provisioning and validate that everything matches.
  4. Export to tar and share the image with the team for express onboardings.

This approach drastically reduces There for commissioning, avoids differences “it works on my machine” and facilitates compliance with IT policies in companies.

Backup and restore of WSL distros

It's infuriating to spend weeks fine-tuning an environment only to lose it due to a single mistake. Using wsl –export you get a complete snapshot of the file system, packages, configurations and users in a single TAR file.

Before exporting, Make sure the distro is stopped to ensure the archive remains complete:

wsl --list --verbose
wsl --terminate Ubuntu   # si está Running
# Repite hasta verla como Stopped

Exporting is straightforward and supports versioned names. Save the tar files to another drive or to the cloud. for added security:

# Ejemplo simple
wsl --export Ubuntu E:\WSL_Backups\UbuntuBackup_2025-09-02.tar

# Con fecha automática en PowerShell
wsl --export Ubuntu E:\WSL_Backups\UbuntuBackup$(Get-Date -Format yyyy-MM-dd).tar

To restore, import the tar file with a new name and folder. You'll get an identical distro to the original:

wsl --import Ubuntu_Backup C:\WSL\Ubuntu_Backup E:\WSL_Backups\UbuntuBackup_2025-09-02.tar
wsl -d Ubuntu_Backup

After an import, you will log in as root. Set your default user by editing /etc/wsl.conf within the distro and restarting WSL:

# Dentro de la distro restaurada
sudo nano /etc/wsl.conf

# Añade:

default = tu_usuario

# Aplica cambios
wsl --terminate Ubuntu_Backup
wsl -d Ubuntu_Backup

Good practices: periodic backup program With the Task Scheduler, clean up temporary files and containers to reduce size, and use short, clear names in your distros to make management easier.

  The best way to use the multilingual keyboard on iPhone

What to do if “wsl –import” does not appear in the help

It may happen that when executing wsl --help Don't see "import" listed among the options And that the import attempt returns the generic usage text. This usually indicates that your WSL binary is not updated to a version that includes the functionality.

On Windows 10 Pro 21H2 (build 19044.1706) and higher, You should have modern capabilities if you upgrade WSLTry the following using PowerShell with privileges:

# Actualiza WSL a la versión más reciente
wsl --update

# Reinicia WSL para aplicar
wsl --shutdown

# Si persiste, reinicia el servicio del subsistema
Restart-Service LxssManager

Behind this, Run wsl –help again and check that “–import” appears.If you're still having the same problem, make sure you're on a compatible build and not using an outdated executable in the path.

GUI applications in WSL: requirements and quick examples

WSL already allows you to run apps Linux GUI (X11/Wayland) integrated into Windows: Pin them to the taskbar, Alt-Tab between apps, copy and paste between environments… For this, you need Windows 10 build 19044+ or Windows 11 and a suitable vGPU controller.

If you start from scratch, a A clean install with wsl –install gets everything up and running and it will ask for your Ubuntu username and password after restarting:

# PowerShell (Administrador)
wsl --install

With WSL already installed, Update to the latest version with GUI support and restarts the subsystem:

wsl --update
wsl --shutdown

Examples in Ubuntu for Install regular desktop apps and test if they work:

# Refresca índices
sudo apt update

# Gnome Text Editor
sudo apt install -y gnome-text-editor
# Ejecuta: gnome-text-editor ~/.bashrc

# GIMP
sudo apt install -y gimp
# Ejecuta: gimp

# Nautilus (Archivos GNOME)
sudo apt install -y nautilus
# Ejecuta: nautilus

# Apps X11 básicas
sudo apt install -y x11-apps
# Ejecuta: xcalc, xclock, xeyes

Even browsers: Chrome is installed by downloading the .deb file and resolving dependencies., and Edge has line installation of commands from their Insider site.

WSL 2 + Docker: Advantages and workflow for a real working environment (NILMTK)

Docker fits like a glove with WSL 2: portability, consistency and speed For hassle-free development and deployment. It allows you to isolate projects, version images, and scale when needed.

Key advantages of Docker in this context: Identical environments throughout the pipeline, efficient use of resources compared to VMs, automation with CI/CD and seamless collaboration by sharing pre-configured images.

Summary of steps for a hybrid environment with NILMTK

In a real-world scenario, you can start with a physical Ubuntu machine, Build a Docker image with NILMTK and dependenciesExport it to tar, activate WSL 2 in Windows and load the image there to work.

# En tu Ubuntu físico
sudo apt update && sudo apt upgrade -y
sudo apt install -y docker.io tar
sudo systemctl enable docker

# Dockerfile mínimo para NILMTK
cat <<EOF > Dockerfile
FROM ubuntu:22.04
RUN apt update && apt install -y python3.8 python3-pip \
    && pip install nilmtk==0.4.3 nilm_metadata==0.2.4
EOF

# Construye y exporta la imagen
sudo docker build -t nilmtk-env .
sudo docker save nilmtk-env > nilmtk-env.tar

In Windows 11, Enables WSL 2 and Ubuntu 22.04 from PowerShell (Administrator):

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
wsl --set-default-version 2
wsl --install -d Ubuntu-22.04

Transfer the tar and Load it into Docker within WSL:

# Desde Ubuntu físico
scp nilmtk-env.tar usuario@windows:/mnt/c/Users/tu_usuario/

# Dentro de Ubuntu en WSL
docker load < /mnt/c/Users/tu_usuario/nilmtk-env.tar

Install Docker Desktop with WSL 2 backend, activate the integration with your distro In Settings > Resources > WSL Integration, launch the container:

docker run -it --rm \
  -v $(pwd):/nilmtk \
  --gpus all \
  nilmtk-env \
  bash

# Verifica NILMTK dentro del contenedor
python3 -c "import nilmtk; print(nilmtk.__version__)"  # 0.4.3

If something goes wrong, here are several quick fixes: “WSL integration not available” is solved with wsl –update and restarting LxssManagerIf the GPU doesn't appear, update. drivers NVIDIA and CUDA support for WSL; when space is limited, the VHDX is compacted after performing a wsl --shutdown.

Enterprise Ubuntu installation and distribution on WSL

Canonical is promoting a format based on tar and, more recently, on .wsl files for direct distribution and installationThis allows IT to self-host images, control which versions are available and customize them before deployment, with native cloud-init support for advanced configuration.

  The camera cannot establish connection

To install Ubuntu using the latest approach, Use the updated version of WSL (2.4.8 or higher) and runs:

wsl --install ubuntu
# O bien, si tienes el archivo
wsl --install --from-file ubuntu.tar.wsl
# Incluso puedes hacer doble clic sobre el .wsl

This model greatly simplifies life in companies, by allowing installations without going through the Store, with centralized control and compliance with security policies.

Custom Linux distributions for WSL

If you need to go a step further, You can create your own distro as a UWP app so that it behaves like the official Store distributions. It's a powerful way for organizations that need to package internal tools, security policies, and specific onboarding workflows.

For everyday use, the combination tar + wsl –import + wsl.conf It already covers the vast majority of scenariosBut if your organization requires distribution through corporate channels, the UWP option is there.

Operating tips and expert support

When planning WSL deployments and backups, organizes the paths, labels versions, and documents the restoration procedureAvoid copying tar files to the same system disk, schedule periodic exports, and clean up artifacts to save space.

If you're looking to fine-tune your pipelines, security, or public clouds, Specialized companies like Q2BSTUDIO can help you to orchestrate backups, automate tasks, design reproducible pipelines and protect your data against incidents and ransomware, as well as advise you on cloud services (AWS, Azure) to store and version images with lifecycle policies and encryption.

With all of the above, the move is clear: wsl –import gives you the key to bringing any Linux distribution to Windowswsl.conf and cloud-init round out the automation, the WSL 2 + Docker duo offers consistent and fast environments, and the export/import functions protect you against unforeseen events; if you also upgrade to the latest version of WSL, you can add integrated GUI applications and new distribution methods such as .wsl, achieving an agile, replicable and easy-to-maintain professional environment.

Using MDT (Microsoft Deployment Toolkit)-8
Related article:
Complete Guide to Using MDT: Deployment, Automation, and Advanced Administration of Windows Systems