Categories
Self-organization

How to mount removable drives and network locations in the windows subsystem for linux

This post shows students and new users steps to mount and unmount a removable USB or thumb drive in the Windows Systems for Linux (WSL) environment. Windows 11 allows users to mount removable drives with ease. Simply insert a removeable drive, and Windows will recognize and mount it.

However, when running WSL, mounting removable drives inside of the WSL environment isn’t that easy.

Windows Subsystem for Linux allows you to manually mount drives using the mount command. WSL will automatically mounts all fixed NTFS drives. So, if you have an internal fixed C: and E: drives, you’ll see them mounted at /mnt/c and /mnt/e in your WSL environment.

For external, removable drive, you’ll have to manually mount those in WSL. DrvFs also allows you to mount external drives like USB, CDs, and DVDs. These devices must be formatted using Windows file system like NTFS or FAT.

Similarly to internal drives, external drives will remain accessible in Windows 11 when mounted within the Windows Subsystem for Linux environment.

Below is how one can mount an external drive in WSL environment.

How to mount an external drive in WSL

As mentioned above, one can mount external drive like USB, CD and other devices in Windows System for Linux.

For example, if you have an external drive attached to your Windows 11 computer using the drive letter F: , you can mount it in WSL using the commands below.

You’ll now be able to access the drive content in Linux at the mount point /mnt/f .

To unmount the drive, simply run the commands below.

That should do it!

Conclusion:

This post showed you how to mount an external, removable drive in WSL environment. If you find any error above or have something to add, please use the comment form below.

Published by Richard

In my spare time, I research topics that are interesting and worthwhile for users and students who want to try something new. I, too, am a student and my focus here is to help other students and new users get started with managing Ubuntu Linux, Windows, Content Management Systems (CMS) and others.

I try to do my best explaining the topics and detailing the instructions so that anyone can understand. These tutorials may not work in all situations and for all users. However, if you run into trouble, please ask your questions below and I or someone from the community may help you resolve. Thanks for reading and hope you come back.

  • Вложения (0)
  • История Страницы
  1. Страницы
  2. Welcome to the Standalone MESH Wiki!
  3. Resources
  4. Operating platforms and systems
  5. Windows Subsystem for Linux (WSL)
  6. WSL How-to articles

This page describes how to mount a missing Windows drive letter and Windows network location inside the Ubuntu Terminal installed for the Windows Subsystem for Linux (WSL).

If a Windows drive letter is missing from inside the /mnt/ folder, it can be mounted manually.

To mount a missing Windows drive letter, first create a folder for the drive inside the /mnt/ folder and then mount the Windows drive location:

Create a folder for the drive letter inside the /mnt/ folder if one does not already exist:

Use the ” mount ” command with the ” drvfs ” drive type to associate the folder with the Windows drive:

If a network location has not been mapped to a specific drive letter in Windows (if so, use the above approach), it can be mapped directly.

To mount a network location directly:

Create a folder for the location inside the /mnt/ folder if one does not already exist:

Use the ” mount ” command to associate the folder with the network location:

If a temporary location was mounted inside the Ubuntu Terminal, it can be removed by using the ” umount ” command:

Run the ” umount ” with the path of the currently mounted folder:

Optionally, remove the temporary folder:

The ” rmdir ” command is used instead of ” rm -r ” to ensure the location was properly unmounted. The ” rmdir ” command will only remove empty folders, where if the location was not properly unmounted, ” rm -r ” would remove all contents of the file system mapped to that location.

To double-check if the folder is empty before running this command, do a listing on the folder:

If you want to access a Linux disk format that isn’t supported by Windows, you can use WSL 2 to mount your disk and access its content. This tutorial will cover the steps to identify the disk and partition to attach to WSL2, how to mount them, and how to access them.

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

Administrator access is required to attach a disk to WSL 2. The WSL 2 mount command does not support mounting a disk (or partitions that belong to the disk) that is currently in use. wsl –mount always attaches the entire disk even 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 later to access this feature. You can join the Windows Insiders Program to get the latest preview builds.

Mounting an unpartitioned disk

In this simplest case, if you have a disk that doesn’t have any partitions, you can mount it directly using the wsl –mount command. First you need to identify the disk.

Identify the disk – To list the available disks in Windows, run:

The disks paths are available under the ‘DeviceID’ columns. Usually under the \\.\PHYSICALDRIVE* format.

Mount the disk – Using PowerShell, you can mount the disk using the Disk path discovered above, run:

Mounting a partitioned disk

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 mount it.

Identify the disk – To list the available disks in Windows, run:

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

List and select the partitions to mount in WSL 2 – Once the disk is identified, run:

