5

I have a linux embedded system that (when doing active development on it) mounts its root filesystem as an nfs share exported from my ubuntu box. So just to be extra clear: embedded linux is the nfs client, my ubuntu box is the nfs server. I don't have much control over the embedded system doing the actual nfs mounting.

When I upgraded to ubuntu 17.10, I found out this does not work any more.

After much debugging, I think I pinpointed the problem to a protocol version mismatch: while sniffing traffic with wireshark I found out the embedded system sends NFS packets with the old protocol version 2, but here's what I get on my ubuntu box I run

$ rpcinfo -p localhost
program vers proto   port  service
 100000    4   tcp    111  portmapper
 100000    3   tcp    111  portmapper
 100000    2   tcp    111  portmapper
 100000    4   udp    111  portmapper
 100000    3   udp    111  portmapper
 100000    2   udp    111  portmapper
 100005    1   udp  43512  mountd
 100005    1   tcp  39783  mountd
 100005    2   udp  35844  mountd
 100005    2   tcp  58287  mountd
 100005    3   udp  48188  mountd
 100005    3   tcp  60599  mountd
 100003    3   tcp   2049  nfs
 100003    4   tcp   2049  nfs
 100227    3   tcp   2049
 100003    3   udp   2049  nfs
 100227    3   udp   2049
 100021    1   udp  44366  nlockmgr
 100021    3   udp  44366  nlockmgr
 100021    4   udp  44366  nlockmgr
 100021    1   tcp  43079  nlockmgr
 100021    3   tcp  43079  nlockmgr
 100021    4   tcp  43079  nlockmgr
 100024    1   udp  50305  status
 100024    1   tcp  42983  status

so no nfs version 2, only 3 and 4.

Anyone knows how to add nfs version 2 support to my nfs server?

6 Answers 6

12

You need to modify /etc/default/nfs-kernel-server to have these lines:

RPCNFSDOPTS="--nfs-version 2,3,4 --debug --syslog"
# To confirm above mods are in effect after service restart use
#     cat /run/sysconfig/nfs-utils
#  or 
#    service nfs-kernel-server status
#

and restart the service

service nfs-kernel-server restart

take care that after service restart you may need to re-start shares

zfs share -a

Finally confirm that protocol 2 is being supported (tcp and udp too if necessary)

rpcinfo -p servername | fgrep nfs

You should see this

100003    2   tcp   2049  nfs
100003    3   tcp   2049  nfs
100003    4   tcp   2049  nfs
100003    2   udp   2049  nfs
100003    3   udp   2049  nfs
2
  • Thank you so much, this helped me out of a really sticky situation. Jan 22, 2018 at 23:00
  • Thank you!! I've been "debugging" this for a few hours :). Well not this directly. NFS client mounted its rootfs and requested v2 - the difference between 2 servers was that one was configured w/ v2 support, the other not. This would have been much easier to debug if only "rpcdebug -m nfsd all" would have displayed in /var/log/syslog an error message such as "NFS: version not supported". Do you know why NFS server doesn't log that or how do I see that logged?? Oct 1, 2018 at 6:30
4

If you upgrade to Ubuntu 18.04, you will find that there is no RPCNFSDOPTS variable anymore in /etc/default/nfs-kernel-server.

I had to hijack RPCNFSDCOUNT to get it to use NFS v2:

RPCNFSDCOUNT="--nfs-version 2 8"

Proof that it worked:

$ service nfs-kernel-server restart
$ cat /proc/fs/nfsd/versions
+2 +3 +4 +4.1 +4.2

After this I could mount the file system from OpenVMS Alpha 8.2 (... yes, really, ...)

$ tcpip mount dnfs2:[000000] /host=beauty /path="/exports/home" /struct=5
%TCPIP$DNFSMOUNT-S-MOUNTED, /exports/home mounted on _DNFS2:[000000]
2
  • You don't have to hijack RPCNFSDCOUNT , you can just add the line RPCNFSDOPTS and it works fine Apr 15, 2020 at 18:54
  • 1
    @WiringHarness, I just checked my /etc/init.d/nfs-kernel-server file on Ubuntu 19.10 and it contains the following segment to start nfsd: ``` start-stop-daemon --start --oknodo --quiet \ --nicelevel $RPCNFSDPRIORITY \ --exec $PREFIX/sbin/rpc.nfsd -- $RPCNFSDCOUNT ``` so I don't see how your suggestion will work. Apr 18, 2020 at 15:51
3

