Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client error 'mounting ... failed, reason given by server: No such file or directory' #58

Open
andrewklajman opened this issue Nov 8, 2020 · 8 comments

Comments

@andrewklajman
Copy link

andrewklajman commented Nov 8, 2020

Apologies in advance for the amateurish question. I know that there must be something that I have done wrong but I am unsure what. If someone can help it would be appreciated.

On my docker server (192.168.1.39) I am running the following.

docker run \
-v /home/andrew/docker.uat/nfs:/container/path/foo \
-e NFS_EXPORT_0='/container/path/foo *(ro,no_subtree_check)'  \
-e NFS_DISABLE_VERSION_3=1 \
-e NFS_LOG_LEVEL=DEBUG \
--cap-add SYS_ADMIN \
--cap-add SYS_MODULE \
-p 2049:2049 \
erichough/nfs-server

The output when I run the above is the following.

==================================================================
      SETTING UP ...
==================================================================
----> log level set to DEBUG
----> will use 8 rpc.nfsd server thread(s) (1 thread per CPU)
----> building /etc/exports from environment variables
----> collected 1 valid export(s) from NFS_EXPORT_* environment variables
----> kernel module nfs is loaded
----> kernel module nfsd is loaded
----> setup complete

==================================================================
      STARTING SERVICES ...
==================================================================
----> mounting rpc_pipefs filesystem onto /var/lib/nfs/rpc_pipefs
mount: mount('rpc_pipefs','/var/lib/nfs/rpc_pipefs','rpc_pipefs',0x00008000,'(null)'):0
----> mounting nfsd filesystem onto /proc/fs/nfsd
mount: mount('nfsd','/proc/fs/nfsd','nfsd',0x00008000,'(null)'):0
----> starting rpcbind
----> starting exportfs
exporting *:/container/path/foo
----> starting rpc.mountd on port 32767
----> starting rpc.nfsd on port 2049 with 8 server thread(s)
rpc.nfsd: knfsd is currently down
rpc.nfsd: Writing version string to kernel: -2 -3 +4 +4.1 +4.2
rpc.nfsd: Created AF_INET TCP socket.
rpc.nfsd: Created AF_INET UDP socket.
rpc.nfsd: Created AF_INET6 TCP socket.
rpc.nfsd: Created AF_INET6 UDP socket.
----> terminating rpcbind
----> all services started normally

==================================================================
      SERVER STARTUP COMPLETE
==================================================================
----> list of enabled NFS protocol versions: 4.2, 4.1, 4
----> list of container exports:
---->   /container/path/foo     *(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,ro,secure,root_squash,no_all_squash)
----> list of container ports that should be exposed: 2049 (TCP)

==================================================================
      READY AND WAITING FOR NFS CLIENT CONNECTIONS
==================================================================

But when I try to mount the folder from the client machine (192.168.1.189) I get the following.

showmount -e 192.168.1.39
clnt_create: RPC: Program not registered

mount -vvv -t nfs -o vers=4,port2049 192.168.1.39:/container/path/foo /mnt/test/
mount.nfs: timeout set for Sun Nov 8 09:22:36 2020
mount.nfs: trying text-based options'port=2049,vers=4.2,addr=192.168.1.39,clientaddr=192.168.1.189'
mount.nfs: mount(2): No such file or directory
mount.nfs: mounting 192.168.1.39:/container/path/foo failed, reason given by server: No such file or directory

I feel like it has something to do with the RPC (but I only have a basic understanding of it). However when I set up a native installation (not docker) of the nfs-server package on my server then my client has no problem connecting to it.

I did log into the container and confirmed that the path /container/path/foo exists. While in the container I also confirmed that the /etc/exports was there and correct.

So I am unsure what the problem is or how to follow up any more (I have spent a day on Google with this problem and have not gotten anywhere). I have tried several variations of the above.

This is only for a home server setup but if anyone can suggest how I would appreciate it.

Thankyou

@andrewklajman
Copy link
Author

Hi All,
I was able to get this to work but i do not understand why. If I run the following on my client then the share mounts fine.
mount 192.168.1.39:/ /mnt/test

So then I was wondering how to share multiple folders. I tested with the following command

docker run \
-v /home/andrew/docker.uat/nfs1:/nfs1 \
-v /home/andrew/docker.uat/nfs2:/nfs2 \
-e NFS_EXPORT_0='/nfs1 *(ro,no_subtree_check,fsid=0)'  \
-e NFS_EXPORT_1='/nfs2 *(ro,no_subtree_check,fsid=0)'  \
-e NFS_DISABLE_VERSION_3=1 \
-e NFS_LOG_LEVEL=DEBUG \
--cap-add SYS_ADMIN \
--cap-add SYS_MODULE \
-p 2049:2049 \
erichough/nfs-server

The above generated the following output

==================================================================
      SETTING UP ...
==================================================================
----> log level set to DEBUG
----> will use 8 rpc.nfsd server thread(s) (1 thread per CPU)
----> building /etc/exports from environment variables
----> collected 2 valid export(s) from NFS_EXPORT_* environment variables
----> kernel module nfs is loaded
----> kernel module nfsd is loaded
----> setup complete

==================================================================
      STARTING SERVICES ...
==================================================================
----> mounting rpc_pipefs filesystem onto /var/lib/nfs/rpc_pipefs
mount: mount('rpc_pipefs','/var/lib/nfs/rpc_pipefs','rpc_pipefs',0x00008000,'(null)'):0
----> mounting nfsd filesystem onto /proc/fs/nfsd
mount: mount('nfsd','/proc/fs/nfsd','nfsd',0x00008000,'(null)'):0
----> starting rpcbind
----> starting exportfs
exporting *:/nfs2
exporting *:/nfs1
----> starting rpc.mountd on port 32767
----> starting rpc.nfsd on port 2049 with 8 server thread(s)
rpc.nfsd: knfsd is currently down
rpc.nfsd: Writing version string to kernel: -2 -3 +4 +4.1 +4.2
rpc.nfsd: Created AF_INET TCP socket.
rpc.nfsd: Created AF_INET UDP socket.
rpc.nfsd: Created AF_INET6 TCP socket.
rpc.nfsd: Created AF_INET6 UDP socket.
----> terminating rpcbind
----> all services started normally

==================================================================
      SERVER STARTUP COMPLETE
==================================================================
----> list of enabled NFS protocol versions: 4.2, 4.1, 4
----> list of container exports:
---->   /nfs2   *(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,no_pnfs,fsid=0,anonuid=65534,anongid=65534,sec=sys,ro,secure,root_squash,no_all_squash)
---->   /nfs1   *(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,no_pnfs,fsid=0,anonuid=65534,anongid=65534,sec=sys,ro,secure,root_squash,no_all_squash)
----> list of container ports that should be exposed: 2049 (TCP)

==================================================================
      READY AND WAITING FOR NFS CLIENT CONNECTIONS
==================================================================

Now when I run mount 192.168.1.39:/ /mnt/test it mounts /nfs1. But when I run either mount 192.168.1.39:/nfs1 /mnt/test or mount 192.168.1.39:/nfs2 /mnt/test I get the same as above.

mount.nfs: timeout set for Sun Nov 8 09:22:36 2020
mount.nfs: trying text-based options'port=2049,vers=4.2,addr=192.168.1.39,clientaddr=192.168.1.189'
mount.nfs: mount(2): No such file or directory
mount.nfs: mounting 192.168.1.39:/container/path/foo failed, reason given by server: No such file or directory

There really is only one directory that I need to share so I should be fine with the above. But still I dont understand why this is not working.

Can anyone offer some insight?

Thanks

@jjwong0915
Copy link

@andrewklajman
I encountered the same problem and found the reason is that nfs4 does not use an auxiliary protocol which allows multiple export entry directly anymore, instead it uses a virtual filesystem which has a root directory containing each export entry as a sub-directory. As a result, exporting multiple folders can be achieved by bind-mounting them into a single parent folder first.


For example, if you want to share /home/user1/.ssh and /home/user1/.local/share:

mkdir /tmp/nfs /tmp/nfs/ssh_folder /tmp/nfs/share_folder
mount --bind /home/user1/.ssh /tmp/nfs/ssh_folder
mount --bind /home/user1/.local/share /tmp/nfs/share_folder

Then, create the nfs-server container with following exports:

docker run --rm --privileged -v /tmp/nfs:/nfs -e NFS_DISABLE_VERSION_3=1 -e NFS_EXPORT_0='/nfs *(fsid=0)' -e NFS_EXPORT_1='/nfs/ssh_folder *(rw)' -e NFS_EXPORT_2='/nfs/share_folder *(ro)' erichough/nfs-server:2.2.1

After the server is started, you can now nfs-mount any of the folders:

mkdir /mnt/ssh_folder
mount <container_ip>:/ssh_folder /mnt/ssh_folder
mkdir /mnt/share_folder
mount <container_ip>:/share_folder /mnt/share_folder

I hope this will help.

@andrewklajman
Copy link
Author

@jjwong0915 , Yes you were absolutely correct.

I spent a few hours looking for the solution myself Im just curious for future reference how you came across the solution?

Thanks again.

@jjwong0915
Copy link

@andrewklajman
The solution comes from this link, which is found in the top result of searching keyword nfs4 multiple exports.

@sergiochoo
Copy link

I tried to set it up with nfs4 protocol, but no luck.
So I masked rpcbind protocol with command "sudo systemctl mask rpcbind" then rebooted the server.
This action resolved my issue.
My docker-compose.yml

version: '3.8'
services:
  nfs:
    image: erichough/nfs-server:2.2.1
    container_name: nfs
    volumes:
      - '/nfs/data:/nfs'
      - '/nfs/exports:/etc/exports:ro'
      - '/lib/modules:/lib/modules:ro'
    environment:
      - NFS_VERSION=3
      - NFS_LOG_LEVEL=DEBUG
    cap_add:
      - SYS_ADMIN
      - SYS_MODULE
    ports:
      - 2049:2049
      - 2049:2049/udp
      - 111:111
      - 111:111/udp
      - 32765:32765
      - 32765:32765/udp
      - 32767:32767
      - 32767:32767/udp

@wood-j
Copy link

wood-j commented Apr 8, 2021

same issue @2021

@lhzw
Copy link

lhzw commented Aug 29, 2022

NFS V4 cannot work, always reports:

mount -v 172.22.1.3:/ /mnt
mount.nfs: timeout set for Mon Aug 29 11:24:57 2022
mount.nfs: trying text-based options 'vers=4.2,addr=172.22.1.3,clientaddr=172.22.1.2'
mount.nfs: mount(2): No such file or directory
mount.nfs: trying text-based options 'addr=172.22.1.3'
mount.nfs: prog 100003, trying vers=3, prot=6
mount.nfs: portmap query retrying: RPC: Unable to receive
mount.nfs: prog 100003, trying vers=3, prot=17
mount.nfs: portmap query failed: RPC: Unable to receive - Connection refused
mount.nfs: trying text-based options 'vers=4.2,addr=172.22.1.3,clientaddr=172.22.1.2'

mount -v 172.22.1.3:/data /mnt
mount.nfs: timeout set for Mon Aug 29 11:15:00 2022
mount.nfs: trying text-based options 'vers=4.2,addr=172.22.1.3,clientaddr=172.22.1.2'
mount.nfs: mount(2): No such file or directory
mount.nfs: trying text-based options 'addr=172.22.1.3'
mount.nfs: prog 100003, trying vers=3, prot=6
mount.nfs: portmap query retrying: RPC: Unable to receive
mount.nfs: prog 100003, trying vers=3, prot=17
mount.nfs: portmap query failed: RPC: Unable to receive - Connection refused
mount.nfs: trying text-based options 'vers=4.2,addr=172.22.1.3,clientaddr=172.22.1.2'

Maybe we should update the document about disable V3, it's so time-wasting, thank you.

@whatwewant
Copy link

whatwewant commented Feb 20, 2024

NFSv4 is virtual filesystem, it must have only one root path with fsid=0
so just => -e NFS_EXPORT_0='/container/path/foo *(rw,no_subtree_check,fsid=0)' is ok (/container/path/foo is the root of NFSv4)
then client command:

$ mount -t nfs <SERVER>:/ /mnt/nfs

instead of

mount -t nfs <SERVER>:/container/path/foo /mnt/nfs

and Another easy way to use NFSv4 Server in Docker:

$ curl -fsSL https://raw.githubusercontent.com/zmicro-design/service-nfs/master/install -o /tmp/install.sh && bash /tmp/install.sh

OR

$ curl -fSL https://zmicro.zcorky.com/ | bash
$ zmicro service start nfs

then Client

$ mkdir -p /mnt/nfs
$ mount -t nfs <SERVER>:/ /mnt/nfs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants