Skip to content

WSL

Backing up and Restoring WSL Distributions

  1. Export a WSL distribution for backup/migration from PowerShell

    wsl --export <distribution_name> <filename>
    
  2. To import a WSL distribution from PowerShell

    wsl --import <distribution_name> <install_location> <filename>
    
  3. This new WSL distribution will start as the root user. To start as another user, add the following to /etc/wsl.conf from inside the distribution

    wsl.conf
    [user]
    default=<username>
    
  4. wsl --shutdown from PowerShell and restart to see the change

More WSL Commands

Command Description
wsl -l -v List WSL distributions along with their state and version
wsl -t <distribution_name> Terminate/shut down a WSL distribution
wsl --unregister <distribution_name> Unregisters WSL distribution and deletes root filesystem
  • wsl --help to see all WSL commands and their descriptions

Commands Inside WSL Distributions

  • Sign in to Git using the Git Credential Manager in Windows

    git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-manager-core.exe"
    
  • Open a WSL file/directory using the Windows default program

    • For example: File Explorer for directories, Excel for CSV files
    wslview <file_or_directory>
    

Resources