LocalHake

Tutorial

Mount Physical Drive

How to mount a physical drive in WSL

Hake HardwarePublished Updated ~8 minadvanced

This post contains paid links (affiliate) — how that works.


▶ Watch this build on YouTube
Contents

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:

bash
GET-CimInstance -query "SELECT * from Win32_DiskDrive"
PowerShell terminal showing GET-CimInstance Win32_DiskDrive output listing physical drives

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 showing 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

bash
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.

PowerShell showing wsl --mount bare command completing successfully

Log into WSL:

bash
wsl

Identify Disk Pt. 2

View block devices to identify the disk:

bash
lsblk
WSL terminal showing lsblk output with attached physical drive

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:

bash
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:

bash
sudo mkdir /media/ssd

Then mount the drive:

bash
sudo mount /dev/sdd /media/ssd

Confirm the drive has been mounted:

bash
df -h

Get the UUID of the disk and save it:

bash
lsblk -f

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

bash
sudo nano /etc/fstab

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

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

Save with Ctrl+X, Y, Enter. Exit Ubuntu:

bash
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 search bar showing Task Scheduler as best match

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 dialog on General tab with WSL Mount Task name

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 dialog set to 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 dialog with cmd.exe and wsl mount command

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:

bash
wsl

Once logged in, verify that the disk is mounted:

bash
df -h

The disk should now be mounted.

Gear used