Skip to content

wsl commands

phaledang edited this page Mar 7, 2024 · 5 revisions

Using powershell to export wsl

show list to get the name

wsl --list

output: Ubuntu-22.04 (Default)

wsl.exe -l --all

export

wsl --export

cd c:\le\export-wsl

wsl --export "Ubuntu-22.04" ".\leubuntu.zar"

install

wsl --install

Using powershell to export wsl

show list to get the name

wsl --list output: Ubuntu-22.04 (Default) wsl --export

List available Linux distributions

wsl --list --online

List installed Linux distributions

wsl --list --verbose

set default version

wsl --set-default-version

set default wsl

wsl --set-default

export

cd c:\le\export-wsl

wsl --export "Ubuntu-22.04" ".\Ubuntu-22.zar"

import

wsl --import <Directory location of the exported .tar file>

wsl --import Ubuntu-22.04 "C:\ubuntu-import" "C:\ubuntu-export\Ubuntu-22.zar"

###To run the specific WSL Linux distro imported from the exported .tar backup file

wsl -d

change directory to home

~

run

wsl --distribution --user

update

run with user

wsl --user

change default user

config --default-user

shutdown

wsl --shutdown

Import a distribution in place

wsl --import-in-place

Imports the specified .vhdx file as a new distribution. The virtual hard disk must be formatted in the ext4 filesystem type.

To unregister and uninstall a WSL distribution:

wsl --unregister

wsl --unregister Ubuntu-22.04

wsl --unregister Ubuntu

Mount a disk or device

PowerShell

Copy wsl --mount Attach and mount a physical disk in all WSL2 distributions by replacing with the directory\file path where the disk is located. See Mount a Linux disk in WSL 2. Options include:

  • --vhd: Specifies that refers to a virtual hard disk.
  • --name: Mount the disk using a custom name for the mountpoint
  • --bare: Attach the disk to WSL2, but don't mount it.
  • --type : Filesystem type to use when mounting a disk, if not specified defaults to ext4. This command can also be entered as: wsl --mount -t .You can detect the filesystem type using the command: blkid , for example: blkid <dev/sdb1>.
  • --partition : Index number of the partition to mount, if not specified defaults to the whole disk.
  • --options : There are some filesystem-specific options that can be included when mounting a disk. For example, ext4 mount options like: wsl --mount -o "data-ordered" or wsl --mount -o "data=writeback. However, only filesystem-specific options are supported at this time. Generic options, such as ro, rw, or noatime, are not supported.

Edit Distro name

Go to registry Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss change the DistributionName value

Go to default user after import

wsl --distribution ubuntu-22.04 -u ledang

cd /home/ledang

show ubuntu version: run PowerShell command on windows

lsb_release -a

References

https://learn.microsoft.com/en-us/windows/wsl/basic-commands

Clone this wiki locally