Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Windows 11 / Mount Physical and Network Drives in WSL2 (Windows Subsystem for Linux)

August 6, 2024

Mount Physical and Network Drives in WSL2 (Windows Subsystem for Linux)

There are several ways to mount and access physical, virtual, or network drives in Windows Subsystem for Linux (WSL2). By default, the WSL environment mounts all Windows logical drives to the /mnt/ directory. In addition, you can access the WSL file system directly from File Explorer running on the Windows host by using the UNC path \\wsl$\ (for example, \\wsl$\ubuntu).

This guide explains how to mount different drives in a WSL environment.

Contents:
  • How to Mount Physical Drive (Partition) in WSL2
  • Mounting Windows Network Drives in WSL
  • Attach Virtual Hard Drive (VHD/VHDX) in WSL

List Windows drives in WSL

How to Mount Physical Drive (Partition) in WSL2

Windows Subsystem for Linux (WSL 2) makes it possible to mount physical drives or specific partitions with file systems that are not supported by the Windows host itself. The /proc/filesystems file contains the list of supported filesystems in WSL.

For example, you have a physical disk with ext4 partitions on it and you want to access them from WSL.

Before proceeding, check and update your WSL 2 version:

wsl --update

Then list the available disk devices in Windows:

wmic diskdrive list brief

Two physical disks are connected to the computer in this example.

wmic diskdrive list brief - list connected physical drives

You can mount an entire hard disk drive in the WSL:

wsl --mount \\.\PHYSICALDRIVE2

Or just a specific partition:

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

wsl - mount physical disk or partition

The partition of the physical hard disk will be mounted in the directory /mnt/wsl/PHYSICALDRIVE2p1.

You can access files on this partition from a Windows host using a UNC path: \\wsl$\ubuntu\mnt\wsl\PHYSICALDRIVE2p1.

Check that the ext4 filesystem partition is accessible in WSL:

$ lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT

lsblk - view connected partitions and filesystems in wsl2

To unmount the partition, run:

wsl --umount \\.\PHYSICALDRIVE2 --partition 1

To automatically mount a physical disk partition when a user logs on to Windows, create a simple scheduler task using PowerShell:

$TaskName="WSL_Mount_DISK1_PART1"
$Trigger= New-ScheduledTaskTrigger -AtLogOn
$Action= New-ScheduledTaskAction -Execute "cmd" -Argument "/c wsl --mount \\.\PHYSICALDRIVE2 --partition 1"
Register-ScheduledTask -TaskName $TaskName -Trigger $Trigger -Action $Action -RunLevel Highest –Force

WSL 2 doesn’t currently support the mounting of USB drives or SD cards. To attach USB storage devices to WSL, it is recommended to use the usbipd-win package (allows to passthrough external USB devices using the USB over IP protocol).

Mounting Windows Network Drives in WSL

In WSL, you can access shared folders on network computers or NAS devices. There are two ways to mount network drives in WSL:

  • You can mount a network drive that is mapped in Windows and has a drive letter assigned to it.
  • It is possible to use the CIFS/SMB client in WSL to mount a shared network folder using a UNC path.

For example, you have mapped a network drive using GPO or with the net use X: \\192.168.100.12\tools command. To access this network drive from WSL:

  1. Create a mount point: $ sudo mkdir /mnt/x
  2. Mount the drive: $ sudo mount -t drvfs X: /mnt/x
  3. Now you can access files and folders on the network drive.

To automatically mount this network drive, add the following line to /etc/fstab:

X: /mnt/x drvfs defaults 0 0

Then mount all the file systems:

$ mount -a

Mounting mapped network drives in WSL using drvfs

Shared network folders can also be mounted directly from SMB-enabled devices using the CIFS package.

$ sudo apt install cifs-utils
$ sudo mount -t cifs -o user={user},pass={password},iocharset=utf8,vers=3.0 //192.168.100.12/tools /mnt/tools

This example uses the SMB 3.0 protocol to connect to shared folders instead of SMBv1 which is disabled by default in current versions of Windows.

Attach Virtual Hard Drive (VHD/VHDX) in WSL

VHD/VHDX virtual hard disks can also be mounted with WSL. If the Hyper-V PowerShell module is installed on the computer, create a new virtual disk file using the command:

New-VHD -Path $env:USERPROFILE\wsl_shared_disk.vhdx -Dynamic -SizeBytes 20GB

Then mount the VHDX file in WSL:

wsl --mount --vhd $env:USERPROFILE\wsl_shared_disk.vhdx --bare

Now you can create a partition table and a partition with the ext4 file system on the virtual disk:

$ lsblk
$ sudo parted /dev/sdc print
$ sudo parted /dev/sdc mklabel msdos
$ sudo parted -a optimal /dev/sdc mkpart primary ext4 0% 100%
$ lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT /dev/sdc
$ sudo mkfs.ext4 /dev/sdd1

Connecting virtual disk image (VHDX) in WSL2

Then you can mount a new partition to a directory by its UUID:

$ sudo blkid
$ sudo mount UUID=c04d0309-b93a-47f2-ae0d-79c95c80cd51 /home/sysops/vhdx

Using this method, you will be able to mount the virtual hard disks of other Linux environments that are installed on this computer under WSL. The Linux WSL image file system is stored in the ext4.vhdx virtual disk in the C:\Users\[user]\AppData\Local\Packages\[distro]\LocalState\[distroPackageName] folder. If you don’t have enough free space on the system drive, you can move the VHDX file that contains the WSL image file system to another drive.
0 comment
4
Facebook Twitter Google + Pinterest
Windows 10Windows 11
previous post
Change Network Connection (Adapter) Priorities in Windows
next post
How to Hide or Show Specific Settings Pages in Windows 11

Related Reading

Managing Windows Firewall Rules with PowerShell

March 11, 2024

Create a Custom Windows Image with Pre-installed Apps

February 28, 2024

Fixing ‘The Network Path Was Not Found’ 0x80070035...

August 31, 2023

Upgrading to Windows 11 on Unsupported Hardware

March 6, 2024

Installing Language Pack in Windows 10/11 with PowerShell

September 20, 2023

Configuring RemoteApps Hosted on Windows 10/11 (without Windows...

January 25, 2025

How to Assign (Passthrough) a Physical GPU to...

June 11, 2024

Disable BitLocker Automatic Drive Encryption in Windows 11

October 16, 2024

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Configuring Windows Protected Print Mode (WPP)

    May 19, 2025
  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • How to Allow Multiple RDP Sessions on Windows 10 and 11
  • How to Run Program without Admin Privileges and Bypass UAC Prompt
  • Fix: BSOD Error 0x0000007B (INACCESSABLE_BOOT_DEVICE) on Windows
  • Fixing ‘The Network Path Was Not Found’ 0x80070035 Error Code on Windows
  • How to Delete Old User Profiles in Windows
  • How to Install Remote Server Administration Tools (RSAT) on Windows
  • How to Backup and Copy Local Group Policy Settings to Another Computer
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top