Configuring WSL 2: Mounting drive fs mountpoint for ordinary users
Windows Subsystem for Linux version 2 (WSL 2) is a significant improvement over its predecessor, providing better performance, compatibility, and flexibility. One of the key features of WSL 2 is the ability to mount a Windows drive as a filesystem mountpoint, making it accessible to Linux applications. In this article, we will discuss how to configure WSL 2 to allow ordinary (non-root) users to mount a drive fs mountpoint.
Prerequisites
Before we begin, make sure you have the following prerequisites:
- A Windows 10 machine with WSL 2 installed.
- A Linux distribution installed on WSL 2.
- A Windows drive that you want to mount as a filesystem mountpoint.
Mounting a Windows Drive in WSL 2
To mount a Windows drive in WSL 2, you need to edit the /etc/fstab file and add an entry for the drive. The entry should include the following information:
- The Windows drive letter (e.g.,
F:). - The Linux mount point (e.g.,
/mnt/fdrvfs). - The filesystem type (e.g.,
drvfs). - The mount options (e.g.,
rw,noatime,dirsync,noauto,exec,umask=22,fmask=11).
Here's an example entry:
F: /mnt/fdrvfs drvfs rw,noatime,dirsync,noauto,exec,umask=22,fmask=11 0 0
Once you've added the entry, save the file and exit the editor. Then, run the following command to mount the drive:
sudo mount -a
The drive should now be mounted at the specified mount point.
Allowing Ordinary Users to Mount the Drive
By default, only the root user can mount drives in Linux. However, you can configure WSL 2 to allow ordinary users to mount the drive by adding their usernames to the /etc/wsl.conf file. Here's an example entry:
[automount]
users = root, , , ...
Replace username1, username2, etc., with the actual usernames of the users you want to allow to mount the drive. Once you've added the entry, save the file and exit the editor. Then, restart the WSL 2 distribution for the changes to take effect.
Verifying the Configuration
To verify that the configuration is working correctly, log in as an ordinary user and try to mount the drive. You should be able to mount the drive without using sudo.
- WSL 2 allows you to mount a Windows drive as a filesystem mountpoint, making it accessible to Linux applications.
- To allow ordinary users to mount the drive, add their usernames to the
/etc/wsl.conffile and restart the WSL 2 distribution. - Verify the configuration by logging in as an ordinary user and trying to mount the drive without using sudo.