Mount a Linux deejay in WSL 2

If yous want to access a Linux disk format that isn't supported by Windows, you lot can employ WSL 2 to mount your disk and access its content. This tutorial volition embrace the steps to identify the disk and partition to attach to WSL2, how to mount them, and how to admission them.

If you are looking for guidance on how to connect a USB device (flash drive, SD bill of fare reader, etc), see Connect USB devices.

Annotation

Administrator admission is required to attach a disk to WSL ii. The WSL 2 mount command does not back up mounting a disk (or partitions that belong to the deejay) that is currently in use. wsl --mount e'er attaches the entire disk fifty-fifty if only a partition is requested. You can't mount the Windows installation disk.

Prerequisites

You will need to be on Windows 11 Build 22000 or higher to admission this feature. You can bring together the Windows Insiders Plan to become the latest preview builds.

Mounting an unpartitioned deejay

In this simplest case, if you lot have a deejay that doesn't have any partitions, y'all tin mount it directly using the wsl --mount command. First yous demand to identify the deejay.

  1. Identify the disk - To list the available disks in Windows, run:

                      Become-CimInstance -query "SELECT * from Win32_DiskDrive"                                  

    The disks paths are available under the 'DeviceID' columns. Unremarkably under the \\.\PHYSICALDRIVE* format.

  2. Mount the disk - Using PowerShell, you tin can mountain the deejay using the Deejay path discovered above, run:

                      wsl --mount <DiskPath>                                  

    Mounting a drive in WSL

Mounting a partitioned deejay

If you have a disk that you aren't sure what file format it is in, or what partitions it has, you can follow the steps below to mountain it.

  1. Identify the disk - To list the available disks in Windows, run:

                      Get-CimInstance -query "SELECT * from Win32_DiskDrive"                                  

    The disks paths are listed after 'DeviceID', usually in the \\.\PHYSICALDRIVE* format.

  2. Listing and select the partitions to mount in WSL two - Once the disk is identified, run:

                      wsl --mount <DiskPath> --bare                                  

    This will make the deejay available in WSL ii. (In the case of our example, the <DiskPath> is \\.\PHYSICALDRIVE*.

  3. Once attached, the sectionalization can be listed by running the post-obit command inside WSL 2:

                      lsblk                                  

    This will display the available block devices and their partitions.

Inside Linux, a cake device is identified every bit /dev/<Device><Partition>. For example, /dev/sdb3, is the sectionalization number 3 of deejay sdb.

Example output:

              NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT sdb      eight:sixteen   0    1G  0 deejay ├─sdb2   8:18   0   50M  0 part ├─sdb3   8:19   0  873M  0 office └─sdb1   eight:17   0  100M  0 part sdc      8:32   0  256G  0 disk / sda      viii:0    0  256G  0 disk                          

Identifying the filesystem blazon

If you don't know the type of filesystem of a disk or partition, y'all can use this control:

              blkid <BlockDevice>                          

This will output the detected filesystem blazon (under the TYPE="<Filesystem>" format).

Mount the selected partitions

Once you have identified the partitions you desire to mountain, run this command on each partition:

              wsl --mountain <DiskPath> --partition <PartitionNumber> --type <Filesystem>                          

Note

If you wish to mount the entire disk every bit a single book (i.eastward. if the disk isn't partitioned), --partition tin can be omitted.

If omitted, the default filesystem type is "ext4".

Access the disk content

Once mounted, the disk can be accessed under the path pointed to by the config value: automount.root. The default value is /mnt/wsl.

From Windows, the disk can be accessed from File Explorer by navigating to: \\wsl$\\<Distro>\\<Mountpoint> (pick any Linux distribution).

Unmount the disk

If yous desire to unmount and detach the disk from WSL ii, run:

              wsl --unmount <DiskPath>                          

Mount a VHD in WSL

You can also mountain virtual hd files (VHD) into WSL using wsl --mount. To practise this, you first need to mount the VHD into Windows using the Mount-VHD control in Windows. Be sure to run this command with administrator privileges. Below is an case where we use this command, and also output the deejay path. Be sure to supplant <pathToVHD> with your bodily VHD path.

              Write-Output "\\.\PhysicalDrive$((Mountain-VHD -Path <pathToVHD> -PassThru | Get-Disk).Number)"                          

Yous tin can use the output to a higher place to obtain the disk path for this VHD and mount that into WSL post-obit the instructions in the previous section.

Y'all can likewise use this technique to mount and interact with the virtual difficult disks of other WSL distros, as each WSL 2 distro is stored via a virtual hard disk file chosen: ext4.vhdx. By default the VHDs for WSL two distros are stored in this path: C:\Users\[user]\AppData\Local\Packages\[distro]\LocalState\[distroPackageName], please exercise circumspection accessing these system files, this is a ability user workflow. Brand certain to run wsl --shutdown before interacting with this disk to ensure the deejay is not in utilize.

Mounting WSL VHD

Command line reference

Mounting a specific filesystem

By default, WSL 2 will effort to mount the device as ext4. To specify another filesystem, run:

              wsl --mount <DiskPath> -t <FileSystem>                          

For case, to mountain a disk as fat, run:

              wsl --mount <Diskpath> -t vfat                          

Note

To list the available filesystems in WSL2, run: true cat /proc/filesystems
When a disk has been mounted via WSL2 (Linux file organisation), it is no longer bachelor to mount via an ext4 driver on the Windows file organization.

Mounting a specific partition

By default, WSL 2 attempts to mount the unabridged disk. To mount a specific sectionalisation, run:

              wsl --mountain <Diskpath> -p <PartitionIndex>                          

This only works if the deejay is either MBR (Master Boot Tape) or GPT (GUID Partition Table). Read about partition styles - MBR and GPT.

Specifying mount options

To specify mountain options, run:

              wsl --mount <DiskPath> -o <MountOptions>                          

Case:

              wsl --mountain <DiskPath> -o "data=ordered"                          

Note

But filesystem specific options are supported at this time. Generic options such as ro, rw, noatime, ... are not supported.

Attaching the deejay without mounting it

If the disk scheme isn't supported by any of the higher up options, yous can attach the disk to WSL 2 without mounting it past running:

              wsl --mount <DiskPath> --bare                          

This will brand the cake device available inside WSL two so it can be mounted manually from there. Apply lsblk to list the bachelor block devices inside WSL 2.

Specifying the mountain name

By default the mountpoint proper name is generated based on the physical disk or VHD proper name. This can be overriden with --name. Example:

              wsl --mount <DiskPath> --proper name myDisk                          

Detaching a deejay

To detach a disk from WSL 2, run:

              wsl --unmount [DiskPath]                          

If Diskpath is omitted, all attached disks are unmounted and discrete.

Note

If i deejay fails to unmount, WSL 2 tin can exist forced to exit by running wsl --shutdown, which will detach the disk.

Limitations

  • At this time, merely unabridged disks tin be fastened to WSL 2, pregnant that it's not possible to attach simply a partition. Concretely, this means that information technology'due south non possible to use wsl --mount to read a partition on the kick device, considering that device can't be detached from Windows.

  • Only filesystems that are natively supported in the kernel can exist mounted past wsl --mountain. This means that it'due south not possible to use installed filesystem drivers (such as ntfs-3g for example) past calling wsl --mount.