WSL: Can't mount NFS from within WSL2 Ubuntu 22.04
Windows Version
Microsoft Windows [Version 10.0.22000.1696]
WSL Version
1.1.3.0
Are you using WSL 1 or WSL 2?
- WSL 2
- WSL 1
Kernel Version
Linux version 5.15.90.1-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Fri Jan 27 02:56:13 UTC 2023
Distro Version
Ubuntu 22.04
Other Software
No response
Repro Steps
I’m trying to mount an NFS share from within WSL2 running Ubuntu 22.04. This works fine on native Ubuntu. I edit /etc/fstab to add:
172.16.0.113:/mnt/share/yocto-cache /home/tom/cache nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
But I get:
$ sudo mount -vvv /home/tom/cache
mount.nfs: timeout set for Thu Mar 9 07:57:54 2023
mount.nfs: trying text-based options 'nolock,intr,tcp,actimeo=1800,vers=4.2,addr=172.16.0.113,clientaddr=172.23.196.48'
mount.nfs: mount(2): Invalid argument
mount.nfs: trying text-based options 'nolock,intr,tcp,actimeo=1800,vers=4,minorversion=1,addr=172.16.0.113,clientaddr=172.23.196.48'
mount.nfs: mount(2): Operation not permitted
mount.nfs: trying text-based options 'nolock,intr,tcp,actimeo=1800,addr=172.16.0.113'
mount.nfs: prog 100003, trying vers=3, prot=6
mount.nfs: trying 172.16.0.113 prog 100003 vers 3 prot TCP port 2049
mount.nfs: prog 100005, trying vers=3, prot=6
mount.nfs: trying 172.16.0.113 prog 100005 vers 3 prot TCP port 56713
mount.nfs: mount(2): Permission denied
mount.nfs: Operation not permitted
I’ve tried the solution from https://github.com/microsoft/WSL/issues/4150#issuecomment-504209723 but with the ports changed and added UDP support but still no luck:
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( $found ){
$remoteport = $matches[0];
echo "IP address of WSL 2 = " $remoteport;
} else{
echo "The Script exited, the IP address of WSL 2 cannot be found";
exit;
}
# [Ports]
# All the ports you want to forward separated by comma
$ports=@(111,2049);
# [Static ip]
# You can change the addr to your ip config to listen to a specific address
$addr='0.0.0.0';
$ports_a = $ports -join ",";
# Remove Firewall Exception Rules
# iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' ";
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock Outbound TCP' ";
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock Inbound TCP' ";
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock Outbound UDP' ";
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock Inbound UDP' ";
# adding Exception Rules for inbound and outbound Rules
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock Outbound TCP' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock Inbound TCP' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock Outbound UDP' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol UDP";
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock Inbound UDP' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol UDP";
for( $i = 0; $i -lt $ports.length; $i++ ){
$port = $ports[$i];
iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr";
iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport";
}
Expected Behavior
I expect the mount to work.
Actual Behavior
It fails.
Diagnostic Logs
No response
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (2 by maintainers)
Dick move.
Thank you.
Looking at the output,
Permission deniedseems to be the problem here. This is probably due to a nfs configuration mismatch between client & server, this SO post might help.Closing since this is not a WSL issue
I finally got access to the server and checked syslog after I tried to connect:
Port 53942 is not what the logging from WSL2 showed so I assume there is some port translation going on. A colleague suggested I try https://serverfault.com/a/107985/116212 so I added
insecureto/etc/exportsand this worked.For Synology NAS I found checking the “allow access from non-privileged ports” is a solution.
If you’re having problems mounting a TrueNAS share and get here like I did, you can go into TrueNAS’s Web GUI, into NFS configuration and turn on “Allow non-root mount”.