Back to Blog
tutorialIntermediate8 min read

Mount Physical Drive

How to mount a physical drive in WSL

Pass Physical Disk to WSL2

Identify Disks

Press WIN + x and then select "Terminal (Admin)" or right click on the start menu and select "Terminal (Admin)". Then execute the following command to identify the disks

GET-CimInstance -query "SELECT * from Win32_DiskDrive"

PowerShell GET-CimInstance Disk Drive Output
PowerShell GET-CimInstance Disk Drive Output

Each disk has a device ID like \\.\PHYSICALDRIVE1. The 1 at the end typically indicates the Disk number as shown in the Disk Management tool. Open up Disk Management by press WIN + x and then selecting "Disk Management".

Windows Disk Management with Unallocated Disks
Windows Disk Management with Unallocated Disks

As can be seen, there is a Disk 0, 1, and 2. This corresponds to \\.\PHYSICALDRIVE0, \\.\PHYSICALDRIVE1, and \\.\PHYSICALDRIVE2.

Attach Disk

Once the disk is identified, copy the "DeviceID" value and attach the drive. As an example, I will use \\.\PHYSICALDRIVE1

wsl --mount \\.\PHYSICALDRIVE1 --bare

This attaches the drive but does not mount it. The disk must be formatted with the ext4 partition before it can be mounted.

WSL Mount Bare Command Output
WSL Mount Bare Command Output

Log into WSL

wsl

Identify Disk Pt. 2

View block devices to identify the disk

lsblk

WSL lsblk Block Device List
WSL lsblk Block Device List

In this example, I can see the disk sdd is the 128G disk I attached. It needs to be formatted and mounted.

Format Disk

Format the disk with ext4.

sudo mkfs.ext4 -m 0 /dev/sdd

The -m 0 sets the reserved space for the disk to 0 and is optional. The disk is now ready to be mounted.

Mount Disk

Create a mount point for the drive. I prefer to mount to /media

sudo mkdir /media/ssd

Then mount the drive

sudo mount /dev/sdd /media/ssd

Confirm the drive has been mounted

df -h

Get the UUID of the disk and save it

lsblk -f

This mount is only temporary until the .wslconfig is updated. First, add an entry to the FSTAB file

sudo nano /etc/fstab

Below the comment, add the following, updating the UUID to match

UUID=<UUID> /media/ssd ext4 defaults 0 0

Press CTRL + x, then y, then ENTER. Exit Ubuntu

exit

Auto Mount

There are two actions that need to occur in order for the disk to be mounted inside WSL to the correct location. The FSTAB has already been updated. Next, Windows needs to mount the physical disk at login. To do this, a scheduled task can be created.

Schedule Task

In the windows search, type in "Task Scheduler" and select the application

Windows Task Scheduler Search Result
Windows Task Scheduler Search Result

Once open, on the right side click "Create Task...". Then follow the steps below:

  1. Set the Name to "WSL Mount Task"
  2. Check "Run only when user is logged on"
  3. Check "Run with highest privileges"

Task Scheduler Create Task General Tab
Task Scheduler Create Task General Tab

Click the "Triggers" tab. Then follow the steps below:

  1. Click "New..." to create a new Trigger
  2. In the "Begin the task" drop down, select "At log on"
  3. Ensure the "Enabled" checkbox is checked
  4. Click "OK" to add the Trigger

Task Scheduler Edit Trigger At Log On
Task Scheduler Edit Trigger At Log On

Click the "Actions" tab. Then follow the steps below:

  1. Click "New..." to create an Action
  2. For "Program/script" type cmd.exe
  3. For "Add arguments" paste in /c wsl --mount \\.\PHYSICALDRIVE1 --bare replacing PHYSICALDRIVE1 as needed.
  4. Click "OK" to add the Action

Task Scheduler Edit Action WSL Mount
Task Scheduler Edit Action WSL Mount

Click the "Conditions" tab. Then uncheck all boxes.

Click the "Settings" tab. Then follow the steps below:

  1. Check "Allow task to be run on demand"
  2. Check "Run task as soon as possible after a scheduled start is missed"
  3. Check "Stop the task if it runs longer than 3 days"
  4. Check "If the task does not end when requested for it to stop"

Once all sections have been completed click "OK".

Reboot the computer.

Verify

Press WIN + x and then select "Terminal(Admin)". Then open wsl

wsl

Once logged in, verify that the disk is mounted

df -h

The disk should now be mounted.