This will make the disk available in WSL 2. (In the case of our example, the is \\.\PHYSICALDRIVE* .

Once attached, the partition can be listed by running the following command inside WSL 2:

This will display the available block devices and their partitions.

Inside Linux, a block device is identified as /dev/

. For example, /dev/sdb3, is the partition number 3 of disk sdb .

Identifying the filesystem type

If you don’t know the type of filesystem of a disk or partition, you can use this command:

This will output the detected filesystem type (under the TYPE=” ” format).

Mount the selected partitions

Once you have identified the partitions you want to mount, run this command on each partition:

If you wish to mount the entire disk as a single volume (i.e. if the disk isn’t partitioned), –partition 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$\\ \\ (pick any Linux distribution).

Unmount the disk

If you want to unmount and detach the disk from WSL 2, run:

Mount a VHD in WSL

WSL from the Microsoft Store introduces a new argument to directly mount a VHD: wsl –mount –vhd

You can also mount virtual hard disk files (VHD) into WSL using wsl –mount . To do this, you first need to mount the VHD into Windows using the Mount-VHD command in Windows. Be sure to run this command with administrator privileges. Below is an example where we use this command, and also output the disk path. Be sure to replace

with your actual VHD path.

You can use the output above to obtain the disk path for this VHD and mount that into WSL following the instructions in the previous section.

You can also use this technique to mount and interact with the virtual hard disks of other WSL distros, as each WSL 2 distro is stored via a virtual hard disk file called: ext4.vhdx . By default the VHDs for WSL 2 distros are stored in this path: C:\Users\[user]\AppData\Local\Packages\[distro]\LocalState\[distroPackageName] , please exercise caution accessing these system files, this is a power user workflow. Make sure to run wsl –shutdown before interacting with this disk to ensure the disk is not in use.

Command line reference

Mounting a specific filesystem

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

For example, to mount a disk as fat, run:

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

Mounting a specific partition

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

This only works if the disk is either MBR (Master Boot Record) or GPT (GUID Partition Table). Read about partition styles – MBR and GPT.

Specifying mount options

To specify mount options, run:

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

Attaching the disk without mounting it

If the disk scheme isn’t supported by any of the above options, you can attach the disk to WSL 2 without mounting it by running:

This will make the block device available inside WSL 2 so it can be mounted manually from there. Use lsblk to list the available block devices inside WSL 2.

Specifying the mount name

This option is only available with WSL from the Microsoft Store

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

Detaching a disk

To detach a disk from WSL 2, run:

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

If one disk fails to unmount, WSL 2 can be forced to exit by running wsl –shutdown , which will detach the disk.

Limitations

At this time, only entire disks can be attached to WSL 2, meaning that it’s not possible to attach only a partition. Concretely, this means that it’s not possible to use wsl –mount to read a partition on the boot device, because that device can’t be detached from Windows.

Only filesystems that are natively supported in the kernel can be mounted by wsl –mount . This means that it’s not possible to use installed filesystem drivers (such as ntfs-3g for example) by calling wsl –mount .

Filesystems not directly supported by the kernel can be mounted via a –bare attach and then invoking the relevant FUSE driver.

Taylor Gibb is a professional software developer with nearly a decade of experience. He served as Microsoft Regional Director in South Africa for two years and has received multiple Microsoft MVP (Most Valued Professional) awards. He currently works in R&D at Derivco International. Read more.

Mapping a network drive to a shared folder from Windows’ graphic interface isn’t hard. But if you already know the network path for the shared folder, you can map drives a lot quicker using the Command Prompt.

Mapping a drive to a network share assigns that share a drive letter so that it’s easier to work with. We’ll be using the net use command in Command Prompt to map a network drive for this tutorial. You can also use the same command in PowerShell if you prefer.

To map a network drive, type the following command and then hit Enter:

DRIVE is the drive letter you want to use and PATH is the full UNC path to the share. So, for example, if we wanted to map drive letter S to the share \\tower\movies, we’d use the following command:

If the share to which you’re connecting is protected with some sort of authentication, and you’d rather not type in the credentials every time you open the network drive, you can add the user name and password to the command with the /user: switch. For example, if we wanted to connect the same share from above, but with the username HTG and the password CrazyFourHorseMen, we’d use the command:

By default, mapped drives are not persistent. If we map drives using the commands we’ve talked about so far, the mapped drives would disappear when you restarted your computer. If you’d rather those mapped drives stick around, you can make them persistent by using the /persistent switch. The switch works as a toggle:

  • /persistent:Yes: Makes the connection you’re currently creating persistent. Future connections you make using the command during the same session are also persistent (you don’t need to keep using the switch) until you use the /persistent:No switch to turn it off.
  • /persistent:No: Turns off the persistency toggle. Future connections you make are not persistent until you turn the toggle back on.

So, essentially, you could type something like the following command:

And the drive map would be persistent. All future mapping you create (even if you don’t use the /persistent:Yes switch) will also be persistent until you turn it off using the /persistent:No switch.

If you ever need to delete a mapped network drive, all you have to do is specify the drive letter and add the /delete switch. For example, the following command would delete the drive mapping we assigned to drive S:

You can also use the asterisk as a wildcard should you ever want to delete all your mapped drives in one go:

And that’s all there is to it. Once you get used to using the command, you’ll find it a lot quicker than clicking through File Explorer’s interface–especially if you work with mapped drives often.

In the latest Windows Insider build, the Windows Subsystem for Linux (WSL) now allows you to manually mount Windows drives using the DrvFs file system. Previously, WSL would automatically mount all fixed NTFS drives when you launch Bash, but there was no support for mounting additional storage like removable drives or network locations.

Now, not only can you manually mount any drives on your system, we’ve also added support for other file systems such as FAT, as well as mounting network locations. This enables you to access any drive, including removable USB sticks or CDs, and any network location you can reach in Windows all from within WSL.

There’s a lot of work being done on WSL.

About The Author

Thom Holwerda

Follow me on Twitter @thomholwerda

8 Comments

Now, not only can you manually mount any drives on your system, we’ve also added support for other file systems such as FAT, as well as mounting network locations. This enables you to access any drive, including removable USB sticks or CDs, and any network location you can reach in Windows all from within WSL.

Passing mount points to linux is a nice addition for WSL, I suppose, but to be honest most real unix/linux users take these kinds of capabilities for granted and it’s just the WSL subsystem catching up with a glorified bind mount.

At first glace, I was actually hoping this would be the other way around and that windows was finally adding support for linux native file systems like fuse, extfs, btrfs. These would be very helpful for users who are running real linux workstations alongside windows ones.

Edited 2017-04-19 21:12 UTC

At first glace, I was actually hoping this would be the other way around and that windows was finally adding support for linux native file systems like fuse, extfs, btrfs. These would be very helpful for users who are running real linux workstations alongside windows ones.

They added WSL to Windows and WSL has support for those file systems. So people that are running linux workstations can access those from inside WSL with the tooling that they are used to from Linux.

I agree that Windows would be better with out-of-the box-support for more filesystems but adding WSL has solved all my requirements.

Is it just me or is the naming just wrong?

If something is called “Windows Subsystem for Linux” I would expect something like Wine: a subsystem that runs on a Linux-Kernel.

But this thing runs on Windows … so it is a subsystem for Windows, or more precise:

a Linux Subsystem for Windows.

In Microsoft terminology, Windows always comes first!

They’re just using a different Endianness to you.

It isn’t a Subsystem for Windows, it’s a Windows Subsystem. Winnt was designed to alow multiple subsystems or personalities, the most used is the Subsystem for Windows (csrss.exe).

It isn’t a Subsystem for Windows, it’s a Windows Subsystem. Winnt was designed to alow multiple subsystems or personalities, the most used is the Subsystem for Windows (csrss.exe).

So you are saying, the Subsystem for Windows is a Windows Subsystem, as is the Subsystem for Linux…

I haven’t tried it recently, but, can I make changes to the WSL tree from outside of the bash shell and have it reflected? Previusly, if I decided to copy files into the WSL tree via Explorer (Or, usually, Total Commander), they would remain invisible….

timeline Stats

This page shows how to install Windows Subsystem for Linux (WSL) system on a non-system drive manually. It can work with both WSL 1 and WSL 2.

Enable Windows Subsystem for Linux system feature

Open PowerShell as Administrator and run the following command to enable WSL feature:

Create a folder in a non-system drive

Run the following command in PowerShell to create a folder for the installation. For my environment, I will create the folder in F drive.

Download a Linux distro

Run the following command in PowerShell to download a distro:

The following distros are available:

Unpack the downloaded distro

Run the following PowerShell commands to unpack:

Initialize Linux distro

In the unzipped folder, there is one executable (*.exe).

Mode LastWriteTime Length Name
—- ————- —— —-
d—– 15/05/2019 7:40 PM AppxMetadata
d—– 15/05/2019 7:40 PM Assets
-a—- 17/08/2018 3:15 AM 212438 AppxBlockMap.xml
-a—- 17/08/2018 3:15 AM 3835 AppxManifest.xml
-a—- 17/08/2018 3:17 AM 11112 AppxSignature.p7x
-a—- 17/08/2018 3:15 AM 223983209 install.tar.gz
-a—- 17/08/2018 3:15 AM 5400 resources.pri
-a—- 17/08/2018 3:15 AM 211968 ubuntu1804.exe
-a—- 17/08/2018 3:15 AM 744 [Content_Types].xml

* Based on the version of Linux distro you are using, the executable name can be different.

Run the executable to initialize:

* You need to input a user name and password. I am using username raymond with ‘password’ as password.

Once the installation is done, you can see a new folder is created:

Mode LastWriteTime Length Name
—- ————- —— —-
d—– 15/05/2019 7:40 PM AppxMetadata
d—– 15/05/2019 7:40 PM Assets
da—- 15/05/2019 7:47 PM rootfs
d—– 15/05/2019 7:49 PM temp
-a—- 17/08/2018 3:15 AM 212438 AppxBlockMap.xml
-a—- 17/08/2018 3:15 AM 3835 AppxManifest.xml
-a—- 17/08/2018 3:17 AM 11112 AppxSignature.p7x
-a—- 17/08/2018 3:15 AM 223983209 install.tar.gz
-a—- 17/08/2018 3:15 AM 5400 resources.pri
-a—- 17/08/2018 3:15 AM 211968 ubuntu1804.exe
-a—- 17/08/2018 3:15 AM 744 [Content_Types].xml

If you install WSL from Microsoft Store, the default folder in your Windows user profile will be used:

rootfs folder includes the following folders:

Mode LastWriteTime Length Name
—- ————- —— —-
da—- 15/05/2019 7:47 PM bin
da—- 15/05/2019 7:44 PM boot
da—- 15/05/2019 7:44 PM dev
da—- 15/05/2019 7:48 PM etc
da—- 15/05/2019 7:48 PM home
da—- 15/05/2019 7:44 PM lib
da—- 15/05/2019 7:44 PM lib64
da—- 15/05/2019 7:44 PM media
da—- 15/05/2019 7:47 PM mnt
da—- 15/05/2019 7:44 PM opt
da—- 15/05/2019 7:44 PM proc
da—- 15/05/2019 7:44 PM root
da—- 15/05/2019 7:44 PM run
da—- 15/05/2019 7:44 PM sbin
da—- 15/05/2019 7:44 PM snap
da—- 15/05/2019 7:44 PM srv
da—- 15/05/2019 7:44 PM sys
da—- 15/05/2019 7:56 PM tmp
da—- 15/05/2019 7:46 PM usr
da—- 15/05/2019 7:47 PM var
-a—- 15/05/2019 7:56 PM 87944 init

These folders include all the Ubuntu folders (libs, executables, etc.).

List all the WSL installations

You can install many Linux distributions in one Windows system.

wslconfig command can be used to list all the installed distributions and set default distribution:

Find out all the WSL installations in your Windows system using the following command:

Set default distribution:

Run the following command to start the default WSL distribution:

To uninstall a distribution, use the following command:

Now you have a WSL installed in a non-system drive. Have fun!

Kontext Newsletter

Subscribe to Kontext Newsletter to get updates about data analytics, programming and cloud related articles. You can unsubscribe at anytime.

Med Windows 10s Fall Creators Update kan Windows Subsystem til Linux nu manuelt montere drev. Det monterer automatisk alle interne NTFS-drev automatisk. Men du kan nu manuelt montere eksterne drev og netværksmapper ved hjælp af kommandoen Linux mount .

Sådan monteres eksterne enheder

RELATERET: Alt du kan gøre med Windows 10’s nye Bash Shell

Windows-delsystemet til Linux stiller stadig fast faste NTFS-drev. Så hvis du har et internt C: drev og D: -drev, kan du se dem på / mnt / c og / mnt / d i Linux-miljøet.

DrvFs giver dig nu mulighed for at montere eksterne drev som USB-sticks, Cd’er og dvd’er. Disse enheder skal bruge et Windows-filsystem som NTFS, ReFS eller FAT. Du kan stadig ikke montere enheder formateret med et Linux-filsystem som ext3 eller ext4.

Ligesom med interne drev, vil disse eksterne drev stadig forblive tilgængelige i Windows, efter at du har monteret dem i Linux-miljøet. Montage dem gør også dem også tilgængelige fra skalmiljøet.

Lad os sige, at du har et eksternt drev G: der repræsenterer enten et USB-drev eller et optisk drev. Hvis du vil montere det, skal du køre følgende kommandoer:

Du skal faktisk ikke montere drevet på / mnt / g , selvfølgelig. Du kan montere det, hvor du vil. Udskift kun begge forekomster af / mnt / g i kommandoerne med den ønskede vej.

For at afmontere drevet senere, så du kan fjerne det sikkert, skal du køre standard umount kommandoen:

Når der arbejdes med en ekstern enhed, der er formateret med et FAT-filsystem eller et netværksfilsystem, er der nogle begrænsninger. Filsystemet er ikke sagerkänsligt, og du kan ikke oprette symbolske links eller hårde links på det.

Sådan monteres netværkssteder

Du kan også montere netværkspladser. En hvilken som helst netværksplacering, du kan nå fra Windows, kan du montere fra Linux-skalen.

Netværksplaceringer kan monteres på to måder. Hvis du kortlægger et netværksdrev til et drevbogstav, kan du montere det ved hjælp af de samme muligheder som ovenfor. Dette ville give dig mulighed for nemt at logge ind på netværksdelingen og indtaste dine legitimationsoplysninger i File Explorer. For eksempel, hvis dit kortlagte netværksdrev er F :, kan du køre følgende kommandoer for at montere det:

Du kan også angive en køre med sin UNC (Universal Naming Convention) -sti. Hvis stien til netværksandelen f.eks. Er \ server mappe , kører du følgende kommando. Brug igen det monteringspunkt du kan lide i stedet for / mnt / folder .

RELATERET: Sådan kortlægger du netværksdrev fra kommandoprompt i Windows

Windows-delsystemet til Linux-miljøet giver ingen mulighed for at angive de legitimationsoplysninger, du vil bruge. Du kan angive legitimationsoplysningerne ved at navigere til mappen i Filutforsker i Windows, indtaste dem via Credential Manager eller ved at bruge kommandoen netforbrug.

Du kan køre kommandoen netbrug inde fra Linux-miljø, da Windows-subsystemet til Linux giver dig mulighed for at starte Windows-software fra Linux-kommandolinjen. Bare kør kommandoen som sådan:

F.eks. Vil følgende kommando forbinde til \ server mappe med brugernavnet Bob og adgangskoden LetMeIn og map det til din F: drev. Her er kommandoen du vil køre:

Når du har tilsluttet en gang, vil Windows huske dette brugernavn og adgangskode og automatisk bruge dem selv når du Brug kommandoen mount i Linux-miljøet.

Hvis du vil afmontere en netværksplacering, kan du bruge standard umount kommandoen igen:

DrvFs indstiller ikke Linux-tilladelserne nøjagtigt, når du monterer en netværksplacering. I stedet synes alle filer på netværksfilsystemet at have fuld adgangstilladelse (0777), og du kan kun se, om du har adgang til en fil ved at prøve at åbne den. Filsystemet vil heller ikke være sagerfølsomt, og du kan ikke oprette symbolske links på dem.

Hvis du er fan af at bruge Windows PowerShell i stedet for kommandoprompt, kan du godt lide At få adgang til det lige fra den sammenhængsmenu, du får, når du højreklikker på en mappe i Windows. Sådan gør du det. Windows indeholder allerede et “Åbn kommandovindue her”, når du Shift + klikker på en mappe.

Første ting først. Lad os tale om, hvad statuslinjen er. Øverst på din Android-telefonens hovedgrænseflade er opdelt i to definerede områder: meddelelseslinjen og statuslinjen. Den førstnævnte er, hvor alle dine anmeldelser er indkvarteret, når de kommer ind, vises simpelthen som ikoner for at fortælle dig, at der er noget, der har brug for din opmærksomhed.

I’m a software engineer building tooling for Visual Studio and Visual Studio Code to support C++ embedded device development. These physical devices typically connect to a computer over USB, but we discovered we couldn’t use WSL to test our tools on Linux because it does not support USB. We weren’t alone — support for connecting physical USB devices to WSL is highly requested by the community as well.

While this functionality is still not natively available in WSL, I’m excited to announce that our summer intern, Nelson Daniel Troncoso Aldas, contributed changes to the open-source usbipd-win project to enable common developer USB scenarios like flashing an Arduino or accessing a smartcard reader.

Setup

To get started with this functionality, first ensure you’re running Windows 11 and have installed all WSL updates. Running uname -a from within WSL should report a kernel version of 5.10.60.1 or later. You’ll need to be running a WSL 2 distro.

From within WSL, install the user space tools for USB/IP and a database of USB hardware identifiers. The instructions below are for Ubuntu — other distributions may require a different usbip client package. On Ubuntu 20.04 LTS, run these commands:

At this point a service is running on Windows to share USB devices, and the necessary tools are installed in WSL to attach to shared devices.

Attaching a device

First ensure a WSL command prompt is open. This will keep the WSL 2 lightweight VM active.

From an administrator command prompt on Windows, run this command. It will list all the USB devices connected to Windows.

Select the bus ID of the device you’d like to attach to WSL and run this command. You’ll be prompted by WSL for a password to run a sudo command.

From within WSL, run lsusb to list the attached USB devices. You should see the device you just attached and be able to interact with it using normal Linux tools. Note that depending on your application, you may need to configure udev rules to allow non-root users to access the device.

Once you are done using the device in WSL, you can either physically disconnect the device or run this command from an administrator command prompt on Windows.

How it works

This functionality takes advantage of the USB/IP protocol to forward USB traffic over the virtual network interface between Windows and WSL. Code for USB/IP support has existed in the Linux kernel since 2009, but several recent changes made it easier to use in WSL.

  • We updated the configuration options for the WSL Linux kernel to enable USB/IP support. This simplifies setup in WSL and avoids requiring users to build the kernel themselves.
  • While support for attaching devices over USB/IP exists in Linux (a client), there was no corresponding server support for USB/IP in Windows. usbipd-win fills this gap. We contributed a command line interface to the project to both enable a USB device for sharing on Windows and attach it from within WSL.

We’d also like to give a shoutout to Frans van Dorsselaer, a system architect from the Netherlands who started usbipd-win. In his own words:

This started as a personal hobby project to get a single device working. I recently switched from VirtualBox to Hyper-V, but I was missing the USB passthrough functionality for my device. Unhappy with the existing solutions, either expensive commercial solutions or open-source projects that required unsigned drivers, I decided that I could do this! I read up on the USB standard, the USBIP implementation in the Linux kernel, and the VirtualBox driver source code. Next, a colleague of mine asked if his USB token would work too. Of course, it didn’t, but I decided to publish the project on GitHub and make it feature complete. Microsoft found my project and decided to help make it more mature with a proper management interface and support for WSL. And that is where we are now: configurable USB passthrough for Hyper-V and WSL.

Where to give feedback

We’re excited for you to try connecting USB devices to WSL. If you have feedback for this project, please open an issue on the open-source usbipd-win project. Learn more about WSL, including how to set up common development tools like Git, VS Code, Docker containers, databases, GPU acceleration for machine learning, and more, by visiting the WSL documentation. Finally, be on the lookout for future announcements from the C++ embedded development team about tooling to improve the embedded development experience regardless of device or compiler. Happy coding!

Comments

ghost commented Mar 12, 2017

Is it possible to run winfsp on WSL?

The text was updated successfully, but these errors were encountered:

billziss-gh commented Mar 12, 2017

That is a great idea and I may in fact look into it now that WinFsp 2017 is almost out the door!

Caveats

I know almost nothing about WSL. I have a very basic understanding that it allows unmodified Linux executables to run on Windows. This means that these FUSE executables are already linked with libfuse (or a variant) and expect to see a /dev/fuse device, which they use to interface with the kernel.

I do not know how to create a “device driver” for WSL. Is there any information available?

An alternative might be to make /dev/fuse into a named pipe and have a Win32 process listening on the other end that can interface with WinFsp. Even if this is possible, it would be suboptimal: a single file system request would now have to go to the pipe server process and then to the FUSE file system to be serviced.

Food for thought. Thanks!

billziss-gh commented Mar 12, 2017

An additional issue here is that /dev/fuse speaks the lowlevel FUSE protocol, which is not currently implemented in WinFsp. Luckily I have experience with it and believe it can be implemented on top of WinFsp.

ghost commented Mar 12, 2017

some notes about device drivers and linux integration:

Windows binaries can now be invoked directly from the WSL command line (Build 14951).

There is a way to develop device driver for WSL but its not documented. Sample driver: LxDrv

billziss-gh commented Mar 12, 2017

I could not run memfs-x64.exe on WSL. WSL does not support removable & network drives.

Interesting. It may be that Windows processes do not have access to the NTOS object namespace under WSL. [MEMFS uses the WinFsp DLL, which needs to interface with the WinFsp FSD (File System Driver) and it does so by opening a special “file”: \\?\GLOBALROOT\Device\WinFsp.Disk ; this is a device controlled by WinFsp.]

What is the exact message you are getting?

[I should probably just install WSL and quit asking obvious questions 🙂 ]

There is a way to develop device driver for WSL but its not documented. Sample driver: LxDrv

This is a very interesting pointer. Thank you!

ghost commented Mar 12, 2017

What is the exact message you are getting?

WSL mounts only the C:\ drive to /mnt/c . There are no errors, just do not allow me to access network, usb & winfsp drive.

billziss-gh commented Mar 12, 2017

WSL mounts only the C:\ drive to /mnt/c. There are no errors, just do not allow me to access network, usb & winfsp drive.

Makes sense, thanks.

billziss-gh commented Mar 12, 2017

There is a way to develop device driver for WSL but its not documented. Sample driver: LxDrv

Ok, I now had the chance to watch the preso and read some more about WSL.

I need a few days to think about it, sketch a potential architecture and scope it. On a first approximation this looks to me like a 3-6 month project (if I work on it full time) to bring it to the stability level that WinFsp currently has. Obviously this falls under “unpaid work”, but I am interested enough about it that I may just do it!

billziss-gh commented Mar 21, 2017 •

@ui4j I now had the chance to look into this some more.

I think I may have been over-enthusiastic in giving any time estimate on this. After seeing lxdrv that you pointed to me I erroneously assumed that there was sufficient information to write a driver for WSL and that such a driver would follow the familiar IRP-based model. Unfortunately I am finding that this is not the case.

My new estimate is: “no estimate”. It is impossible to gauge the amount of work needed, because the WSL internals are not actually documented. Furthermore WSL at this point is a moving target, even if someone reverse engineered the portions of WSL needed to get FUSE going, any development on this knowledge would be very fragile and likely break at the next WSL point release.

For all intents and purposes WSL is like a new and changing OS at this point; it just happens to run on Windows and just happens to have a Linux-compatible interface. I strongly recommend that we wait until it stabilizes and Microsoft releases more documentation on it.

However I compile here some random notes based on my research so far. Most of these notes are based on Alex Ionescu’s lxss project and some of my own WinDbg sleuthing.

WSL uses a VFS-compatible model for its drivers: https://github.com/ionescu007/lxss/blob/master/lxdrv/lxvfs.h#L120-L139. The familiar IRP model is not used.

A FUSE driver would have to register /dev/fuse . Lxdrv uses VfsInitializeStartupEntries to register /dev/lxdrv .

It is not clear how a new file system is to be mounted (although there are many interesting symbols in the lxcore.sys symbol list which I attach to the end). Presumably once a file system was mounted it would be getting calls in VFS_FILE_CALLBACKS , which it would then forward to the file system process connected to /dev/fuse . [NOTE: the WinFsp I/O queues can only queue IRP’s and cannot be reused without significant rework.]

Symlinks created by WSL (on DrvFs) are reparse points with tag 0xa000001d. The actual link is stored in the file. For a link baz -> foobaz the following is stored:

Apart from symlinks, other special files are not supported on DrvFs. It is unclear to me why this is so. It is also unclear why they did not use the existing NFS reparse points for symlinks and special files: https://msdn.microsoft.com/en-us/library/dn617178.aspx

I may update this list as I find out more about WSL.

I have a samba drive which is mounted on my local windows computer.

I have a /mnt/c drive in WLS (Windows 10 Bash), but no /mnt/z .

Is there a way to access it somehow? Can I remount it in WSL?

7 Answers 7

[Update — apparently this feature is available in build 16176. I haven’t tried it yet.]

No, though there may be some trick I haven’t discovered. Windows Subsystem for Linux does not mount network drives. A Microsoft employee says here (in a comment):

We only “mount” fixed drives at this time. USB/removable/network drives are not handled at this time. This capability is on our backlog, but it’s not on the cards anytime soon.

So don’t hold your breath.

I attempted to work around it by using a symbolic link, like this:

The link works just fine in “normal” Windows (cmd.exe, PowerShell, file explorer, etc.), but is invisible to WSL:

For my own use, this limitation is a show-stopper. I have things on network drives that I’m not willing to move. There are alternatives; I’m using Cygwin.

In order to mount a Windows drive using DrvFs, you can use the regular Linux mount command. For example, to mount a removable drive D: as /mnt/d directory, run the following commands:

Now, you will be able to access the files of your D: drive under /mnt/d. When you wish to unmount the drive, for example so you can safely remove it, run the following command:

When you wish to mount a network location, you can of course create a mapped network drive in Windows and mount that as indicated above. However, it’s also possible to mount them directly using a UNC path:

Note the single quotes around the UNC path; these are necessary to prevent the need to escape the backslashes. If you don’t surround the UNC path with single quotes, you need to escape the backslashes by doubling them (e.g. \\\\server\\share ).

WSL does not have any way to specify which credentials to use to connect to a network share. If you need to use different credentials to connect to the server, specify them in Windows by navigating to the share in File Explorer, using the Windows Credential Manager, or the net use command. The net use command can be invoked from inside WSL (using net.exe use) via interop. Type net.exe help use for more information on how to use this command.

WSL2 supports CIFS (SMB) protocol. You may need to specify your network server version when mounting. E.g. on Ubuntu 20.04:

I just ran across this issue recently where I have a Mac host running a vmware fusion with windows 10 installed as a guest OS. I installed WSL (ubuntu) in the windows 10. I am sharing a folder on my Mac (

/Public) with all my fusion guest O/S, and it works seemlessly with any linux/bsd guest OSes. On Windows 10, the network drive for the shared folder is \vmware-host\Shared Folder\Public\ and is accessible from the windows 10, and is also mounted on Z: drive as well.

The problem is when you are using bash in WSL. The suggested method is to (adjust actual drive letter and folder names as needed)

or, more directly

The mount command is successful, but in fact the mount “failed”. You can’t see the content of the folder /mnt/z. The mount works well with other network drives AS LONG AS the filesystem is a windows (NTFS, FAT32, etc) filesystem. Since the file system I’m trying to use is apple file system (apfs), the drvfs cannot use it. It will likewise fail if the underlying filesystem you are trying to mount is linux (ext2, ext3, . ) or network nfs/samba type. This drvfs will only understand windows native drvie format.

Its funny how you can use none-windows filesystem drives in windows, but in wsl/linux, you can only see windows filesystem drives.

So, the short answer is

as long as the network drive is using native windows filesystem (ntfs, fat*).

I’d like to mount a windows server from within WSL (Windows Subsystem for Linux). On Ubuntu (with unity interface) I can just type

and everything mounts just fine.

If I try this in WSL then I get the following error:

5 Answers 5

You can now choose to sort by Trending, which boosts votes that have happened recently, helping to surface more up-to-date answers.

Trending is based off of the highest score sort and falls back to it if no posts are trending.

Assuming the host Windows OS can access a file share at “\\servername\sharename”, try this command in bash. You will need to be root:

The single quotes are important!

Worked for me with a SharePoint Online UNC path. The permissions are screwy though. I can navigate through the folders and see the filenames, but I can’t read files. So need to figure out the permissions thing. Let me know if you get anywhere with that.

Actually if your windows share is already mapped to a drive in the Windows host, it can be even simpler. Let’s suppose you already mounted the share on Z: . In that case the following will work:

While you have an a mount created to the windows host through /mnt/c already created for you in WSL, if you want to mount a share from another machine, then you will need to create the mount point, e.g.

Then you will need to mount the remotely shared smb:// filesystem at that mount point using mount.cifs , e.g.

Optionally, you will want to include options following /mnt/somename such as

If it is an older WinXP share you are attempting to mount, then you will need to enable NTLMv1 authentication by including the sec=ntlm or sec=ntlm1 . See mount.cifs for further use of the sec= option.

In WSL (I’m using Ubuntu) it looks like that when you install the cifs-utils it doesn’t create the module file that cifs needs when mounting. Type: “modinfo cifs” and you will see. Anyway, the work-around is to map a drive letter in Windows and then mount to that, as mentioned above. Thanks gabuzo.

Maybe its that cifs-utils is looking in the wrong place for the module file. Or MS intentionally disabled it. They don’t want WSL to be too useful.

Mounting an SMB server share should be straightforward, I tested this on Windows build 1909 and WSL 2.0 Ubuntu 20.04.1 LTS (GNU/Linux 4.19.128-microsoft-standard x86_64). You use mount just as usual:

Nothing too hard, the source path of the mount is the regular UNC pathname. The important bits are the file system type (“drive filesystem”?) and the fact that you need to enclose the server path in single quotes (on the command line). As usual, your mount folder must also exist.

On this WSL issue I found good options (-o) that seem to work very well with creating, reading and writing files without sudo as well as reading correct modification/creation dates:

Because I like to have this server mounted always, I put the mount instruction into /etc/fstab to have it auto-mounted by WSL:

(you can reload fstab with sudo mount -a )

Note that I have logged into the server on Windows itself and made it remember the user and password. @David C. Rankin’s answer has some info on how to specify username and password if you need to do it separately.

I’m trying to install nvm using curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash on WSL2, but I’m getting different errors. Initially, the curl command would return the following:

After running netsh int ip reset in Windows, which was suggested in another question, the same command started timing instead:

I’ve also tried manually saving the install.sh to my machine and running it locally (after setting its permissions with chmod +x install.sh ), but that returns a similar error:

I can successfully ping github.com. ping -c 100 github.com returns the following:

This issue suggests that a Windows update resolved the issue, but that’s not an option for me since it’s a work machine and I can’t update beyond build 18363.2039. I’ve also checked that my VPN is not enabled and I set my DNS to 8.8.8.8 and 8.8.4.4 , which had no effect.

1 Answer 1

I have a feeling you are probably correct about this being the same issue mentioned on Github that was resolved in a Windows update.

If that’s truly the case, you are probably going to continue to run into issues even after getting nvm installed. For instance, nvm probably will have trouble downloading Node releases.

The easiest solution that I can propose, if it works for you, is to simply convert to WSL1 instead of WSL2. WSL1 will handle most (but not all) Node use-cases just as well as WSL2. And WSL1 handles networking very differently than WSL2. If the Windows networking stack is working fine for you, then WSL1’s should as well.

As noted in that Github issue, this seemed to be a problem that occurred only in Hyper-V instances. WSL2 runs in Hyper-V, but WSL1 does not.

If you go this route, you can either:

create a copy of your existing WSL2 distribution and convert that copy to WSL1. From PowerShell:

Note that you’ll be root, by default. To change the default user, follow this answer.

Or, just convert the WSL2 instance to WSL1:

If WSL1 doesn’t work for you (at least in the short term until your company pushes that update), then there may be another option similar to the one mentioned in this comment on that Github issue. Let me know if you need to go that route, and I’ll see if I can simply that a bit.

Lawrence Abrams
  • September 10, 2020
  • 02:12 PM
  • 4

Windows 10 now allows you to mount physical disks formatted using the Linux ext4 filesystem in the Windows Subsystem for Linux 2.

Linux filesystems, such as ext4, cannot be natively accessed in Windows 10 without installing special drivers.

Starting with Windows 10 preview build 20211, WSL 2 now includes a wsl –mount command that lets you mount ext4 and other Linux kernel supported filesystems, directly in installed WSL distributions.

This feature is especially useful for users who dual-boot Windows 10 and Linux and would like to access their Linux drives while using Windows.

How to mount a disk in WSL 2

Once Windows 10 preview build 20211 is installed, you can use the wsl –mount command to mount a disk in WSL 2.

To mount a drive, you should first open a PowerShell command prompt with Administrative privileges and run the following command to get a list of available drives.

If a disk has a single partition, you can mount it using the command:

Otherwise, if you wish to mount a particular partition, you would use the commands:

Finally, to unmount a disk from WSL 2, you would use the following commands:

By default, wsl –mount will attempt to mount the partition using ext4. To specify a different filesystem, you can use the following command:

When mounted, the disk will be accessible in a Linux distribution under /wsl/[mountpoint].

More detailed instructions on how to use the wsl –mount command can be found here.

To illustrate how these commands work, you can see the image below from Microsoft.

To access a mounted filesystem in Windows 10’s File Explorer, you can open the Linux category and navigate to /mnt.

It should be noted that when you mount a disk in WSL 2, it will be available for all WSL 2 Linux distributions that you have installed.

Furthermore, when mounting a partition, the whole disk is mounted and thus will become inaccessible to other applications that may normally use it.

“Also please note that this feature comes with the limitation that only physical disks can be attached to WSL 2. At this time, it’s not possible to attach a single partition,” Microsoft notes.

As an administrator or manager, you may require all developers to use the same approved software. This consistency helps to create a well-defined work environment. The Windows Subsystem for Linux aids in this consistency by allowing you to import and export custom WSL images from one machine to the next. Read the guide below to learn more about:

Creating a custom WSL image

What is commonly referred to as an “image”, is simply a snapshot of your software and its components saved to a file. In the case of the Windows Subsystem for Linux, your image would consist of the subsystem, its distributions, and whatever software and packages are installed on the distribution.

To begin creating your WSL image, first install the Windows Subsystem for Linux.

Once installed, use The Microsoft Store for Business to download and install the Linux distribution that’s right for you. Create an account with the Microsoft Store for Business.

Exporting your WSL image

Export your custom WSL image by running wsl –export , which will wrap your image in a tar file and make it ready for distribution on to other machines.

Distributing your WSL image

Distribute the WSL image from a share or storage device by running wsl –import , which will import the specified tar file as a new distribution.

Update and patch Linux distributions and packages

Using Linux configuration manager tools is strongly recommended for monitoring and managing Linux user space. There are a host of Linux configuration managers to choose from. Check out this blog post on how to install Puppet in WSL 2.

Enterprise security and control options

Currently, WSL offers limited control mechanisms in regard to modifying the user experience in an Enterprise scenario. Enterprise features continue in development however, below are the areas of supported and unsupported features. To request a new feature not covered in this list, file an issue in our GitHub repo.

Supported

  • Sharing an approved image internally using wsl –import and wsl –export
  • Creating your own WSL distro for your Enterprise using the WSL Distro Launcher repo

Here’s a list of features for which we don’t yet have support for, but are investigating.

Currently unsupported

Below is a list of commonly asked features that are currently unsupported within WSL. These requests are on our backlog and we are investigating ways to add them.

  • Synchronizing the user inside WSL with the Windows user on the host machine
  • Managing updates and patching of the Linux distributions and packages using Windows tools
  • Having Windows update also update WSL distro contents
  • Controlling which distributions users in your Enterprise can access
  • Running mandatory services (logging or monitoring) inside of WSL
  • Monitoring Linux instances using Windows configuration manager tools such as SCCM or Intune
  • McAfee support

Browse Post Topics

Introduction

Windows subsystem for Linux allows you to run Linux shell commands from your Window PC.

This guide offers 3 methods to enable Windows subsystem for Linux in Windows 10. It also demos how to download and install your preferred Linux Distribution from Windows Store.

There are 2 high-level steps to be able to run Linux commands in Windows 10:

  1. Enable Windows Subsystem for Linux Windows Optional Features
  2. Download and install a Linux distribution from Windows store

Options to Enable Windows Subsystem for Linux in Windows 10

The 3 methods discussed in this guide to enable Windows Subsystem for Linux in Windows 10 are:

  1. From Control Panel
  2. Install with DISM
  3. Enable Windows Subsystem for Linux with PowerShell

Enable Windows Subsystem for Linux in Windows 10 from Control Panel

Here is the first method to enable Windows Subsystem for Linux in Windows 10:

  • Type control panel in Windows 10 search bar. Then click it from the search results.
  • When Control Panel opens confirm that View by is set to Category. If not click the drop-down and select Category.
  • At Programsand Features, click Turn Windows features on or off. A new pop up window will open. If the Windows Features pop window is too small, you can expand it (see the second image below).
  • Then, at the Windows Features pop up screen, locate Windows Subsystem for Linux and click the check box beside it. To enable the feature, click OK
  • Windows will begin enabling the feature…
  • When it is completed, click Restart now.

Enable Windows Subsystem for Linux in Windows 10 with Command Line

Another option is to use DISM command line to enable this feature.

Here are the detailed steps:

  • Type cmd in search bar. Then beneath Command Prompt, click Run as Administrator.
  • To display the feature name for the Windows Optional feature you wish to enable, type the command below. Then press enter.

Here is the result of the command in command prompt..

  • To enable the feature, type this command and press enter.

DISM will start enabling the feature…Wait for it the reach 100% and report success…

  • The feature installation requires a restart. To restart your PC, at the prompt, type Y.
  • Your PC will restart and start installing Windows Subsystem for Linux.

Enable Windows Subsystem for Linux in Windows 10 with PowerShell

The final option to enable the Linux Subsystem is via PowerShell.

Here are the steps…

  • Type powershell in search bar. Then beneath Windows PowerShell, click Run as Administrator.
  • To display the name for the Linux subsystem, type the command below. Then press enter.

Here is the result of the command in PowerShell with the feature status showing as “Disabled”.

  • To enable the feature, type this command and press enter.
  • The feature installation will start…
  • When the feature installation is completed, you will be prompted to restart your PC. At the restart prompt, type Y. Then press enter.

Download and Install a Linux Distribution from Windows store

Now that you have enabled Windows Subsystem for Linux, the final step to enable Linux shell in Windows 10 is to download your preferred Linux distro from Windows store.

Here are the detailed steps:

  • Open Microsoft Store page for your favorite Linux distribution. To open the Microsoft store page for a distribution, click the link below (all links open in a new browser tab):
  1. Ubuntu 16.04 LTS
  2. Ubuntu 18.04 LTS
  3. OpenSUSE Leap 15
  4. OpenSUSE Leap 42
  5. SUSE Linux Enterprise Server 12
  6. SUSE Linux Enterprise Server 15
  7. Kali Linux
  8. Debian GNU/Linux
  9. Fedora Remix for WSL
  10. Pengwin
  11. Pengwin Enterprise
  12. Alpine WSL
  • For this demo I will download Ubuntu 18.04 LTS. When the link opens, click Get.
  • Then if prompted, click Open Microsoft Store.
  • When the App opens in Microsoft Store, click Get.
  • If you are not signed to a Microsoft account you will be prompted to sign in. This is optional. To use the app on the device alone, click No, thanks.
  • The Linux distribution will start downloading…
  • When the download is completed, click Launch. Linux installation will start. (See the second image).
  • When prompted, type a username. Then press enter.
  • At the password prompt, type a password for the previous user and press enter. Then retype the password and press enter again. Your installation is ready to go!

Conclusion

To run Linux commands in Windows 10 you need to complete 2 tasks:

  • Enable Windows Subsystem for Linux Windows Optional Feature
  • Download and install your preferred Linux distro from Windows store.

If you have completed these two steps you should be able to enjoy Linux right from your Windows 10 PC.

For questions, feedback or comment use the “Leave a Reply” form found at the end of this page.

For more Windows guides visit our Windows How To page.