mounted nfs share, cannot access symlinked files

Paul Smith paul at mad-scientist.net
Sat Oct 9 15:18:58 UTC 2021


On Sat, 2021-10-09 at 07:55 +0200, Bo Berglund wrote:
> It seemed natural for me that the sharing subsystem (nfs or samba)
> would handle this transparently to the user.

It's one way it could work.  But it's not how it works.  A symlink is a
special type of file and when you NFS mount you get the filesystem "as-
is" including all files "as-is".

You don't get some interpretation of the filesystem where if you look
at the contents on the server you see it one way and when you look at
the contents on the client you see something different.

> But what you infer is that instead of presenting the actual *content*
> of the file the nfs sharing presents the verbatim link instead....

Actually we are not inferring anything; you were inferring... how
symlinks might work :) :).  We could be implying, but in fact we're not
even doing that, we're just saying outright how they work.

> Obviously this will not work across a network since the file's
> address (the link) has no meaning on the client machine.

You can use symlinks "across a network" if (a) the target of the link
is a relative, not absolute, path, and (b) they link to files on the
same exported partition.

Then the lookup will find the same thing on the server as on the
client.

But you can't export files from your server that aren't actually on the
exported partition, just by making an exported symlink to them.

> The only way out would be to share the bin dir where all the files
> actually live, but then it would not be possible to have a
> *selection* of some but not all files available to the share user
> system.

Others have mentioned hard links which could be a solution but just be
aware: you can't create hard links across disk partitions.

So if you have two partitions for example: "/" and "/home".  You can
make hardlinks in the "/" partition to other files in the "/"
partition, and you can make hardlinks in the "/home" partition to other
files in the "/home" partition, but you cannot create hardlinks between
the "/" and "/home" partitions.

In your case, where all the files to be shared live inside your home
directory which is on a single disk partition (presumably), this isn't
an issue.

However there is one very big difference to understand between
hardlinks and symlinks.  Unlike a symlink, a hardlink is another name
pointing to the same location on the disk.  A hardlink is NOT updated
when the origin file is deleted and recreated; the hardlink will still
point to the same (old) location on the disk.

In other words if you have a symlink like this:

    ~/www/foo -> ~/bin/foo

and you update ~/bin/foo by deleting it and recreating it:

    rm ~/bin/foo
    gcc -o ~/bin/foo foo.o

Now the ~/www/foo points to the new ~/bin/foo.

But if you have a hard link from ~/www/foo to ~/bin/foo and you delete
~/bin/foo and update it then ~/www/foo is NOT CHANGED, it still points
to the old version of the file.  You have to recreate the hardlink to
update it.

My advice is: create a shell script or a makefile that "builds" your
shared space by copying the files into it that you want to share, and
don't worry about either symlinks or hardlinks.





More information about the ubuntu-users mailing list