This guide explains how to create, mount, and maintain a VHDX drive for use with WSL (Windows Subsystem for Linux).
- Windows 10/11 with WSL2 installed
- Administrative access
- PowerShell
- Sufficient disk space
- First, check existing devices in your WSL distribution:
ls /dev/sd* -la
- Create the VHDX file in PowerShell (run as Administrator):
New-VHD -Path "Z:\Disks\wsl-ubuntu-2404\data_disk.vhdx" -SizeBytes 500GB -Dynamic
wsl --mount --vhd "Z:\Disks\wsl-ubuntu-2404\data_disk.vhdx" --bare
- Identify the new device:
ls /dev/sd* -la
Note: Compare with the previous listing to identify the new device (e.g., /dev/sdd)
- Create a mount point:
sudo mkdir /mnt/data
- Initialize the disk using fdisk:
sudo fdisk /dev/sdX # Replace X with your disk letter
Enter these commands in sequence:
n
(new partition)p
(primary partition)1
(partition number)- Enter (default first sector)
- Enter (default last sector)
w
(write changes)
- Format the partition:
sudo mkfs.ext4 /dev/sdX1 # Replace X with your disk letter
- Get the partition UUID:
sudo blkid
- Mount the partition:
sudo mount UUID="YOUR-UUID" /mnt/data
- Add to /etc/fstab:
echo 'UUID="YOUR-UUID" /mnt/data ext4 defaults 0 0' | sudo tee -a /etc/fstab
- Configure WSL automount by adding to /etc/wsl.conf:
sudo tee -a /etc/wsl.conf << EOF
[automount]
enabled=true
mountFsTab=true
EOF
- Create a startup script (mount-wsl-vhdx.bat):
wsl --mount --vhd "Z:\Disks\wsl-ubuntu-2404\data_disk.vhdx" --bare
- Create a scheduled task:
- Open Task Scheduler
- Create a new task with these triggers:
- At system startup
- On event: Log: Microsoft-Windows-Hyper-V-Worker/Admin
- Source: Hyper-V-Worker
- Event ID: 18500
This ensures the disk is mounted when:
- Windows starts
- WSL restarts after shutdown
- Any Hyper-V VM starts
Where do you get this "Event ID: 18500" ? Is this a standard or is this something I need to figure out?