# [solved] NFS Server not working after systemd migration

## Nitro_146

Hi All,

I have a few directories exported via NFS to my wife's ubuntu box.

The shares ceased to work after I migrated to systemd (as well as syslog, but this is another story)

on the client side :

```
# showmount -e 192.168.1.2

clnt_create: RPC: Program not registered

```

```

# mount -t nfs 192.168.1.2:/home/pierre/a_sauver/Photos_a_graver /tmp/test -v -o nfsvers=4,vers=4

mount.nfs: timeout set for Mon Dec 30 16:44:00 2013

mount.nfs: trying text-based options 'nfsvers=4,vers=4,addr=192.168.1.2,clientaddr=192.168.1.3'

mount.nfs: mount(2): Permission denied

mount.nfs: access denied by server while mounting 192.168.1.2:/home/pierre/a_sauver/Photos_a_graver

```

On the server side

```
#exportfs -rav

exporting 192.168.1.0/24:/home/pierre/partage_marine

exporting 192.168.1.0/24:/mnt/stockage/videos

exporting 192.168.1.0/24:/mnt/stockage/sauvegarde_photos/APN

exporting 192.168.1.0/24:/mnt/stockage/films_a_voir

exporting 192.168.1.0/24:/home/pierre/a_sauver/Photos_a_graver
```

 Note that I also tried with /255.255.255.0 instead of /24

```
#systemctl --failed 

UNIT               LOAD   ACTIVE SUB    DESCRIPTION

rpc-mountd.service loaded failed failed NFS Mount Daemon

syslog-ng.service  loaded failed failed System Logger Daemon

syslog.socket      loaded failed failed Syslog Socket

```

```

# systemctl -l status rpc-mountd

rpc-mountd.service - NFS Mount Daemon

   Loaded: loaded (/usr/lib64/systemd/system/rpc-mountd.service; linked)

   Active: failed (Result: exit-code) since lun. 2013-12-30 16:39:53 CET; 47min ago

  Process: 24400 ExecStart=/usr/sbin/rpc.mountd $OPTS_RPC_MOUNTD (code=exited, status=1/FAILURE)

déc. 30 16:39:53 core-i5 rpc.mountd[24400]: Usage: rpc.mountd [-F|--foreground] [-h|--help] [-v|--version] [-d kind|--debug kind]

déc. 30 16:39:53 core-i5 systemd[1]: rpc-mountd.service: control process exited, code=exited status=1

déc. 30 16:39:53 core-i5 systemd[1]: Failed to start NFS Mount Daemon.

déc. 30 16:39:53 core-i5 systemd[1]: Unit rpc-mountd.service entered failed state.

```

```

# showmount -e 192.168.1.2

clnt_create: RPC: Program not registered

```

```

# rpcinfo -p 192.168.1.2

   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

    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

    100003    4   udp   2049  nfs

    100021    1   udp  53222  nlockmgr

    100021    3   udp  53222  nlockmgr

    100021    4   udp  53222  nlockmgr

    100021    1   tcp  59595  nlockmgr

    100021    3   tcp  59595  nlockmgr

    100021    4   tcp  59595  nlockmgr

    100024    1   udp  42683  status

    100024    1   tcp  35679  status

```

