I want to mount a Windows partition inside wsl ubuntu 18.04.2 LTS
. I added the following line to /etc/fstab
:
\\192.168.2.42\c /mnt/test drvfs noauto,defaults,user 0 0
It works if I run it with sudo like this:
sudo mount /mnt/test
Then I added a file to /etc/sudoers.d/
with this context (also tried with my user and host name etc.):
ALL ALL = (root) NOPASSWD: /bin/mount
I restartet wsl (also tried reboot):
net stop LxssManager
net start LxssManager
When I now run mount without sudo I still get:
mount /mnt/test
mount: only root can use "--options" option <3>init: (146) ERROR:
UtilCreateProcessAndWait:360: /bin/mount failed with status 0x100 No
error information
Edit after feedback from @biswapriyo
I was in the group sudo already (1st step). The 2nd step mounts the drive when launching wsl. /etc/wsl.conf
:
# Enable extra metadata options by default
[automount]
enabled = true
options = "defaults,user"
mountFsTab = true
It works because it is launched as root I suppose. Nevertheless this is not what I need. Background: I need to mount a remote VPN network drive by a shell script. I don't always need it and it might not always be available. So mounting on startup is not an option.
Answering my own question:
/etc/fstab
stuff does not work for wsl.sudo visudo
does:enter:
sudo visudo
then
yourusername ALL=NOPASSWD: /bin/mount /media/data, /bin/umount /media/data
replace yourusername
with your login name, then you can do a
sudo mount /media/data
, still need the sudo
but works w/o password.
Note: /media/data
and /media/data/
are handled differently so be aware. Maybe enter both to be on the safe side.