Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mount Windows folders in WSL automatically on startup

When I go into WSL the C drive is automatically mounted at /mnt/c. I would further like to mount a folder C:\D to the mount point /mnt/d.

The contents of /etc/fstab:

LABEL=cloudimg-rootfs   /        ext4   defaults        0 0
/mnt/c/D        /mnt/d  none    bind

The contents of /etc/wsl.conf:

# Enable extra metadata options by default
[automount]
enabled = true
root = /mnt/
options = "metadata,umask=22,fmask=11"
mountFsTab = true

# Enable DNS – even though these are turned on by default, we’ll specify here just to be explicit.
[network]
generateHosts = true
generateResolvConf = true

When I do sudo mount -a then it mounts correctly. However it is not mounted at startup and running mount -a reports "mount: only root can use "--all" option".

like image 622
Kit Johnson Avatar asked Jan 29 '20 00:01

Kit Johnson


1 Answers

The question is old but if somebody still hit the question I found the answer in WSL release notes

WSL now processes the /etc/fstab file during instance start [GH 2636]. This is done prior to automatically mounting DrvFs drives; any drives that were already mounted by fstab will not be remounted automatically, allowing you to change the mount point for specific drives.

Therefore before bind mount one have to add mount for windows drive: eg:

# <file system> <dir> <type> <options> <dump> <pass>
C: /mnt/c drvfs rw,noatime,uid=1000,gid=1000,case=off,umask=0027,fmask=0137, 0 0
/mnt/c/directory/for/mount /where/to/mount none bind,default 0 0
like image 91
glpub Avatar answered Nov 17 '22 17:11

glpub