I googled a bit and foud the ArchWiki nfs page (https://wiki.archlinux.org/index.php/NFS#Client)

but I am stuck because I cannot start rpc-idmapd.service and rpc-mountd.service

Anyone can help me ?

Thank you.

----------

## Kompi

You need quite a lot of services and some pseudo file systems mounted for nfs to work properly. When I switched to systemd there weren't any service files so I wrote my own. Took me a while, since it was a bit of a hassle to find out the right order and what I actually need. This is my setup for nfsv4:

proc-fs-nfsd.mount:

```
[Unit]

Description=/proc/fs/nfsd

Before=nfs.target

Before=rpc.nfsd.service

[Mount]

What=nfsd

Where=/proc/fs/nfsd

Type=nfsd

Options=nodev,noexec,nosuid

[Install]

WantedBy=nfs.target
```

var-lib-nfs-rpc_pipefs.mount:

```
[Unit]

Description=rpc_pipefs

Before=nfs.target

Before=remote-fs-pre.target

[Mount]

What=rpc_pipefs

Where=/var/lib/nfs/rpc_pipefs

Type=rpc_pipefs

[Install]

WantedBy=nfs.target
```

rpcbind.service:

```
[Unit]

Description=NFS port mapping server

Before=nfs.target

Before=remote-fs-pre.target

[Service]

EnvironmentFile=/etc/conf.d/rpcbind

ExecStart=/sbin/rpcbind $RPCBIND_OPTS

Type=forking

[Install]

WantedBy=nfs.target
```

rpc.idmapd.service:

```
[Unit]

Description=NFSv4 ID - Name Mapper

Wants=rpcbind.service

Wants=var-lib-nfs-rpc_pipefs.mount

Wants=proc-fs-nfsd.mount

After=proc-fs-nfsd.mount

Before=nfs.target

Before=remote-fs-pre.target

[Service]

EnvironmentFile=/etc/conf.d/nfs

ExecStart=/usr/sbin/rpc.idmapd -f $OPTS_RPC_IDMAPD

[Install]

WantedBy=nfs.target
```

rpc.mountd.service:

```
[Unit]

Description=RPC mountd

Wants=rpcbind.service

After=rpcbind.service

After=rpc.svcgssd.service

After=rpc.idmapd.service

Before=nfs.target

[Service]

EnvironmentFile=/etc/conf.d/nfs

ExecStart=/usr/sbin/rpc.mountd --foreground $OPTS_RPC_MOUNTD

[Install]

WantedBy=nfs.target
```

rpc.statd.service:

```
[Unit]

Description=NFS status daemon

Wants=rpcbind.service

After=rpc.svcgssd.service

After=rpc.idmapd.service

After=rpc.mountd.service

Before=rpc.nfsd.service

Before=nfs.target

[Service]

EnvironmentFile=/etc/conf.d/nfs

ExecStart=/sbin/rpc.statd --no-notify -F $OPTS_RPC_STATD

```

sm-notify.service:

```
[Unit]

Description=NFS sm-notify

Wants=rpc.statd.service

Before=nfs.target

Before=remote-fs-pre.target

[Service]

EnvironmentFile=/etc/conf.d/nfs

ExecStart=/usr/sbin/sm-notify -d $OPTS_SMNOTIFY

Type=oneshot

[Install]

WantedBy=nfs.target
```

rpc.gssd.service:

```
[Unit]

Description=NFS rpcsec_gss daemon

Wants=rpcbind.service

Wants=var-lib-nfs-rpc_pipefs.mount

After=var-lib-nfs-rpc_pipefs.mount

Before=nfs.target

Before=remote-fs-pre.target

# shutdown while sleeping, to re-authenticate with kerberos after resume

Conflicts=sleep.target

[Service]

EnvironmentFile=/etc/conf.d/nfs

ExecStart=/usr/sbin/rpc.gssd -f $OPTS_RPC_GSSD

Restart=on-failure

[Install]

WantedBy=nfs.target
```

rpc.svcgssd.service:

```
[Unit]

Description=NFS rpcsec_gss server daemon

Wants=rpcbind.service

Wants=proc-fs-nfsd.mount

After=proc-fs-nfsd.mount

Before=nfs.target

[Service]

EnvironmentFile=/etc/conf.d/nfs

ExecStart=/usr/sbin/rpc.svcgssd -f ${OPTS_RPC_SCVGSSD}

Restart=on-failure

[Install]

WantedBy=nfs.target
```

rpc.nfsd.service:

```

[Unit]

Description=NFS server

Wants=rpcbind.service 

Wants=rpc.statd.service 

Wants=rpc.mountd.service

After=rpcbind.service

After=rpc.statd.service

After=rpc.svcgssd.service

After=rpc.idmapd.service

Before=nfs.target

[Service]

Type=oneshot

RemainAfterExit=yes

EnvironmentFile=/etc/conf.d/nfs

ExecStart=/usr/sbin/rpc.nfsd ${OPTS_RPC_NFSD}

ExecStop=/usr/sbin/rpc.nfsd 0

[Install]

WantedBy=nfs.target
```

exportfs.service:

```
[Unit]

Description=NFS server exports

Wants=rpcbind.service 

Wants=rpc.statd.service 

After=rpc.mountd.service

After=rpc.statd.service

Before=nfs.target

[Service]

Type=oneshot

RemainAfterExit=yes

EnvironmentFile=/etc/conf.d/nfs

ExecStart=/usr/sbin/exportfs -r

ExecStop=/usr/sbin/exportfs -ua

ExecReload=/usr/sbin/exportfs -r

[Install]

WantedBy=nfs.target
```

nfs.target:

```
[Unit]

Description=NFS services

[Install]

WantedBy=multi-user.target
```

The rpc.[svc]gssd services are only needed if you use nfsv4 with kerberos authentication. Enable rpc.gssd on the client and rpc.svcgssd on the server.

The rpc.mountd and rpc.statd, as well als sm-notify services are only necessary if you are using nfsv3 shared. Enable the first two on the server if you export nfsv3 shares, and sm-notify on the client.

To make it a little easier, these are the services you need to enable on the server:

```

systemctl enable var-lib-nfs-rpc_pipefs.mount

systemctl enable proc-fs-nfsd.mount  

systemctl enable rpcbind.service   

systemctl enable rpc.idmapd.service  

systemctl enable rpc.nfsd.service   

systemctl enable exportfs.service  

# for NFSv3 only:

systemctl enable rpc.mountd.service

systemctl enable rpc.statd.service

# for NFSv4 kerberos auth only:

systemctl enable rpc.svcgssd.service

# finally, enable nfs.target to start services at boot:

systemctl enable nfs.target

```

on the client:

```

systemctl enable rpcbind.service   

systemctl enable var-lib-nfs-rpc_pipefs.mount

systemctl enable rpc.idmapd.service  

# for nfsv3 only:

systemctl enable sm-notify.service  

# for nfsv4 kerberos auth only:

systemctl enable rpc.gssd.service

# finally, enable nfs.target to start services at boot:

systemctl enable nfs.target

```

Of course you need to add a "After=remote-fs-pre.target" in the [unit] section to any .mount unit on the client that should mount an nfs share.

Hope those files can help you.

----------

## Nitro_146

Thank you for such a long and precise answer !

Right now, I am not on my gentoo box, but I will try this in a few days.

I will write down some feedback then.

----------

## ese002

Thanks, Kompi!

I'm not the original poster but I had the exact same problem.  I used your service files, not to directly execute but as a guide to find out what was missing.  At this point, there are service files.  They just don't seem to be entirely complete or documented.  I determined that all I needed was the stock rpc-mountd.service

# systemctl enable rpc-mountd.service

# systemctl start rpc-mountd.service

And I'm golden!  It is possible that another supplied service is necessary that I have enabled in my fumbling but no new service were needed.

----------

## 666threesixes666

bleh please file bugs to the tracker so the packages come as "just works" for systemd

----------

## Nitro_146

Hello,

I am the original poster.

It is still not working for me, nfsd.service fails to start at boot

```
 # systemctl --failed 

UNIT              LOAD   ACTIVE SUB    DESCRIPTION

nfsd.service      loaded failed failed NFS server

syslog-ng.service loaded failed failed System Logger Daemon

syslog.socket     loaded failed failed Syslog Socket
```

I can start it manually, but it still does not work

```
# systemctl start nfsd

# showmount -e 192.168.1.2 

clnt_create: RPC: Program not registered
```

I cannot start rpc-mountd.service as suggested by ese002

```
 # systemctl status rpc-mountd.service

rpc-mountd.service - NFS Mount Daemon

   Loaded: loaded (/usr/lib64/systemd/system/rpc-mountd.service; disabled)

   Active: failed (Result: exit-code) since ven. 2014-01-03 10:03:57 CET; 3min 36s ago

  Process: 8729 ExecStart=/usr/sbin/rpc.mountd $OPTS_RPC_MOUNTD (code=exited, status=1/FAILURE)

janv. 03 10:03:57 core-i5 systemd[1]: Starting NFS Mount Daemon...

janv. 03 10:03:57 core-i5 systemd[1]: rpc-mountd.service: control process exited, cod...s=1

janv. 03 10:03:57 core-i5 systemd[1]: Failed to start NFS Mount Daemon.

janv. 03 10:03:57 core-i5 systemd[1]: Unit rpc-mountd.service entered failed state.

Hint: Some lines were ellipsized, use -l to show in full.
```

@666threesixes666 : Should I file a bug for systemd package or nfs package ?

----------

## ese002

What does journalctl report?

journalctl is the "native" logging method for systemd.  If syslog isnt' running, it is your best bet to figuring out what is going on.

Is it possible that, in adding support for systemd in your kernel, that you inadvertently removed support for nfs?  That would prevent nfsd from running.

If you still have the openrc files you could run /etc/init.d/nfs to determine if nfs is truly broken of it is just a systemd problem.

----------

## Nitro_146

Here are the logs related to nfs

```

# journalctl | grep nfs

janv. 05 08:46:06 core-i5 kernel: Installing knfsd (copyright (C) 1996 okir@monad.swb.de).

janv. 05 08:46:06 core-i5 systemd[1]: Mounting /proc/fs/nfsd...

janv. 05 08:46:06 core-i5 systemd[1]: Mounted /proc/fs/nfsd.

janv. 05 08:46:07 core-i5 rpc.nfsd[3216]: rpc.nfsd: Setting version failed: errno 22 (Invalid argument)

janv. 05 08:46:07 core-i5 rpc.nfsd[3215]: rpc.nfsd: Setting version failed: errno 22 (Invalid argument)

janv. 05 08:46:07 core-i5 rpc.nfsd[3216]: rpc.nfsd: unable to bind inet TCP socket: errno 98 (Address already in use)

janv. 05 08:46:07 core-i5 rpc.nfsd[3215]: rpc.nfsd: unable to bind inet6 TCP socket: errno 98 (Address already in use)

janv. 05 08:46:07 core-i5 kernel: NFSD: Using /var/lib/nfs/v4recovery as the NFSv4 state recovery directory

```

NFS is still activated in the kernel

```
 │          < >   NFS client support                                                      │

 │         <*>   NFS server support                                                      │

 │         -*-     NFS server support for NFS version 3                                  │

 │         [ ]       NFS server support for the NFSv3 ACL protocol extension             │

 │         [*]     NFS server support for NFS version 4                                  │

 │         [ ]       NFS server manual fault injection                                   │

 │         [ ]   RPC: Enable dprintk debugging                                           │

 │         < >   Ceph distributed file system                                            │

 │         < >   CIFS support (advanced network filesystem, SMBFS successor)             │

 │         < >   NCP file system support (to mount NetWare volumes)                      │

 │         < >   Coda file system support (advanced network fs)                          │

 │         < >   Andrew File System support (AFS)                                        │

 │                                                
```

I will try to launch nfs from openrc, later since I have a warning when I try to do it now, and I don't want to break my system at this moment...

----------

## ese002

 *Nitro_146 wrote:*   

> Here are the logs related to nfs
> 
> ```
> 
> # journalctl | grep nfs
> ...

 

That suggests that nfsd is already running.  The new launch is failing because it can't bind to the port.

----------

## Nitro_146

But, if it is running, why my wife's box cannot mount the shared directories ?

Should I investigate on it ?

----------

## ese002

 *Nitro_146 wrote:*   

> But, if it is running, why my wife's box cannot mount the shared directories ?
> 
> Should I investigate on it ?

 

Running doesn't necessarily mean working.  That was the situation I had.  nfsd was running but without rpc-mountd, I could not mount the directories.  At minimum, you need to make sure that nfs is shut down before starting again.   

systemctrl stop nfsd.service 

This should shut down nfsd assuming it was started by systemd.  I'm not sure what it will do if nfsd was started manually or by openrc.  The latter is a possibility.  I found that with the recommended boot arg of Init=/usr/lib/systemd/systemd I got a broken openrc boot instead of a systemd boot. I had to change Init to real_init to get a clean systemd boot.

----------

## Nitro_146

I stopped it and restarted it via systemctl. Remote connexion is still not possible.

I also have had to append real_init to my grub.conf to make it boot with systemd

----------

## 666threesixes666

im not sure if its systemd that the bug is filed against, im pretty sure it would be against nfs.

----------

## ese002

666, I did file https://bugs.gentoo.org/show_bug.cgi?id=496832

But it turned out to duplicate https://bugs.gentoo.org/show_bug.cgi?id=484768

Which was closed as WONTFIX through peculiar reasoning.

----------

## Nitro_146

Sorry to answer so late, but I have had some urgent stuff to do last couple weeks.

So if this is not a bug, how can I have my nfs shares to work ?

If needed I can restart it form the start if I am sure that will fix the problem. Do you know an up-to-date how-to (including systemd) ?

----------

## ese002

Nitro, the bug/nonbug in question is the lack of dependency for rpc-mountd.  While you may have this problem too, it clearly isn't the only issue.

Previously, it appeared that you had another instance of nfsd running that was interfering with launching via systemd.  You stopped and restart nfsd using sytstemd but that may not be sufficient.  If nfsd was not started by systemd, then systemctl stop nfsd may not kill it.  Check for it with ps (ps -eaf |grep nfsd).  If necessary, you can pkill nfsd.  Once you are sure there is no nfsd running, then you start it systemctl.

----------

## Nitro_146

It seems that nfsd is started by systemctl

```
# ps -eaf |grep nfsd

root      3232     2  0 08:54 ?        00:00:00 [nfsd4]

root      3233     2  0 08:54 ?        00:00:00 [nfsd4_callbacks]

root      3237     2  0 08:54 ?        00:00:00 [nfsd]

root      3238     2  0 08:54 ?        00:00:00 [nfsd]

root      3239     2  0 08:54 ?        00:00:00 [nfsd]

root      3240     2  0 08:54 ?        00:00:00 [nfsd]

root      3241     2  0 08:54 ?        00:00:00 [nfsd]

root      3242     2  0 08:54 ?        00:00:00 [nfsd]

root      3243     2  0 08:54 ?        00:00:00 [nfsd]

root      3244     2  0 08:54 ?        00:00:00 [nfsd]

# systemctl stop nfsd

# ps -eaf |grep nfsd

root      9709  8755  0 22:38 pts/0    00:00:00 grep --colour=auto nfsd
```

----------

## ese002

Now, with nfsd not running, if you start it with systemctl, does it still complain about "Address already in use"?

----------

## Nitro_146

No complaint at all, it starts flawlessly

```
# systemctl start nfsd
```

----------

## ese002

Is rpc-mountd running?

----------

## Nitro_146

Not, it is not.

```
# systemctl -l status rpc-mountd 

rpc-mountd.service - NFS Mount Daemon

   Loaded: loaded (/usr/lib64/systemd/system/rpc-mountd.service; disabled)

   Active: inactive (dead)
```

And It does not start

```
# systemctl start rpc-mountd 

Job for rpc-mountd.service failed. See 'systemctl status rpc-mountd.service' and 'journalctl -xn' for details.
```

----------

## ese002

Is rpc-mountd.service enabled?

systemctl enable rpc-mountd.service

systemctl start rpc-mountd.service

If that works, then restart nfsd and see if it works.

----------

## Nitro_146

Unfortunately, it does not work

```
# systemctl enable rpc-mountd.service 

ln -s '/usr/lib64/systemd/system/rpc-mountd.service' '/etc/systemd/system/multi-user.target.wants/rpc-mountd.service'

# systemctl start rpc-mountd.service 

Job for rpc-mountd.service failed. See 'systemctl status rpc-mountd.service' and 'journalctl -xn' for details.

# systemctl -l status rpc-mountd.service

rpc-mountd.service - NFS Mount Daemon

   Loaded: loaded (/usr/lib64/systemd/system/rpc-mountd.service; enabled)

   Active: failed (Result: exit-code) since mar. 2014-01-21 23:48:33 CET; 11s ago

  Process: 31990 ExecStart=/usr/sbin/rpc.mountd $OPTS_RPC_MOUNTD (code=exited, status=1/FAILURE)

janv. 21 23:48:33 core-i5 rpc.mountd[31990]: Usage: rpc.mountd [-F|--foreground] [-h|--help] [-v|--version] [-d kind|--debug kind]

janv. 21 23:48:33 core-i5 rpc.mountd[31990]: [-o num|--descriptors num] [-f exports-file|--exports-file=file]

janv. 21 23:48:33 core-i5 rpc.mountd[31990]: [-p|--port port] [-V version|--nfs-version version]

janv. 21 23:48:33 core-i5 rpc.mountd[31990]: [-N version|--no-nfs-version version] [-n|--no-tcp]

janv. 21 23:48:33 core-i5 rpc.mountd[31990]: [-H ha-callout-prog] [-s|--state-directory-path path]

janv. 21 23:48:33 core-i5 rpc.mountd[31990]: [-g|--manage-gids] [-t num|--num-threads=num] [-u|--no-udp]

janv. 21 23:48:33 core-i5 systemd[1]: rpc-mountd.service: control process exited, code=exited status=1

janv. 21 23:48:33 core-i5 systemd[1]: Failed to start NFS Mount Daemon.

janv. 21 23:48:33 core-i5 systemd[1]: Unit rpc-mountd.service entered failed state.
```

----------

## ese002

 *Nitro_146 wrote:*   

> Unfortunately, it does not work
> 
> ```
> # systemctl enable rpc-mountd.service 
> 
> ...

 

Well, at least you know the issue is rpc-mountd.  Looks like the service file is messed up.  Did you edit your copy?  Unfortunately, I'm not at my machine so I can't tell what it is "supposed" to look like.

----------

## Nitro_146

If by «edit your copy» you mean modify some file, I don't remember exactly. I have this issue for 2 month now and I have tried several fixes.

Should I backup my config file, unmerge nfsd (and some other package) and emerge it again ?

----------

## ese002

 *Nitro_146 wrote:*   

> If by «edit your copy» you mean modify some file, I don't remember exactly. I have this issue for 2 month now and I have tried several fixes.
> 
> Should I backup my config file, unmerge nfsd (and some other package) and emerge it again ?

 

I meant: did you edit the service file: rpc-mountd.service?  I'm running unmodified.

I'm not really sure which package this file comes from.  It might have come with systemd.  

If you have equery you can "equery --belongs /usr/lib64/systemd/system/rpc-mountd.service" and remerge whichever package it is.

----------

## Nitro_146

Hum... this is weird !

```
# equery belongs /usr/lib64/systemd/system/rpc-mountd.service

 * Searching for /usr/lib64/systemd/system/rpc-mountd.service ... 

```

No answer.

I have

```
# find / -name rpc-mountd.service

/sys/fs/cgroup/systemd/system.slice/rpc-mountd.service

/usr/portage/net-fs/nfs-utils/files/rpc-mountd.service

/usr/lib64/systemd/system/rpc-mountd.service

/etc/systemd/system/multi-user.target.wants/rpc-mountd.service

```

Let's re-emerge nfs-utils and systemd

(...some time...)

No change, the service refuses to start.

----------

## ese002

 *Nitro_146 wrote:*   

> Hum... this is weird !
> 
> Let's re-emerge nfs-utils and systemd
> 
> (...some time...)
> ...

 

rpc-mountd.service is provided by nfs-utils.  You just have to equery /usr/lib instead of /usr/lib64

What I have (default) looks like this:

------------------------------------------------------

[Unit]

Description=NFS Mount Daemon

After=rpcbind.service nfsd.service

Requires=rpcbind.service nfsd.service

[Service]

Type=forking

EnvironmentFile=/etc/conf.d/nfs

ExecStart=/usr/sbin/rpc.mountd $OPTS_RPC_MOUNTD

[Install]

WantedBy=multi-user.target

------------------------------------------------------

The error you are seeing looks like invalid options are being passed to rpc.mountd.  If your service file is unmodified the problem would seem to lie in /etc/conf.d/nfs.  Look for OPTS_RPC_MOUNTD in this file.  Mine is set to null:

----------------------------------------

# Options to pass to rpc.mountd

# ex. OPTS_RPC_MOUNTD="-p 32767"

OPTS_RPC_MOUNTD=""

-------------------------------------------

----------

## Kompi

 *Nitro_146 wrote:*   

> 
> 
>   Process: 31990 ExecStart=/usr/sbin/rpc.mountd $OPTS_RPC_MOUNTD (code=exited, status=1/FAILURE)
> 
> janv. 21 23:48:33 core-i5 rpc.mountd[31990]: Usage: rpc.mountd ....
> ...

 

This suggests rpc.mountd is started with wrong command line parameters. The /usr/lib/systemd/system/rpc-mountd.service service file shipped with the gentoo ebuild reads custom parameters from /etc/conf.d/nfs, as did the /etc/init.d file for openrc. You may have something wrong in the OPTS_RPC_MOUNTD variable in /etc/conf.d/nfs.

Edit: oh, didn't see in time that ese002 already posted that. Sry for double posting.

----------

## Nitro_146

My rpc-mountd.service is identical to yours.

My /etc/conf.d/nfs is as follow (only uncommented lines).

```
# Optional services to include in default `/etc/init.d/nfs start`

# For NFSv4 users, you'll want to add "rpc.idmapd" here.

NFS_NEEDED_SERVICES="rpc.idmapd"

# Number of servers to be started up by default

OPTS_RPC_NFSD="8"

# Options to pass to rpc.mountd

# ex. OPTS_RPC_MOUNTD="-p 32767"

OPTS_RPC_MOUNTD="-V 4 -V 3 -N 2" # supporte la version 3 et 4, mais pas la version 2

# Options to pass to rpc.statd

# ex. OPTS_RPC_STATD="-p 32765 -o 32766"

OPTS_RPC_STATD=""

# Options to pass to rpc.idmapd

OPTS_RPC_IDMAPD=""

# Options to pass to rpc.gssd

OPTS_RPC_GSSD=""

# Options to pass to rpc.svcgssd

OPTS_RPC_SVCGSSD=""

# Options to pass to rpc.rquotad (requires sys-fs/quota)

OPTS_RPC_RQUOTAD=""

# Timeout (in seconds) for exportfs

EXPORTFS_TIMEOUT=80

```

If I set OPTS_RPC_MOUNTD to "" and restart nfsd

```
# systemctl stop nfsd

# systemctl start nfsd

# systemctl status rcp-mountd.service

rcp-mountd.service

   Loaded: not-found (Reason: No such file or directory)

   Active: inactive (dead)

# systemctl start rcp-mountd.service

Failed to issue method call: Unit rcp-mountd.service failed to load: No such file or directory.

# systemctl -l status rpc-mountd.service

rpc-mountd.service - NFS Mount Daemon

   Loaded: loaded (/usr/lib64/systemd/system/rpc-mountd.service; enabled)

   Active: failed (Result: exit-code) since mer. 2014-01-22 18:17:12 CET; 2h 20min ago

  Process: 3255 ExecStart=/usr/sbin/rpc.mountd $OPTS_RPC_MOUNTD (code=exited, status=1/FAILURE)

janv. 22 18:17:12 core-i5 systemd[1]: rpc-mountd.service: control process exited, code=exited status=1

janv. 22 18:17:12 core-i5 systemd[1]: Failed to start NFS Mount Daemon.

janv. 22 18:17:12 core-i5 systemd[1]: Unit rpc-mountd.service entered failed state.
```

----------

## Nitro_146

After a reboot it is working on the client side !   :Very Happy: 

What I dont understand, is that rcp-mountd is not working...

```
# systemctl status rcp-mountd.service

rcp-mountd.service

   Loaded: not-found (Reason: No such file or directory)

   Active: inactive (dead)
```

I think the problem is solved.

Thank all those answered this post and especially ese002 for his precious help !

----------

## yogi77

Sorry to capture this thread, I also have the described problem even if I'm on Openrc layout and not systemd...

Starting nfs with only nfsv4 enabled via OPTS_RPC_MOUNTD="-V 4 -N 3 -N 2" on my server gives me 

```
rpc.nfsd: Setting version failed: errno 22 (Invalid argument)
```

showmount -e server then gives me 

```
clnt_create: RPC: Program not registered
```

If I just give no OPTS_RPC_MOUNTD parameter, I still get the errno 22. However, I'm able to see my shares and connect to it (but it's nfs v3 as nfsstat tells me). So, it seems to be a problem related to nfsv4 and I don't have a clue where the error comes from...

