Improving WSL2 Disk I/O Performance
· 6 min read · Views --
Last updated on

Improving WSL2 Disk I/O Performance

Author: Alex Xiang


Improving WSL2 Disk I/O Performance

It is well known that reading and writing files on Windows partitions from WSL2 can be slow. I used to access Windows files directly through paths such as /mnt/d/, but recently even Git operations started to feel uncomfortable, so I decided to optimize this properly.

The basic idea is to create a VHDX file in Windows, format it as an ext4 filesystem, and mount it inside WSL2. That way, development files stay on a Linux filesystem, while Windows can still access them through the WSL network path when needed.

In Computer Management -> Disk Management, create a VHDX file. Then use a tool such as DiskGenius 5.4 to format the virtual disk as ext4.

In PowerShell, run:

wmic diskdrive list brief

Find the DeviceID of the newly created “Microsoft Virtual Disk”, for example \\.\PHYSICALDRIVE2.

Then mount the first partition into WSL:

wsl --mount \\.\PHYSICALDRIVE2 --partition 1

Inside WSL, you should see something like:

/dev/sdf1 on /mnt/wsl/PHYSICALDRIVE2p1 type ext4 (rw,relatime)

If you want to mount it to a specific directory, first attach the disk without mounting it:

wsl --mount \\.\PHYSICALDRIVE2 --bare

This only attaches the disk to WSL2. Then, inside WSL, create a work directory and mount the partition yourself:

mkdir ~/work
sudo mount /dev/sdf1 ~/work

For automatic mounting, edit /etc/fstab:

LABEL=work /mnt/work ext4 defaults 0 0

When creating the VHDX, you can set a filesystem label in advance. That makes automatic mounting by label straightforward. Running mount -a applies the configuration immediately.

After this change, accessing files on the mounted Linux partition from WSL is much faster than accessing files directly from a Windows drive. The tradeoff is that the Windows-side access path changes. You can use paths such as:

\\wsl.localhost\Ubuntu\mnt\work

For development, opening the directory through the VS Code Remote - WSL extension is usually more convenient.