For Ubuntu 22.04, I used the answer above but found NFSv2 does not appear until you edit /etc/nfs.conf and enable udp=y, vers2=y which are both disabled by default. restart nfs-kernel-server and confirm with rpcinfo -p and cat /proc/fs/nfsd/versions

1
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – Pilot6
    Dec 23, 2022 at 20:40
1

I modified the nfs-server.service's loaded file.

Check the loaded file:

>> systemctl status nfs-kernel-server.service

* nfs-server.service - NFS server and services
     Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; ...

Modify the file:

sudo vi /lib/systemd/system/nfs-server.service
...

ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS

-> ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS -V -2

...

Restart service and check the available nfs versions.

>> sudo systemctl daemon-reload
>> sudo systemctl restart nfs-kernel-server.service

>> sudo cat /proc/fs/nfsd/version

+2 +3 +4 +4.1 +4.2
New contributor
pingu is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

I ran into the same problem with my embedded system (TI AM5728). Assuming you are using uboot, the trick is to change the command line being passed to the kernel. This is set by the contents of the bootargs environment variable. (see uboot documentation for details)

To fix you will need to add a ",nfsvers=3" addition onto the end of the nfsroot portion of your kernel command line (bootargs variable)

On my system when booting into NFS, the bootargs variable line looks like the following:

bootargs=console=ttyO2,115200n8 root=/dev/nfs rw rootfstype=nfs ip=dhcp nfsroot=192.168.x.x:/path/to/share

This worked fine until 17.10 and then died - The following change forces the kernel to connect using NFS v3.

bootargs=console=ttyO2,115200n8 root=/dev/nfs rw rootfstype=nfs ip=dhcp nfsroot=192.168.x.x:/path/to/share,nfsvers=3

0

UPDATE: on Ubuntu 22.04, we cannot enable the nfs server with 6.x kernel (you can check it in uname -a) since CONFIG_NFSD_V2 is not enabled. We have to boot with 5.x kernel. See comment #14 on this page for details.

From Ubuntu 22.04, the hack of RPCNFSDCOUNT/RPCNFSDOPTS doesn't work any more (because /lib/systemd/scripts/nfs-utils_env.sh has been removed, which used the RPCNFSDCOUNT/RPCNFSDOPTS variables).

Do this instead:

echo -e "[nfsd]\nudp=y\nvers2=y" | sudo tee /etc/nfs.conf.d/local.conf
sudo systemctl restart nfs-server.service

How did I found out this configuration:

  • systemctl cat nfs-server.service shows nfs-server.service executes rpc.nfsd (ExecStart=/usr/sbin/rpc.nfsd)
  • man rpc.nfsd shows the configuration file is located at /etc/nfs.conf
  • man nfs.conf shows the format of the configuration file, and says /etc/nfs.conf.d/*.conf is also valid configuration files

You can confirm that the configuration is applied with these commands:

  • nfsconf --dump
  • rpcinfo -s
  • rpcinfo -p
  • sudo cat /proc/fs/nfsd/versions
--- "nfsconf --dump.1"
+++ "nfsconf --dump.2"
 [general]
  pipefs-directory = /run/rpc_pipefs
 
 [mountd]
  manage-gids = y
+
+[nfsd]
+ vers2 = y

--- "rpcinfo -s.1"
+++ "rpcinfo -s.2"
    program version(s) netid(s)                         service     owner
     100000  2,3,4     local,udp,tcp,udp6,tcp6          portmapper  superuser
     100005  3,2,1     tcp6,udp6,tcp,udp                mountd      superuser
     100024  1         tcp6,udp6,tcp,udp                status      136
-    100003  4,3       tcp6,tcp                         nfs         superuser
-    100227  3         tcp6,tcp                         -           superuser
+    100003  4,3,2     tcp6,tcp                         nfs         superuser
+    100227  3,2       tcp6,tcp                         -           superuser
     100021  4,3,1     tcp6,udp6,tcp,udp                nlockmgr    superuser

--- "rpcinfo -p.1"
+++ "rpcinfo -p.2"
    program vers proto   port  service
+    100003    2   tcp   2049  nfs
     100003    3   tcp   2049  nfs
     100003    4   tcp   2049  nfs
+    100227    2   tcp   2049
     100227    3   tcp   2049

--- "sudo cat /proc/fs/nfsd/versions.1"
+++ "sudo cat /proc/fs/nfsd/versions.2"
--2 +3 +4 +4.1 +4.2
++2 +3 +4 +4.1 +4.2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .