Mike Slinn

Mounting Shared Directories on WSL & Ubuntu

Published 2025-01-19.
Time to read: 3 minutes.

This page is part of the posts collection, categorized under Linux, Ubuntu, WSL.

Most aspects of running Ubuntu natively (directly on a physical motherboard) are identical when running under Microsoft Windows Subsystem for Linux (WSL). The details of how shared directories are mounted differ between Ubuntu on WSL and native Ubuntu. The tiny difference is essential to get right.

The SMB Family Tree

The filesystem type used for the mount command depends on the filesystem being mounted. Shared directories require a filesystem type that is specially for the type of sharing in play.

The SMB file sharing protocol was invented by IBM in the mid-eighties. It has gone through several major evolutions through the years.

CIFS is an old, obsolete dialect of SMB. CIFS stands for “Common Internet File System.” This flavor of SMB was created by Microsoft in 1996, but they stopped work on CIFS in 2006 when Microsoft moved to SMB 2.

Linux still supports CIFS. This is becoming a problem, so I expect Linux will have to bring its SMB support up-to-date soon.

Microsoft moved from SMB 2 to SMB 3 in 2012. SMB 2 and SMB 3 are much superior to CIFS. Windows 10 included support for SMB 3.1.1.

Samba is a well-known filesystem sharing technology for Linux. It consists of several applications that allow a Linux server to act like a Windows domain controller. Samba can also perform network actions such as serving files, authentication, authorization, name resolution and print services.

Installing SMB Support on WSL

To install the capability of mounting shared SMB drives from WSL, type:

Shell
mslinn@bear ~ yes | sudo apt install cifs-utils winbind

Mount

The Linux mount command is a way of combining file systems. Local and remote file systems can be mounted.

Remote file systems can be mounted two ways:

  1. At the command line, by using the mount command with root privilege.
  2. At boot time, by making an entry in /etc/fstab.

Mount Syntaxes

The syntaxes for both ways of specifying a Linux mount are very similar. In this article, I focus on the subset of the mount command as it pertains to mounting shared drives over an SMB network. The mount command can also mount file systems on attached (local) devices, and it can be used to mount other types of shared directories, for example, NFS.

Generic command-line syntax
$ sudo mount -t FS_TYPE -o OPTIONS //SERVER/SHARE_PATH /MOUNT_POINT

See also man mount.

Generic /etc/fstab entry syntax
//SERVER/SHARE_PATH /MOUNT_POINT FS_TYPE OPTIONS

See also man fstab.

Where:

FS_TYPE
Might be cifs or drvfs.

WSL requires the drvfs filesystem type to be specified on the mount command. Native Ubuntu uses cifs filesystem type for the same purpose. If you mistakenly use the cifs filesystem type when mounting a remote shared drive onto a WSL filesystem, the entire mounted filesystem will be owned by root, and the permissions will be immutable. Other problems will also manifest until you specify drvfs.
SERVER
Might be an IP address or a DNS name.
SHARE_PATH
The directory shared by SERVER.
MOUNT_POINT
An empty local directory that is dedicated to hosting the content provided by SERVER at SHARE_PATH.
OPTIONS
Specifies credentials, permissions, and read/write control.

Common Options

An OPTIONS string might look like:

/home/mslinn/gojira_credentials
credentials=/home/mslinn/gojira_credentials,defaults,gid=1000,uid=1000

Where:

credentials
Specifies a file that stores user ID, password and workgroup.
defaults
Specifies default options: async, auto, dev, exec, nouser, relatime, rw, and suid.
gid
Set the group ID of the mounted files; the default value is 0 (root). User mslinn has gid 1000.
uid
Set the user ID of the mounted files; the default value is 0 (root). User mslinn has uid 1000.

The default options are:

async
All I/O to the filesystem should be done asynchronously.
auto
(For fstab) Specifies that this mount will occur when mount -a is executed.
dev
Interpret character or block special devices on the filesystem.
exec
Permit execution of binaries stored in the mounted directory.
nouser
Require root privilege to mount the filesystem. This is the default.
relatime
Informs applications if a file has been read since it was last modified.
rw
Mount the filesystem read-write.
suid
Allow set-user-identifier or set-group-identifier bits to take effect.

Credentials

A credentials file is better than exposing passwords in commands.

/home/mslinn/gojira_credentials
username=mslinn
password=secret
domain=workgroup

Examples

These examples assume that the mount point /mnt/gojira_mslinn exists.

Creating the mount point
\mslinn@bear ~ sudo mkdir /mnt/gojira_mslinn

Command-Line Mount

Command-line mount
mslinn@bear ~ sudo mount -t drvfs \
  -o credentials=/home/mslinn/gojira_credentials,defaults,gid=1000,uid=1000 \
  //gojira/mslinn /mnt/gojira_mslinn
mslinn@bear ~ ls -l /mnt/gojira_mslinn/bare_repo total 12 -rwxrwxrwx 1 root root 23 Jan 19 08:08 HEAD* -rwxrwxrwx 1 root root 126 Jan 19 08:08 config* -rwxrwxrwx 1 root root 73 Jan 19 08:08 description* drwxrwxrwx 1 root root 512 Jan 19 08:08 hooks/ drwxrwxrwx 1 root root 512 Jan 19 08:08 info/ drwxrwxrwx 1 root root 512 Jan 19 08:08 objects/ drwxrwxrwx 1 root root 512 Jan 19 08:08 refs/

/etc/fstab Entry

The following mounts the same shared directory with the same options at boot time. Unlike the command line version, fstab entries may not be wrapped to several lines. Edit /etc/fstab and add something similar to the following:

/etc/fstab fragment
//gojira/mslinn /mnt/gojira_mslinn drvfs credentials=/home/mslinn/gojira_credentials,defaults,gid=1000,uid=1000

After modifying /etc/fstab, reload it:

Shell
$ sudo systemctl daemon-reload

Now mount the shared directory without having to reboot:

Shell
$ sudo mount /mnt/gojira_mslinn

Unmount

You can unmount the drive the same way, no matter how it was mounted:

Shell
$ sudo umount /gojira_mslinn
* indicates a required field.

Please select the following to receive Mike Slinn’s newsletter:

You can unsubscribe at any time by clicking the link in the footer of emails.

Mike Slinn uses Mailchimp as his marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp’s privacy practices.