15

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".

1
  • Mounting is for file systems, I don't think you can "mount" a folder. You might be looking for a symlink: ln -s /mnt/c/D /mnt/d. However I'd not recommend this because you create the impression that it's a mount point while it's not.
    – geronimo
    Commented Apr 1, 2020 at 7:36

2 Answers 2

17

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
1

Here is a convenient mount command to make your Windows home also your WSL home, provided you create the Linux user in the same name as your Windows account:

sudo mount -t drvfs C:/Users /home -o "rw,noatime,dirsync,mmap,access=client,msize=262144,trans=virtio"
ls -l ~/

The equivalent line to add to /etc/fstab to make it permanent and load your .bash_profile and .bashrc files in your Windows home folder is:

C:/Users /home drvfs rw,noatime,dirsync,mmap,access=client,msize=262144,trans=virtio

Voilà, enjoy!

Not the answer you're looking for? Browse other questions tagged or ask your own question.