Cheat sheet de comandos Ăștiles para WSL (Windows Subsystem for Linux): instalar, las distribuciones disponibles y quĂ© cambia entre PowerShell y WSL en el dĂa a dĂa.
List installed Linux distributions
wsl --list --verboseUpdate WSL
wsl --updateCheck WSL status
wsl --statusShutdown
wsl --shutdownImmediately terminates all running distributions and the WSL 2 lightweight utility virtual machine. This command may be necessary in instances that require you to restart the WSL 2 virtual machine environment, such as changing memory usage limits or making a change to your .wslconfig file.
Terminate
wsl --terminate <Distribution Name>To terminate the specified distribution, or stop it from running, replace <Distribution Name> with the name of the targeted distribution.
Identify IP address
wsl hostname -I: Returns the IP address of your Linux distribution installed via WSL 2 (the WSL 2 VM address)ip route show | grep -i default | awk '{ print $3}': Returns the IP address of the Windows machine as seen from WSL 2 (the WSL 2 VM)
Export a distribution
wsl --export <Distribution Name> <FileName>Exports a snapshot of the specified distribution as a new distribution file. Defaults to tar format. The filename can be - for standard input. Options include:
--vhd: Specifies the export distribution should be a .vhdx file instead of a tar file (this is only supported using WSL 2)
Import a distribution
wsl --import <Distribution Name> <InstallLocation> <FileName>Imports the specified tar file as a new distribution. The filename can be - for standard input. Options include:
--vhd: Specifies the import distribution should be a .vhdx file instead of a tar file (this is only supported using WSL 2)--version <1/2>: Specifies whether to import the distribution as a WSL 1 or WSL 2 distribution
Import a distribution in place
wsl --import-in-place <Distribution Name> <FileName>Imports the specified .vhdx file as a new distribution. The virtual hard disk must be formatted in the ext4 filesystem type.
Unregister or uninstall a Linux distribution
While Linux distributions can be installed through the Microsoft Store, they canât be uninstalled through the store.
To unregister and uninstall a WSL distribution:
wsl --unregister <DistributionName>Replacing <DistributionName> with the name of your targeted Linux distribution will unregister that distribution from WSL so it can be reinstalled or cleaned up. Caution: Once unregistered, all data, settings, and software associated with that distribution will be permanently lost. Reinstalling from the store will install a clean copy of the distribution. For example, wsl --unregister Ubuntu would remove Ubuntu from the distributions available in WSL. Running wsl --list will reveal that it is no longer listed.
You can also uninstall the Linux distribution app on your Windows machine just like any other store application. To reinstall, find the distribution in the Microsoft Store and select âLaunchâ.
Mount a disk or device
wsl --mount <DiskPath>Attach and mount a physical disk in all WSL2 distributions by replacing <DiskPath> with the directory\file path where the disk is located. See Mount a Linux disk in WSL 2. Options include:
--vhd: Specifies thatÂ<Disk> 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>: Filesystem type to use when mounting a disk, if not specified defaults to ext4. This command can also be entered as:Âwsl --mount -t <Filesystem>.You can detect the filesystem type using the command:Âblkid <BlockDevice>, for example:Âblkid <dev/sdb1>.--partition <Partition Number>: Index number of the partition to mount, if not specified defaults to the whole disk.--options <MountOptions>: 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.
Unmount disks
wsl --unmount <DiskPath>Source