WSL: Difference between revisions
| Line 121: | Line 121: | ||
== Create VDH == | == Create VDH == | ||
Enable VDH commands | Enable VDH commands (Install Hyper-V Module) | ||
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -All -NoRestart | Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -All -NoRestart | ||
| Line 131: | Line 131: | ||
ref: https://gist.github.com/lseongjoo/d38b29fdbd5c082880576d0c34f7593e | ref: https://gist.github.com/lseongjoo/d38b29fdbd5c082880576d0c34f7593e | ||
Alternative: | |||
Disk Management > Click Action > Create VHD | |||
== Mount VHDX or VHD in WSL == | == Mount VHDX or VHD in WSL == | ||
Revision as of 02:29, 14 February 2026
Windows Subsystem for Linux
NOTE: THERE IS TOO MUCH RAM OVERHEAD FOR WSL, DON'T ENABLE, UNLESS YOU HAVE A TON OF RAM!
Enable
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Disable
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
List Available Install Options
wsl --list --online
Online list as of 2025.07.04:
C:\> wsl --list --online The following is a list of valid distributions that can be installed. Install using 'wsl.exe --install <Distro>'. NAME FRIENDLY NAME AlmaLinux-8 AlmaLinux OS 8 AlmaLinux-9 AlmaLinux OS 9 AlmaLinux-Kitten-10 AlmaLinux OS Kitten 10 AlmaLinux-10 AlmaLinux OS 10 Debian Debian GNU/Linux FedoraLinux-42 Fedora Linux 42 SUSE-Linux-Enterprise-15-SP6 SUSE Linux Enterprise 15 SP6 SUSE-Linux-Enterprise-15-SP7 SUSE Linux Enterprise 15 SP7 Ubuntu Ubuntu Ubuntu-24.04 Ubuntu 24.04 LTS archlinux Arch Linux kali-linux Kali Linux Rolling openSUSE-Tumbleweed openSUSE Tumbleweed openSUSE-Leap-15.6 openSUSE Leap 15.6 Ubuntu-18.04 Ubuntu 18.04 LTS Ubuntu-20.04 Ubuntu 20.04 LTS Ubuntu-22.04 Ubuntu 22.04 LTS OracleLinux_7_9 Oracle Linux 7.9 OracleLinux_8_7 Oracle Linux 8.7 OracleLinux_9_1 Oracle Linux 9.1
Install Ubuntu
wsl --install -d Ubuntu-24.04
wsl --install -d Ubuntu-22.04
wsl --install -d Ubuntu-20.04
wsl --install -d Debian
wsl --install -d ubuntu
Give the installation a non-default name (useful for having more than one copy of said distribution installed)
wsl --install -d Debian --name MyDebian
ref [1]
Basic Commands for WSL
Basic commands for WSL https://learn.microsoft.com/en-us/windows/wsl/basic-commands
List Running
List running
wsl --list --running # or wsl -l --running
List all
wsl --list --all wsl -l --all
Also open File Explorer, and click on the Linux in the Navigation Pane. [1]
Convert WSL and Windows Paths
$ wslpath
Usage:
-a force result to absolute path format
-u translate from a Windows path to a WSL path (default)
-w translate from a WSL path to a Windows path
-m translate from a WSL path to a Windows path, with '/' instead of '\'
EX: wslpath 'c:\users'
Windows path from WSL:
$ wslpath 'c:\users' /mnt/c/users
WSL path from Windows:
$ wslpath -w '/' \\wsl.localhost\Ubuntu\
Set Default User for WSL
Ubunutu:
ubuntu config --default-user root
Ubuntu18:
ubuntu1804 config --default-user root
Set Default User for Windows Subsystem for Linux Distro in Windows 10 | Tutorials https://www.tenforums.com/tutorials/128152-set-default-user-windows-subsystem-linux-distro-windows-10-a.html
Create VDH
Enable VDH commands (Install Hyper-V Module)
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -All -NoRestart
Create VDH:
New-VHD support.vhdx -SizeBytes 25GB -Dynamic -BlockSizeBytes 1MB Write-Output "\\.\PhysicalDrive$((Mount-VHD -Path support.vhdx -PassThru | Get-Disk).Number)"
wsl --mount \\.\PhysicalDriveX --bare
ref: https://gist.github.com/lseongjoo/d38b29fdbd5c082880576d0c34f7593e
Alternative:
Disk Management > Click Action > Create VHD
Mount VHDX or VHD in WSL
Install Docker Desktop WSL2 on Windows with allocated maximum size (virtual size) less then default 1TB - Docker Desktop for Windows - Docker Community Forums https://forums.docker.com/t/install-docker-desktop-wsl2-on-windows-with-allocated-maximum-size-virtual-size-less-then-default-1tb/135817/8
Is it possible to map a WSL mount into a docker container? Or use an EXT4 VHD with Docker in any other way? : r/docker https://www.reddit.com/r/docker/comments/112b10k/is_it_possible_to_map_a_wsl_mount_into_a_docker/
Moving docker-desktop "distro" vhdx file - Docker Desktop for Windows - Docker Community Forums https://forums.docker.com/t/moving-docker-desktop-distro-vhdx-file/137632/3
WSL2 mount VHDX virtual disk issue with Windows docker Volumes - Stack Overflow https://stackoverflow.com/questions/65548924/wsl2-mount-vhdx-virtual-disk-issue-with-windows-docker-volumes
Get started mounting a Linux disk in WSL 2 | Microsoft Learn https://learn.microsoft.com/en-us/windows/wsl/wsl2-mount-disk
How to Use Dedicated Disks in Wsl - Rouke's Blog https://broersma.dev/how-to-use-dedicated-disks-in-wsl/
best:
WSL2 How-to: Prepare and Attach Virtual Drives (VHD) | by Tony Tannous | Medium https://anthony-f-tannous.medium.com/wsl2-how-to-prepare-and-attach-virtual-drives-vhd-ac17b1fc7a61
Misc:
wsl --mount \\.\PHYSICALDRIVE2 --bare
wsl -d Ubuntu-20.04 --mount --vhd C:\Users\<username>\wsl2-shared.vhdx --bare | out-null wsl -d Ubuntu-20.04
wsl -d Ubuntu-20.04 --mount --vhd $env:USERPROFILE\wsl2-shared.vhdx --bare
Mount VHD:
pwsh.exe -Command "wsl.exe -d Ubuntu-20.04 --mount --vhd C:\Users\<username>\wsl2-shared.vhdx --bare | out-null; wsl.exe -d Ubuntu-20.04"
Inside WSL see mount:
blkid lsblk -o NAME,LABEL,FSTYPE,SIZE,MOUNTPOINT /dev/sdd lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT /dev/sdd sudo parted /dev/sdd print sudo parted -a optimal /dev/sdd mkpart primary ext4 0% 100% parted /dev/sdd mklabel msdos mount -l | grep vhd-part1
Unmount
wsl --unmount \\?\C:\Users\<username>\wsl2-shared.vhdx
NFS
To mount an NFS share in WSL, you will need to mount it with "insecure"
example /etc/exports
/pub *(rw) /pub 10.0.0.101(insecure,rw)
Kali Linux
Error installing Kali:
C:\> wsl --install -d kali-linux --name kali Downloading: Kali Linux Rolling An error occurred in the secure channel support Error code: Wsl/InstallDistro/0x80072f7d
Same with:
wsl --install -d kali-linux --name kali --web-download
If you get the above, try downloading it from the MS Store:
Kali Linux - Free download and install on Windows | Microsoft Store https://apps.microsoft.com/detail/9pkr34tncv07?hl=en-US&gl=US
Disable Automatic Generation of /etc/resolv.conf
Sample
/etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf: # [network] # generateResolvConf = false nameserver 10.255.255.254 search corp.com home.com
---
Disabling Automatic Generation: To permanently customize your DNS settings, you need to disable this automatic generation by adding generateResolvConf = false under the [network] section in /etc/wsl.conf. After making this change, you can then manually create or modify /etc/resolv.conf with your desired DNS servers.
$ cat /etc/wsl.conf [boot] systemd=true [user] default=aznotuser [network] generateResolvConf = false
$ cat/etc/resolv.conf nameserver 10.0.0.8
Mount Drives with Correct Permissions
sudo ln -s /mnt/c /c sudo ln -s /mnt/d /d sudo mkdir /d/code sudo chwon USER:USER /d/code sudo ln -s /d/code /code cd ~ ln -s /code code
Add these automount settings to /etc/wsl.conf and restart wsl:
[automount] enabled = true options = "metadata,umask=22,fmask=11"
inside wsl:
sudo vim /etc/wsl.conf
From powershell/command prompt:
wsl --terminate Ubuntu-24.04 # or wsl -t Ubuntu-24.04
Start ubuntu again:
wsl -d Ubuntu-24.04
Example:
/etc/wsl.conf :
[boot] systemd=true [automount] enabled = true options = "metadata,umask=22,fmask=11"
---
https://learn.microsoft.com/en-us/windows/wsl/wsl-config
Automount settings:
- enabled - true causes fixed drives (i.e C:/ or D:/) to be automatically mounted with DrvFs under /mnt. false means drives won't be mounted automatically, but you could still mount them manually or via fstab.
- options - comma-separated list of values, such as uid, gid, etc.
- metadata - Whether metadata is added to Windows files to support Linux system permissions
- umask - An octal mask of permissions to exclude for all files and directories
- fmask - An octal mask of permissions to exclude for all files
You can optionally add more options to set default permissions, which is often recommended for better compatibility with Linux tools that expect standard file permissions (like SSH keys or git):
[automount] enabled = true options = "metadata,umask=22,fmask=11"
- metadata: This option enables the storage of Linux file metadata (like permissions and ownership) on Windows drives.
- umask and fmask: These set default octal masks to control file and directory permissions.
Move WSL Instance
1. Terminate the running distribution
wsl --terminate <DistroName>
2. Export the distribution to a temporary tar file.
wsl --export <DistroName> "D:\wsl-instances\<DistroName>.tar"
3. Unregister the original distribution from its default C: drive location. - Caution this is destructive
wsl --unregister <DistroName>
4. Create the new installation directory
mkdir D:\wsl-instances\<DistroName> wsl --import <DistroName> "D:\wsl-instances\<DistroName>" "D:\wsl-instances\<DistroName>.tar"
5. (Optional) Set the default user if it changes to root after the import.
5.1 Start new instance
wsl -d <DistroName>
5.2 Inside new instance edit /etc/wsl.conf:
sudo nano /etc/wsl.conf
5.3 Change with username:
[user] default=<your_username>
5.4 Save exit, and exit wsl instance
exit
6. Terminate wsl again
wsl --terminate <DistroName>
7. Clean up the temporary tar file and start your new instance.
Remove-Item "D:\wsl-instances\<DistroName>.tar"
8. Start new instance
wsl -d <DistroName>
# or just: wsl # if it was set as default with: wsl --set-default <DistroName>
Issues
Update fails with Forbidden (403)
C:\>wsl --update Checking for updates. Forbidden (403). Error code: Wsl/UpdatePackage/0x80190193
Searches online indiate Defender (or other virus scanner may be to blame).
One suggests using --web-download:
wsl --update --web-download
ref: [2]
C:\>wsl --update Checking for updates. The most recent version of Windows Subsystem for Linux is already installed.