Any help is appreciated!

----------

## Kompi

 *yogi77 wrote:*   

> If I just give no OPTS_RPC_MOUNTD parameter, I still get the errno 22. However, I'm able to see my shares and connect to it (but it's nfs v3 as nfsstat tells me). So, it seems to be a problem related to nfsv4 and I don't have a clue where the error comes from...

 

Do you have the module "nfsv4" loaded (or compiled in the kernel)?

How does you /etc/exports look like? For nfsv4 you need a slightly different configuration: For example, you need a virtual root and all exported filesystems mounted below that root AFAIK (see https://wiki.gentoo.org/wiki/NFSv4#.2Fetc.2Fexports)

----------

## yogi77

Thx for your quick reply!

nfsv4 is compiled into the kernel and /etc/exports is created acc. to the wiki (with fsid=0 for the root etc.)

rpcinfo -p gives me 

```

   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

    100024    1   udp  41273  status

    100024    1   tcp  43880  status

    100003    2   tcp   2049  nfs

    100003    3   tcp   2049  nfs

    100003    4   tcp   2049  nfs

    100227    2   tcp   2049  nfs_acl

    100227    3   tcp   2049  nfs_acl

    100003    2   udp   2049  nfs

    100003    3   udp   2049  nfs

    100003    4   udp   2049  nfs

    100227    2   udp   2049  nfs_acl

    100227    3   udp   2049  nfs_acl

    100021    1   udp  48252  nlockmgr

    100021    3   udp  48252  nlockmgr

    100021    4   udp  48252  nlockmgr

    100021    1   tcp  55333  nlockmgr

    100021    3   tcp  55333  nlockmgr

    100021    4   tcp  55333  nlockmgr

    100005    3   udp  50575  mountd

    100005    3   tcp  35339  mountd

```

rpcinfo -u server nfs 4 gives me

```
program 100003 version 4 ready and waiting
```

Only mountd service doesn't seem to be running for v4 and I don't have specific errors in the log...

----------

## Kompi

ah, ok  :Idea:  you were writing about the rpc.mountd daemon! (should have read more carefully). 

Okay, that's your problem: mountd does not understand -V 4, because it is not needed for NFSv4 and thus only supports up to v3. So if you want a pure NFSv4 setup, you don't need rpc.mountd at all. Same fore statd BTW.

----------

## yogi77

Ok, if mountd service isn't needed for v4 (but I've read a lot about options like -V 4 -N 3 N -2), I'm fine. 

