11

I'm trying to mount a windows share (SMB/CIFS) using a Debian 10 linux distribution running on Windows 10's Subsystem for Linux using fstab to automount on startup. My software specs are

OS: Windows 10 Pro 21H2
OS Build: 19044.1526
    
Windows Subsystem for Linux 2 (WSL2)
Distribution: Debian 10.11

According to the following article by Microsoft, you can create a text file at /etc/wsl.conf to store user configuration settings for WSL2.

https://docs.microsoft.com/en-us/windows/wsl/wsl-config

I started using wsl.conf to set the mountFsTab key to true. That should ensure that WSL processes the fstab file. I know the setting should not matter because it defaults to true, but I wanted to make sure it was set to true. My wsl.conf file currently looks like:

# Automatically mount Windows drive when the distribution is launched. 
[automount]
# Automatically mount the fixed drives (C:) under /mnt.
enabled = false
# Sets the `/etc/fstab` file to be processed when a WSL distribution is launched.
mountFsTab = true
        
# Network host settings that enable the DNS server used by WSL 2. This example changes the hostname, sets generateHosts to false, preventing WSL from the default behavior of auto-generating /etc/hosts, and sets generateResolvConf to false, preventing WSL from auto-generating /etc/resolv.conf, so that you can create your own (ie. nameserver 1.1.1.1).
[network] 
hostname = JTI-ITL05-DEBIAN

The hostname does change successfully. However, even when the mountFsTab key is set to true, the fstab file’s mounts are not being applied when the Debian WSL2 instance starts. To test the fstab file, I first tried running the following command.

Sudo mount -a

The command successfully mounts the two entries I have in /etc/fstab. Here is an example of my fstab entries to illustrate the structure using the DrvFs file system plugin Microsoft created for WSL.

#file system                    dir            type    options                         dump    pass
\\\\domain.com\\share\\path     /mnt/mountdir  drvfs   defaults,uid=1000,gid=1000      0       0
C:                              /mnt/c         drvfs   defaults,uid=1000,gid=1000      0       0

To test the processing of fstab, I included a line to mount a local device, drive C in Windows. The line that mounts a local device, mounts successfully when the WSL2 instance starts up. The other line pointing to a Windows network share does not mount on startup, but I can mount it after the instance boots to a terminal CLI. I can confirm the results using the wsl command to shutdown the instance and start it back up. The fstab file is being processed on start up.

I don’t see a relevant log file in /var/log to check for errors. All of my tests have failed so far to get the fstab file to mount a Windows network share when WSL2 Debian starts up.

How do I get the WSL2 instance to automatically mount a Windows network share found in the fstab file?

1
  • 2
    I'm not able to reproduce this on my systems at this point. I was thinking maybe /etc/fstab was getting processed before init installed 9p and virtio into the instance. But on both my Windows 10 and Windows 11 systems, the share mounted when WSL started, both from a wsl --terminate <distro> and even a wsl --shutdown. It could still be a timing issue on your system. Check dmesg to see if there are any hints there. Commented Mar 16, 2022 at 17:27

2 Answers 2

6

It turns out I did set everything up correctly. To answer the original question, follow the procedure below to configure Windows Subsystem for Linux 2 (WSL2) to use fstab to automatically mount a Windows Network File Share.

  1. Open WSL2 in a terminal.
  2. Create a directory to mount the file share. /mnt/mountdir
  3. Create a file called "fstab". /etc/fstab
  4. Add the following line to the "fstab" file.
\\\\domain.com\\share\\path    /mnt/mountdir    drvfs defaults,uid=1000,gid=1000    0    0

Fill in the share path with a windows share on your network.

I setup a new laptop running Windows 10, followed the procedure above, and confirmed that the Windows share is mounted when the WSL2 instance starts. I'm not sure what the original issue was. It seems to be related to Windows 10 OS corruption. I'll update my answer if I can find the original cause of the issue.

0

You need to tell fstab to mount automatically at boot.

Change

\\\\domain.com\\shares\\sharename   /mnt/mntdir drvfs       uid=1000,gid=1000   0       0

To

\\\\domain.com\\shares\\sharename   /mnt/mntdir drvfs       defaults,uid=1000,gid=1000   0       0

While auto would be enough, defaults would contain the following options:

 defaults
          Use default options: rw, suid, dev, exec, auto, nouser, and async.

2
  • I tried adding either "defaults" or "auto" to the list of comma-separated options. I made sure to shutdown and stop the WSL2 instance to test fstab. Unfortunately, neither changes made any difference for me. The "fstab" file was still not processed on startup, but I can use mount command to mount the fstab entries. I'll add the "defaults" option to my post to illustrate that I tried that out. Commented Mar 15, 2022 at 23:21
  • What are the permissions for your wsl.conf and fstab files set to? I can't get fstab to execute with settings similar to what you have above.
    – aagha
    Commented Aug 25, 2022 at 1:10

You must log in to answer this question.

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