Windows:- WSL – Accessing Network Shares

Background

Let us go over how to access Microsoft Network Shares from within WSL ( Microsoft’s Windows Subsystem for Linux ).

Glossary

What is /mnt?

Control-Escape.Com

I like the definition availed via Control-Escape.Com.

And, so let us use that definition.

Guide to Linux for Beginners – ADDING FILE SYSTEMS TO THE TREE
Link

To gain access to files on another device, you must first tell Linux where in the directory tree you would like those files to appear.

This process is called mounting a file system. For example, you will frequently need to access files from CD-ROM.

In order to do this, you must tell Linux, “Take the file system from this CD-ROM and make it appear under the directory /mnt.”

The directory given to Linux is called the mount point. In this case it is /mnt.

The /mnt directory exists on all Linux systems, and it is intended specifically for use as a mount point for temporary media like floppy disks or CDROMs. It may be empty, or it may contain subdirectories for mounting individual devices.

Linux does not require you to use /mnt as the mount point for other file systems.

You may mount file systems anywhere in the directory tree.

However, it is good practice to create empty directories that are reserved as mount points.

 

Outline

  1. Mount Point
    • List Mount Points Targets
    • Reserve Mount Point Target
    • Attach Mount Point Source
    • Access Mount Point
      • List Mount Point Contents
    • Review Mount Points
      • Mount -l ( command )
      • findmnt command
    •  Detach Mount Point Source
    • Release Mount Point Target

Mount Point

List Mount Points Targets

Outline

Assuming we have a standard of availing our file systems under /mnt, let us go with it.

ls command

Syntax


ls -la /mnt

Sample


ls -la /mnt

 

Reserve Mount Point Target

Outline

Create our mount point target.

We will be creating a new folder under /mnt.

We can give the folder any name.

In our case, we will be pointing the folder to a remote network share.

For ease of distinguishing various mount points,  we will call the one we are creating backupDB.

mkdir command

Syntax


mkdir /mnt/<folder>

Sample


mkdir /mnt/backupDB

 

Attach Mount Point Source

Outline

Using the mount command, we will mount our network share (  \genesis\fs\database\backup\sqlServer ) to our empty local folder ( /mnt/backupDB ).

Though not required, we will inform the mount utility that our source folder’s type is drvfs.

mount command

Syntax


sudo mount -t drvfs <remote-network-share> /mnt/<local-folder>

Sample


sudo mount -t drvfs '\\genesis\fs\database\backup\sqlServer' /mnt/backupDB

Access Mount Point

Outline

Let us access our mount point.

List Mount Point Contents

ls command

Syntax

ls <folder>

Sample

ls /mnt/backupDB

 

Review Mount Point

Outline

Let us review our mount points.

Mount Command

Syntax

mount -l

Sample ( Basic )

mount -l

Output
Output – Image


Explanation

We can use the “mount -l” command to review mounts.

In the screen shot above, the two bottom entries are Microsoft Windows Mounts.

Entries

  1. Entry – 01
    • /mnt/c
      • Drive C
      • on /mnt/c
      • Type:- 9p
      • Path:- C:\
  2. Entry – 02
    • /mnt/backup
      • Drive C
      • Type:- 9p
      • Path:- UNC\

 

Sample – Filtered On  – Type is drvfs

mount -l --type drvfs

Output
Output – Image


Explanation

Requesting a filter on type drvfs returns an empty list.

 

Sample – Filtered On  – Type is 9p

mount -l --type 9p

Output
Output – Image


Explanation

Requesting a filter on type 9p returns our MS Windows mounts

 

 

findmnt Command

Syntax

findmnt

Sample ( Basic )

findmnt

Output
Output – Image


Explanation

We can use the “findmnt” command to review mounts.

In the screen shot above, the two bottom entries are Microsoft Windows Mounts.

Above those last two entries, we have WSL’s own mount points.

 

Sample – Filtered On  – Type is 9p

findmnt --type 9p

Output
Output – Image


Explanation

Requesting a filter on type 9p returned our WSL list.

 

Detach Mount Point

Outline

Let us detach our mount point.

umount command

Syntax


sudo umount /mnt/<target>

Sample


sudo umount /mnt/backupDB

Release Mount Point Target

Outline

Release mount point.

rmdir command

Syntax


rmdir /mnt/<local-folder>;

Sample


rmdir /mnt/backupDB

Dedication

Dedicating this post to Microsoft’s WSL Team.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s