But I get the same error and no access to the share, if I put for instance -N 3 -N 2 as mountd options (to get pure and only v4). That's why I'm assuming the relation to mountd (I don't know, if my error are related to mountd)...

----------

## rochus

I have the same problem that yogi77 has. mountd is automatically started when you start nfs, and -N 3 -N 2 is ignored. The server will still provide versions 2 and 3. Any way to fix this?

To summarize: NFSv4 is built into the kernel (3.10.25), nfs-utils v1.2.9 with nfsv4 and nfsv41 useflags, "standard" /etc/conf.d/nfs with -V 4 -N 3 -N 2 for mountd (or without -V 4, doesn't really matter):

the relevant fstab part:

```

/home/rochus/library   /export/library      none   bind 0 0

/home/rochus/media/audio /export/audio      none   bind 0 0

```

and exports file:

```

/export         net/24(ro,fsid=0,no_subtree_check)

/export/library      net/24(ro,no_subtree_check)

/export/audio      net/24(ro,no_subtree_check)

```

(of course with "net" something suitable)

some results:

```

root / # /etc/init.d/nfs start

 * Starting rpcbind ...                                                                                                                         [ ok ]

 * Starting NFS statd ...                                                                                                                       [ ok ]

 * Starting idmapd ...                                                                                                                          [ ok ]

 * Exporting NFS directories ...                                                                                                                [ ok ]

 * Starting NFS mountd ...                                                                                                                      [ ok ]

 * Starting NFS daemon ...

rpc.nfsd: Setting version failed: errno 22 (Invalid argument)                                                                                   [ ok ]

 * Starting NFS smnotify ...                                                                                                                    [ ok ]

root / # rpcinfo -u localhost nfs 

program 100003 version 2 ready and waiting

program 100003 version 3 ready and waiting

program 100003 version 4 ready and waiting

root / # exportfs -v

/export      net/24(ro,wdelay,root_squash,no_subtree_check,fsid=0,sec=sys,ro,secure,root_squash,no_all_squash)

/export/library   net/24(ro,wdelay,root_squash,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)

/export/audio   net/24(ro,wdelay,root_squash,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)

root / # showmount -e localhost

clnt_create: RPC: Program not registered

```

----------

## Kompi

looks like the shipped /etc/init.d/nfs script for openrc hard codes starting mountd in any case.

As said, AFAIK you do not need mountd for NFSv4 only and it probably won't like "-V 4 -N 3 -N 2" as it does not speak NFSv4. So probably - this is just a guess - nfsd sees mountd running and does not like not to provide v3/2.

So one thing you could try is to comment out starting mountd and see if that changes anything. It should be thoose lines in /etc/init.d/nfs, starting with at line 99:

```

        local ret=0

#        start_it mountd ${mountd} ${OPTS_RPC_MOUNTD}

        start_it daemon ${nfsd} ${OPTS_RPC_NFSD}

        [ -x "${smnotify}" ] && start_it smnotify ${smnotify} ${OPTS_SMNOTIFY}

        return ${ret}

}

stop() {

        local ret=0

#        ebegin "Stopping NFS mountd"

#        start-stop-daemon --stop --exec ${mountd}

#        eend $?

#        ret=$((ret + $?))

```

If that does not help: What are your OPTS_RPC_NFSD in /etc/conf.d/nfs? 

And does nfsd tell you any more if you add "--debug" to the OPTS_RPC_NFSD?

----------

## CrazyIvanMN

I believe I have been having a similar issue. (google brought me here).

I dug into the source code and found the error "rpc.nfsd: Setting version failed: errno 22 (Invalid argument)" 

nfsd on start up write a string to /proc/fs/nfsd/versions, specifically it should be setting the versions you tell it to support or not support.

for example.. if you have the options -V 4 -N 3 -N 2..   it will construct a string "+4 +4.1 -4.2 -3 -2"  (not necessarily in that order) and write it to /proc/fs/nfsd/versions.

Try it yourself you'll get an error if your kernel doesn't recognize nfsd 4.2.  

echo "+4 +4.1 -4.2 -3 -2" > /proc/fs/nfsd/versions

the message will be invalid input or some such.  (when you run the --debug option you'll see this message).

try it again with out 4.2 and it will succeed.

echo "+4 +4.1 -3 -2" > /proc/fs/nfsd/versions

(no error)

I hacked a patch that suppresses the error, and tried to start nfsd again.

```
diff -urN nfs-utils-1.2.9/support/include/nfs/nfs.h nfs-utils-1.2.9.new/support/include/nfs/nfs.h

--- nfs-utils-1.2.9/support/include/nfs/nfs.h   2013-11-05 14:41:27.000000000 -0600

+++ nfs-utils-1.2.9.new/support/include/nfs/nfs.h   2014-02-01 16:05:17.378726133 -0600

@@ -16,7 +16,7 @@

 #define NFSD_MAXVERS 4

 

 #define NFS4_MINMINOR 1

-#define NFS4_MAXMINOR 2

+#define NFS4_MAXMINOR 1

 #define NFS4_VERDEFAULT  0x1  /* minor verion 1 */

 

 struct nfs_fh_len {

```

The function that does this is sort of a noop if it fails.  You'll be stuck with I believe the kernel default support, instead of what you chose with the -V and -N flags.

To see for yourself the function is nfssvc_setvers in utils/nfsd/nfssvc.c

The patch above just restricts the building of the string to only do version 4.1 at most not go to 4.2.

I suspect there are some 'newer' kernels that do not have this problem.  I'm running a 3.6.11 kernel on a raspberry pi..

You could take the patch and add it to an overlay ebuild  and it works like a champ for both supressing the error about setting version numbers and allowing your -V and -N flags to work again.

----------

## yogi77

I also was at that point, I found some comments on the net about that string  and the missing 4.2 support (I think it was mentioned for kernel < 3.11 or such). Normally, I would expect, that the parameter given by OPTS_RPC_NFSD would be used to write the versions file. I changed the init script to control the output and the script worked like expected, but it seems to be overwritten (e.g. output is +4 -3 -2, but the file shows -4.2 +4.1 +4 +3 +2 or such).  I didn't look at the source so far, but your post explains my observation    :Smile:   I will try your patch, thx for this!

----------

