hansontechsolutions.com

Creating and Exporting a WSL Environment: A Comprehensive Guide

Written on

Chapter 1: Setting Up Your WSL Environment

If you're already familiar with the Windows Subsystem for Linux (WSL), this guide will serve as a handy reference to help you create and export your WSL environment efficiently.

Installing a Linux Distribution

When you execute the command wsl --install, Ubuntu is typically installed as the default Linux distribution. However, you can specify a different distribution by using:

wsl --install -d <distribution name>

For additional options, you can install other distributions either via the Windows Store or by running:

wsl --install -d <distribution name>

To see the list of available distributions, use:

wsl --list --online

Options include popular distributions like Debian or openSUSE-42.

Configuring the Base Environment

After installing your desired distribution, launch it with:

wsl -d <distribution name>

This environment will be the foundation for any copies you wish to create. Customize it to your liking, as these settings will be replicated in future instances.

Exporting the Base Environment

Once you're satisfied with your setup, exit the WSL environment to return to the Windows shell. To export your environment, use the following command:

wsl --export <distribution name> <export file name>

For example, to export an Ubuntu distribution, you would run:

wsl --export Ubuntu ubuntu.tar

This command packages your environment into a .tar archive, making it ready for import.

Creating New Instances of the Distribution

You can create new instances based on your exported base environment by importing the .tar file with the command:

wsl --import <new distribution name> <install location> <export file name>

For instance, to create a new distribution named UbuntuDev1 from the original Ubuntu base, you would execute:

wsl --import UbuntuDev1 .UbuntuDev1 ubuntu.tar

The file systems for these instances are stored within a virtual hard disk located at:

%USERPROFILE%AppDataLocalPackages<distribution package name>LocalStateext4.vhdx

For example, the package name for Ubuntu is CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc.

Accessing the New Environment

To access your newly created environment, use:

wsl -d <new distribution name>

For instance:

wsl -d UbuntuDev1

If you're using Windows Terminal, the new environment will also be visible in the dropdown profiles.

Accessing the new WSL environment in Windows Terminal

Additionally, if you're on Windows 11, you can conveniently explore the Linux filesystem of your environment using File Explorer.

Navigating the Linux filesystem in Windows 11 File Explorer

Configuring User Settings in the Environment

Upon opening the new environment, you may notice that it logs in as the root user, rather than a custom user you set up in the base environment. Although your custom user is available, it hasn't been designated as the default.

To start the environment with your custom user, you can use:

wsl -d <new distribution name> -u <username>

Alternatively, to set your custom user as the default, create or update the wsl.conf file in the /etc directory of your environment with the following content:

[user]

default=<username>

You can easily create or append to this configuration file using a single command:

tee -a /etc/wsl.conf <<EOF

[user]

default=NerpNerp

EOF

Video Resources

To further enhance your understanding of WSL, here are two helpful video resources:

Importing and Exporting WSL Distributions

This video provides an overview of how to effectively import and export WSL distributions.

Export, Import, and Migrate WSL and WSL2 Installations

This video walks you through the steps to export, import, and migrate WSL installations, ensuring a smooth transition between environments.

If you haven't joined Medium yet and wish to do so, consider signing up through my referral link. It will earn me a small commission.

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

Navigating My Path as a Licensed Insurance Agent: A Personal Story

A personal account of my journey as a licensed insurance agent, overcoming challenges, and making a difference in clients' lives.

Discovering Your Purpose: A Simple Approach to Fulfillment

Unveil the straightforward path to finding your purpose in life through commitment, responsibility, and action.

Understanding Phase Transitions in the Checkerboard State

An exploration of phase transitions in atom arrays, focusing on the checkerboard state and the Kibble-Zurek mechanism.

Exploring the Allure of Fake Social Media Platforms

Discover the benefits of fake social media apps, offering privacy and personal validation without the pressures of traditional platforms.

Incredible Comeback Strategies: Enhance Your Running with Key Tips

Discover effective techniques to recover from injuries, optimize running form, and stay healthy while training.

Understanding the Complexities Behind the Reddit Crisis

An in-depth look at the recent controversies surrounding Reddit and its impact on users and third-party applications.

Choosing the Right Programming Language: A Personal Journey

Discover how to select your next programming language through personal insights and practical frameworks.

The Caucasity in Tech: A Call for Diversity and Change

Exploring the persistent lack of diversity in tech and the need for systemic changes.