WSL and Windows Filesystem

Logos of the Windows and Linux spread on a table

When running Windows Subsystem for Linux version 1 (WSL/WSL1) on Windows, you will be greeted by a default drive mount for your primary operating system drive. More specifically, you will find that your primary drive (usually C:) will be mounted to /mnt/c in your WSL shell.

This is great and super convenient; the only problem is that Windows does not understand Linux permissions, so all of the files and folders will appear to have full permissions (777, -rwxrwxrwx). You can attempt to set these permissions all you like, they simply will not take effect since Windows doesn’t understand these granular file/directory access controls.

To get around this, we need to mount the drive (/mnt/c) including the metadata mounting option. To do this, we need to edit the /etc/wsl.conf file. This likely does not exist by default, so you’ll need to create it.

Mounting with Metadata

Before doing that, though, you can test remounting the drive with metadata using the following commands:

# Unmount /mnt/c and remount it using drvfs and enable the metadata option
sudo umount /mnt/c && sudo mount -t drvfs C: /mnt/c -o metadata

This command will first unmount /mnt/c and if that’s successful, it will remount /mnt/c using the drvfs driver and the mount option metadata.

You should now find that any changes to permissions in /mnt/c will be persisted! Now we just need to make this permanent. To do that, we need to update the WSL configuration.

Making it Stick

There are several options for configuring the drive mount. You can find details in the documentation, but for quick reference, these are the settings I use in my /etc/wsl.conf file.

enabled = true
options = "metadata,umask=22,fmask=11"

These settings enable the automatic mounting of the /mnt/c drive, and enables the metadata, umask, and fmask mounting options. The umask and fmask parameters set the octal mask to exclude default permissions. In this case, all regular directories will have 755 or rwxr-xr-x permissions and all regular files will have 644 or rw-r--r-- permissions. You can still change the permissions however you see fit; this just masks off the default 777 or rwxrwxrwx permissions for the Windows drive to be more sensible defaults.

Once you’ve created or updated the /etc/wsl.conf file, you will need to restart WSL. You can do that using the wsl.exe -t command to terminate the WSL instance. You can find the running instances with wsl.exe -l -v.

c:\> wsl.exe -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Running         1
c:\> wsl.exe -t Ubuntu-20.04
c:\> wsl.exe -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Stopped         1
c:\> wsl.exe
wsl@host $ # Hey we're back in our WSL shell!