Mount Windows Folders in WSL Automatically on Startup
In this article
Yes—you can have Windows directories automatically mounted in WSL each time the distribution starts by adding the appropriate entries to /etc/fstab or by creating a small launch script that runs at login.
What You'll Need
- Windows 10 version 1903 or later (or Windows 11) with the Windows Subsystem for Linux feature enabled.
- A Linux distribution installed from the Microsoft Store (Ubuntu, Debian, Kali, etc.).
- Administrative privileges on the Windows host (required to edit
/etc/fstaband to set up a startup task). - Basic familiarity with the Bash shell and a text editor such as
nanoorvim.
Step‑by‑Step
-
Confirm that the drive you want to mount is accessible from WSL. Open your WSL terminal and run
ls /mnt. You should see entries likec,d, etc. If the drive you need is not listed, make sure the drive is mounted in Windows and that the WSL integration option is enabled in Settings > Privacy & Security > For developers > WSL (labels may differ slightly by version). -
Create a mount point inside the Linux file system. Choose a location under
/mntor any other directory you prefer. For example, to mountC:\Projectsas/mnt/projects, run:
Thesudo mkdir -p /mnt/projects-pflag ensures the directory is created if it does not already exist. -
Test a manual mount command. Use the
mountutility with thedrvfsfile‑system type:
After the command finishes,sudo mount -t drvfs C:\Projects /mnt/projectsls /mnt/projectsshould list the Windows folder contents. If you receive a permission error, add themetadataoruid=1000,gid=1000options as needed (replace1000with your Linux UID/GID). -
Make the mount persistent with
/etc/fstab. Open the file with a text editor:
Add a line that follows the pattern:sudo nano /etc/fstab
You can also add optional flags such asC:\Projects /mnt/projects drvfs defaults 0 0metadata(to enable Linux permissions) oruid=1000,gid=1000(to force ownership). Example with metadata:
Save the file (Ctrl+O, Enter, Ctrl+X inC:\Projects /mnt/projects drvfs defaults,metadata 0 0nano). -
Verify the
fstabentry works without reboot. Run:
If no error appears, the entry is syntactically correct. Check the mount point again withsudo mount -als /mnt/projects. -
Configure WSL to run the mount at every launch. By default, WSL reads
/etc/fstabon each start, but some users disable this behaviour via the.wslconfigfile. Ensure you do not haveenabled = falseunder the[automount]section. If the file exists, edit it:
and either remove thenotepad $env:USERPROFILE\.wslconfigenabledline or set it totrue. -
Optional: Use a launch script for more complex scenarios. If you need to mount multiple folders with different options, create a script, for example
~/mount-windows.sh:
Make it executable:#!/bin/bashMount several Windows directories at WSL startup
sudo mount -t drvfs C:\Projects /mnt/projects -o metadata sudo mount -t drvfs D:\Data /mnt/data -o uid=1000,gid=1000
Then add it to your WSL profile (chmod +x ~/mount-windows.sh~/.bashrcor~/.profile) with the line:
This ensures the script runs each time a new interactive shell starts.~/mount-windows.sh -
Restart WSL to confirm everything works. In a Windows PowerShell window, execute:
Then reopen your Linux distro. The mount point should be present immediately without manual intervention.wsl --shutdown
Common Mistakes
- Using backslashes inside
/etc/fstabwithout escaping them. Windows paths must be written exactly asC:\Folder, notC:/Folder. - Omitting the
drvfsfile‑system type; the default type will beext4and the mount will fail. - Adding the mount line to
/etc/fstabbut havingautomount.enabled = falsein.wslconfig, which prevents WSL from processing the file. - Running the mount command without
sudo, which yields a “permission denied” error for non‑root users. - Setting the mount point inside a directory that already contains files; the mount will hide existing files and can cause confusion.
Tips
- Use the
metadataoption if you need Linux‑style permission bits on Windows files. This makeschmodandchownbehave as expected. - When mounting a drive that contains spaces (e.g.,
C:\My Documents), quote the path in/etc/fstab:"C:\My Documents" /mnt/mydocs drvfs defaults 0 0 - If you share the same Windows folder between multiple WSL distributions, use the same mount point in each distro to avoid duplicate mounts.
- For read‑only mounts (e.g., when you only need to view logs), add the
roflag:C:\Logs /mnt/logs drvfs ro 0 0. - Keep your WSL version up to date (run
wsl --update) because newer releases improvedrvfsperformance and add new mount options.
Troubleshooting
If the folder does not appear after a reboot, follow these checks in order:
- Restart both Windows and WSL. A simple power‑cycle clears transient mount issues.
- Verify the
/etc/fstabsyntax. Runsudo mount -amanually; any error message points to a line problem. - Check the
.wslconfigfile. Ensure the[automount]section does not disable processing. If the file does not exist, create it with:[automount] enabled = true - Confirm the Windows path exists. Open a Command Prompt and run
dir "C:\Projects". If Windows cannot see the folder, WSL cannot mount it either. - Inspect permissions. If you receive “permission denied”, add
uid=1000,gid=1000(or your actual UID/GID) to the mount options.C:\Projects /mnt/projects drvfs defaults,uid=1000,gid=1000 0 0 - Look for conflicting mounts. Use
mount | grep /mnt/projectsto see if another mount is already occupying the point. - Update WSL. Run
wsl --updatefrom PowerShell, then repeat the shutdown/startup cycle. - Review Windows Defender or third‑party security software. Some antiviruses block the
drvfsdriver; temporarily disable them to test.
If none of the above resolves the issue, consider removing the problematic line from /etc/fstab and using a launch script instead, as scripts provide more granular error handling.
Frequently Asked Questions
Can I mount a network share (e.g., \SERVER\share) automatically?
Yes. Map the share to a drive letter in Windows first (e.g., Z:), then add an fstab entry for Z: just like any local drive.
Do I need admin rights to edit /etc/fstab?
Editing /etc/fstab requires root privileges inside WSL, which you obtain with sudo. No additional Windows admin rights are needed unless you modify .wslconfig.
Why does my mount disappear after I close the terminal?
Mounts defined in /etc/fstab persist for the lifetime of the WSL instance, not per‑terminal. If you shut down WSL (e.g., wsl --shutdown) the mounts are re‑created on the next start. If you only close the terminal window, the instance stays alive and the mount remains.
Can I set different mount options for different folders?
Absolutely. Each line in /etc/fstab can have its own comma‑separated option list, allowing you to mix ro, metadata, uid, etc., per folder.
Is there a performance penalty for using drvfs?
Access speed is comparable to native Windows file access. Using the metadata option adds a small overhead for permission translation, but for typical development work the impact is negligible.
What if I want the mount to be read‑only for security?
Add the ro flag in the fstab line. Example: C:\Secrets /mnt/secrets drvfs defaults,ro 0 0. This prevents any write operations from the Linux side.