8

Perhaps this is an odd request, but it's the opposite of the question detailed at:

Is it possible to view the contents of an underlying NFS mount without unmounting the NFS content?

I have an arrangement where Linux servers at multiple remote sites mount an NFS share from a central server (all CentOS 5.x). Think: /opt/software or something similar.

If all is well, the client systems mount the NFS export from the main server and run without incident. The data contained within the share does not change frequently (perhaps weekly).

I'm concerned about the situation where there's a loss of connectivity to the main NFS server (NFS server outage, fiber-cut, etc.). Due to the fact the the shared data does not change often, I'd like for these systems to be able to run standalone if they lose the NFS mount.

Say the mount goes away, I'd like to use the local files sitting in /opt/software underneath the NFS mount at the same location. Additionally, I'd keep a daily sync of those files.

The NFS mount is read/write because changes to the mounted volume need to be possible from any of the client sites.

Is this possible? How do I access (or overwrite) the files in the underlying directory? Would there potentially be timeout issues? Are there any mount options/tips that could help with this?

3 Answers 3

16
mount -o bind / /mnt

When you look at /mnt/opt/software you will find the files (if any) which are underneath the mount in /opt/software.

4
  • But that would mount all of the root filesystem under /mnt. Hmm...
    – ewwhite
    May 19, 2011 at 21:24
  • 1
    So? What harm is it going to do? It just lets you synchronize the files you want. You can even put it in /private/root where /private is 700 root so no-one else can get at those files, not that it would do any harm if they could since they have exactly the same permissions. It seems basically like an exact answer to your question. Now if your question is how to recover once the NFS server goes away, that is entirely different, and probably involves force unmount. That will invalidate and thus break half of your processes forcing a reboot anyway. May 20, 2011 at 0:16
  • This was close, but I decided to just mount the directory I needed access to with the bind parameter to another location on the filesystem.
    – ewwhite
    May 27, 2011 at 13:04
  • Actually this is very useful in a specific case and I wish I had know about this option a long time ago. I just ran into this situation again. Basically I had a /usr directory that was tied to the root filesystem and wanted to move it to its own filesystem to recover space on root. So after making usr and migrating the data there and rebooting to mount the new usr, how do you easily remove the old /usr data? One way is to use single user mode and hope nothing is using files there. Another way is to use this bind trick and remove the data directory from an alternate path.
    – deltaray
    Feb 8, 2015 at 18:20
8

This is possible by using the mount --bind option.

Since Linux 2.4.0 it is possible to remount part of the file hierarchy somewhere else. The call is
   mount --bind olddir newdir
After this call the same contents is accessible in two places.

So I was able to mount --bind /opt/software /foo

And then apply the NFS mount over /opt/software, retaining the ability to see the underlying files at /foo.

3

What you might need, since the files are relatively static, is rsync. Unless multiple remote clients have ability to change files. If data is essentially read-only, why not just rsync a couple of times a day via some cron-like job, on each machine. Again, I may be missing the point, but if data on NFS is basically read-only-like, this might do it.

3
  • Rsync would traditionally make sense, but there's a chance that files would be modified at any given site. If I were mounting read-only, rsync would be a better choice. Unless you know of a two-way synchronization solution...
    – ewwhite
    May 20, 2011 at 19:26
  • One thing you can do with rsync is setup a cron job that checks timestamps on your files on each machine, and perhaps do it every 5min. As soon as an update is noticed push the files to nfs, and ad the same time perhaps create a trigger file that every other machines checks at a fixed period. As soon as they see this trigger they all run rsync to get most updated files from NFS.
    – slashdot
    May 22, 2011 at 3:41
  • I may try Unison as an approach to solving this.
    – ewwhite
    May 23, 2011 at 16:47

You must log in to answer this question.

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