Export NFS path containing "-" (dash)

I'm in a bit of a pinch with NFS exports file.

Specifically, I can't find a way to export a directory containing "-" in the path name.

Manual (exports(5)) states:

Also, each line may have one or more specifications for default options 
after the path name, in the form of a dash ("-") followed by an option 
list. The option list is used for all subsequent exports on that line 
only.

It then states:

If an export name contains spaces it should be quoted using double quotes. 
You can also specify spaces or other unusual character in the export name 
using a backslash followed by the character code as three octal digits.

Unfortunately, that is not the case. Specifically, if the pathname contains "-", either verbatim, or with \055 or is enclosed in double quotes, it still refers to the name without "-"

Any ideas? I have a large number of directories, all of the form

  • /vol/buildsystem-s3c2440
  • /vol/buildsystem-tao3530

and I'd prefer to have them all available as nfs exports. Short of replacing the "-" with "_" everywhere in the scripts, can it be done with "-" ?


Based on this text, I assume you are on Linux?

If an export name contains spaces it should be quoted using double quotes. You can also specify spaces or other unusual character in the export name using a backslash followed by the character code as three octal digits.

There are two different NFS server implementations on Linux systems:

  • user NFS
  • kernel NFS

Please try running ps -ef | grep nfsd to see which one you have.

I think user NFS will appear as nfsd or unfsd, and kernel NFS will appear as [nfsd].
(Note how one has square brackets, but the other does not.)

With kernel NFS you should use double quotes or octal escapes, e.g.

"/path/to/mount-point" <options>

or

/path/to/mount\055point <options>

(Reference: nfs-utils-1.1.2, xgettok in support/nfs/xio.c)

With user NFS, spaces are not allowed in export names, but a minus sign (-) should not require escaping, e.g.

/path/to/mount-point <options>

(Reference: nfs-user-server-2.2beta47, filt_getc in auth_init.c)

If you can't get to the bottom of it, I would suggest switching from user NFS to kernel NFS so that you can use quoting or octal escapes.

On Debian and Ubuntu:

  • apt-get install kernel-nfs-server

On Red Hat and Fedora:

  • yum install nfs-utils

This is a bit of a hack but you can create bind mounts to each of the directories and export the bind mounts destinations. Something like:

mount -o bind /vol/buildsystem-s3c2440 /vol/buildsystems3c2440
mount -o bind /vol/buildsystem-tao3530 /vol/buildsystemtao3530

I'm not sure if having tons of mounts will slow down file access though.


Does escaping with backslash work?

  • /vol/buildsystem\-s3c2440
  • /vol/buildsystem\-tao3530

Have you tried simply escaping with \-. I am not an NFS expert - but its worth a try. It works in many other situations...


Ok, maybe another workaround. It's a bit troublesome, but why not creating a directory containing symbolic links to all the previous directories (a script or a while loop could be used for this). If the names of the symbolic links do not contain any dash, you should be able to export them. This way, as you wished, you would not need to modify the names of your real directories.

I am not sure if it would work, but it's probably worth giving it a shot, isn't it?