Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

WSL - Windows Subsystem for Linux

WSL2 runs a real Linux kernel in a lightweight VM. Windows drives are automounted under /mnt/ (e.g. D: -> /mnt/d) but without Linux metadata support by default, which means file permissions and ownership are not preserved on Windows filesystem paths.

Reference: Microsoft WSL configuration docs

Metadata: fixing file permissions on Windows mounts

Without metadata, chmod, chown, and sed -i (which uses a temp file) behave unexpectedly or fail with permission errors.

Remount on the fly

sudo umount /mnt/d
sudo mount -t drvfs D: /mnt/d -o metadata

Make it permanent

Add to /etc/wsl.conf:

[automount]
options = "metadata"

Note: The official Microsoft docs use options = "metadata,..." — spaces around = and quotes around the value. The quotes are part of the expected format when passing a comma-separated list of sub-options.

Then restart WSL from PowerShell or CMD:

wsl --shutdown

wsl.conf reference

Located at /etc/wsl.conf inside the distro. Changes take effect after wsl --shutdown.

[automount]

OptionDefaultDescription
enabledtrueAuto-mount Windows drives under root
mountFsTabtrueProcess /etc/fstab on startup
root/mnt/Mount point prefix for Windows drives
options(none)DrvFs mount options (comma-separated)

DrvFs mount sub-options for options=:

Sub-optionDefaultDescription
metadataoffStore Linux permissions in NTFS extended attributes
uid1000Default file owner UID
gid1000Default file owner GID
umask022Permission mask for files and directories
fmask000Permission mask for files only
dmask000Permission mask for directories only
caseoffCase sensitivity: off, dir, or force
[automount]
enabled=true
root=/mnt/
options = "metadata,umask=22,fmask=11"
mountFsTab=true

[boot]

OptionDefaultDescription
systemdfalseEnable systemd
command(none)Command to run at startup (as root)
protectBinfmttruePrevent systemd from overriding binfmt entries
[boot]
systemd=true

[network]

OptionDefaultDescription
generateHoststrueGenerate /etc/hosts
generateResolvConftrueGenerate /etc/resolv.conf
hostnameWindows hostnameWSL distro hostname

[interop]

OptionDefaultDescription
enabledtrueAllow launching Windows processes from WSL
appendWindowsPathtrueAdd Windows PATH entries to $PATH

[user]

OptionDefaultDescription
default(install user)Default login user

[gpu] / [time]

OptionDefaultDescription
gpu.enabledtrueGPU access via para-virtualization
time.useWindowsTimezonetrueSync timezone from Windows

Full example

[user]
default=gbraad

[boot]
systemd=true

[network]
generateResolvConf=false

[automount]
options = "metadata"

.wslconfig reference

Located at %UserProfile%\.wslconfig on the Windows side. Controls the WSL2 VM globally across all distros.

[wsl2]

OptionDefaultDescription
memory50% of RAMVM memory allocation (e.g. 8GB)
processorslogical CPU countVM CPU core count
swap25% of memorySwap size (e.g. 2GB)
swapFile%Temp%\swap.vhdxSwap file path
localhostForwardingtrueForward localhost ports to Windows host
networkingModeNATnone, nat, mirrored, virtioproxy
guiApplicationstrueWSLg GUI app support
nestedVirtualizationtrueAllow VMs inside WSL
vmIdleTimeout60000 (ms)Idle time before VM shuts down
defaultVhdSize1TBMax distro filesystem size
kernel(bundled)Path to custom kernel
kernelCommandLine(none)Extra kernel parameters
[wsl2]
memory=8GB
processors=4
swap=2GB
networkingMode=mirrored

Path values require escaped backslashes: C:\\Temp\\kernel

Common WSL commands

wsl --shutdown                          # stop all running distros
wsl --list --verbose                    # list distros and status
wsl --set-default Ubuntu                # set default distro
wsl --set-version Ubuntu 2             # upgrade distro to WSL2
wsl --export Ubuntu ubuntu.tar         # back up distro
wsl --import Ubuntu C:\WSL ubuntu.tar  # restore distro