11

I have no problems mounting a network drive W: with the following command:

sudo mount -t drvfs W: /mnt/htdocs

In /proc/mounts the corresponding line then is:

W: /mnt/htdocs drvfs rw,relatime 0 0

But if I add this line to /etc/fstab and restart, I would expect the system to auto-mount the drives, which doesn't happen.

Any ideas?

6 Answers 6

9
+50

WSL does process fstab, but only as of build 17093. Assuming you're using an earlier version, you'll probably need to write a script to do the mount and invoke it manually.

3

I ran into the same problem.

What I did to fix it was, go to the /etc/bash.bashrc and add the below script at the top:

sudo rm -r /mnt/d
sudo mkdir /mnt/d
sudo mount -t drvfs D: /mnt/d

Please note that D is my network drive.

2

I ran into the same problem.

I am running Windows 10 Enterprise Version 1709, OS Build 16299.431

What I did is I added to the top of /etc/bash.bashrc the following line:

sudo mount -t drvfs '\\127.0.0.1\MyDrive' /mnt/MyDrive

I am not saying this is the best way to go about it, but I was sure tired of having to mount the drive every time I started WSL bash.

2

WSL does load /etc/fstab at startup, please follow steps below.

  1. Install cifs utils
sudo apt-get install cifs-utils
  1. Make sure the below file exists
ls -l /sbin/mount.cifs
  1. Add entry to /etc/fstab, assuming /mnt/files exists, set file/directory permissions to rwx
//host/files /mnt/files cifs username=xyz,password=xyz,file_mode=0777,dir_mode=0777 0 0
1
  • 1
    Thank you! I used cifs-utils to setup a SMB connection on Linux. Now with this instructions I've configured my SMB drive. If one doesn't want to publish credentials into /etc/fstab, its possible to use a similar configuration: credentials=/home/your_user/.my_smb_drive_credentials That file should contain the same properties as the fstab config: username=<your_user> (newline) password=<passwd> keeping the file into your home will keep credentials away from other users. Cheers
    – funder7
    Feb 14, 2023 at 22:34
1

Windows build 17093 is supposed to fix the fstab problem, but at the moment it is only an Insider Build, so not advised for stability.

You can effectively accomplish this by writing a .bash_login script in your home directory like this:

if [ ! -e full_file_name ]
then sudo mount --bind ...
fi

Just replace the mount command by whatever mount commands you want, and full_file_name with a file-name that will reliably exist if your mounts are in place.

The first Linux window might require you to type your Linux password, but later windows will not.

0

I suspect that WSL ignores /etc/fstab. You have access to other Windows files because WSL automatically mounts all open Windows partitions. Note that there is no /dev/sda when Ubuntu runs under WSL.

2
  • The wslconfig documentation says /etc/fstab is processed by default.
    – Bob
    Feb 15, 2018 at 16:02
  • 2
    it also says "Available in Windows Insider Build 17093 and later"
    – sickelap
    May 5, 2018 at 9:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .