NFS cannot allocate memory seems to be common issue a lot of people face while mounting NFSv4 shares, as revealed from search results on Google. Even I faced it when trying to mount a NFS share exported from my desktop on my Raspberry Pi. It didn’t give the error on the Pi, though. I discovered this issue when debugging this problem and tried to mount on localhost.

Initially it appears to be a kernel issue, but it turned out not to be one. After researching a lot about the problem I understood that it is a error in exports configuration!

Basically, in NFSv4, there is a / (root) under which all shares are exported and this must have the fsid=0 parameter specified in the configuration.
At the client, while mounting you are not supposed to specify the full path to the resource, instead it must be relative to the NFS Root.

The following example would clear it up –

I’ll try to export /home and mount it on localhost with following configuration:

# /etc/exports: NFS file systems being exported.  See exports(5).
/home *(rw,no_root_squash,no_all_squash,no_subtree_check)

And when I run the mount command:

Linux ~ # mount localhost:/home /mnt/nfs -v
mount.nfs: timeout set for Tue Jan 29 11:59:27 2013
mount.nfs: trying text-based options 'vers=4,addr=::1,clientaddr=::1'
mount.nfs: mount(2): Cannot allocate memory
mount.nfs: Cannot allocate memory

Now I’ll change the exportfs configuration to:

Linux ~ # cat /etc/exports 
# /etc/exports: NFS file systems being exported.  See exports(5).
/home *(fsid=rw,no_root_squash,no_all_squash,no_subtree_check)

Running the mount command again,

Linux ~ # exportfs -rv
exporting *:/home
Linux ~ # mount localhost:/home /mnt/nfs -v
mount.nfs: timeout set for Tue Jan 29 12:01:58 2013
mount.nfs: trying text-based options 'vers=4,addr=::1,clientaddr=::1'
mount.nfs: mount(2): No such file or directory
mount.nfs: trying text-based options 'addr=::1'
mount.nfs: prog 100003, trying vers=3, prot=6
mount.nfs: trying ::1 prog 100003 vers 3 prot TCP port 2049
mount.nfs: prog 100005, trying vers=3, prot=17
mount.nfs: trying ::1 prog 100005 vers 3 prot UDP port 60646
localhost:/home on /mnt/nfs type nfs (rw)

Now, in the above output, you can see that while it failed to mount with NFSv4, but it succeeded in mounting NFSv3. This comes from the newer way of exports which is partially explained in the manual exports(5).

The solution to the No such file or directory is simple, you have to use / as the path to mount the root and if you are exporting some subdirectories, they need to be relative to / in the mount command instead of the full path.

Now modifying the mount command accordingly:

Linux ~ # mount localhost:/ /mnt/nfs -v
mount.nfs: timeout set for Tue Jan 29 12:15:11 2013
mount.nfs: trying text-based options 'vers=4,addr=::1,clientaddr=::1'
localhost:/ on /mnt/nfs type nfs (rw)

Now if I export a subdirectory inside /home, say my home folder /home/nilesh then it would be available via NFSv4 to clients as /nilesh and not /home/nilesh.

There seems to be a big problem controlling access in this model, you can’t have different permissions for /home and /home/nilesh. If you export /home as read-only, /home/nilesh will also get mounted read-only no matter what.

If you export /home as read-write and /home/nilesh as read-only, then clients would be able to write into all directories on the share, when the share root is mounted, i.e. /, but if the client mounts /home/nilesh it will be read-only.

I’m not sure about how to control access in NFSv4 for subdirectories, since you cannot have more than one entry for fsid=0. If you know the answer, do comment.

Advertisements

5 responses to “NFS cannot allocate memory and No such file or directory errors”

  1. Zach Goldsmith Avatar
    Zach Goldsmith

    make sure portmap is running on client with server running nfs4 # chkconfig portmap on
    follow this tutorial here: >> http://www.brennan.id.au/19-Network_File_System.html

    Like

    1. Portmap isn’t a separate service on Arch or Gentoo. I had rpcbind running on both server and client with firewall disabled.

      Like

      1. Zach Goldsmith Avatar
        Zach Goldsmith

        strange. My client is RHL5, and Server is RHL6,. Neither distros have NFS enabled out of the box. I was getting Input/Output Error and Cannot Allocate Memory, until I started portmap on the RHL5 client. This may narrow down a more amicable solution to configuring NFS4 across legacy distributions.

        Like

      2. Portmap one is a known issue and I came across it many times when I was solving the issue.
        But it simply didn’t match my environment.

        Like

  2. Nikolay Mihaylov Avatar
    Nikolay Mihaylov

    I had exactly same problem. However when I mounted /, I realized there is a symlink on the host system. Once I fixed with real path all was ok.

    Like

Leave a comment