0

I have one network share that I mount in fstab. This is working fine.

Then, I have a second mount which binds on the folder from the first mount. Something like this:

//my-cifs-share/foo /mnt/foo-share cifs _netdev,dir_mode=0777 0 0
/mnt/foo-share /my/binded/folder none bind

Now, my problem is that apparently the second mount is executed before the first mount. Hence, the folder /my/binded/folder will empty after boot. When I then log in and execute mount -a just once, it gets created all fine.

So, is there any way to enforce the order or to make one mount depended on another one?

Thanks a lot!

//edit: As discussed in the comments there seems to be no real save path. Hence I decided to go with this: Leave fstab as it is above. Use crontab to run mount -a every 5 minutes. Seems to be good enough for now.

2

from man mount:

   -F, --fork
          (Used  in  conjunction  with -a.)  Fork off a new incarnation of
          mount for each device.  This will do  the  mounts  on  different
          devices  or  different  NFS  servers  in parallel.  This has the
          advantage that it is faster; also NFS timeouts go  in  parallel.
          A  disadvantage  is that the mounts are done in undefined order.
          Thus, you cannot use this option if you want to mount both  /usr
          and /usr/spool.

I think your distro uses this parameter as default on boot. Try to find and remove it. (I don't know redhat)

6
  • Hm, from what I found --fork is the default setting for fstab in general? I dont think I can change that, can I? – silent Nov 17 '16 at 8:57
  • 1st google hit: access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/… it seems to look a workaround And gnu+linux is opensource, you can change anything. – Ipor Sircer Nov 17 '16 at 9:02
  • I saw that before was hoping for an easier way. But I guess I will have to build a custom script then. Thanks anyway! – silent Nov 17 '16 at 9:25
  • Too bad: I tried it with an init.d script but apparently that one is still executed before my first mount is properly set up. To I still need to find another way. – silent Nov 17 '16 at 10:21
  • Then put a mount -a command after all initscripts finished their jobs. I'm using /etc/rc.local for it in Debian. Redhat should have an alternative for this. – Ipor Sircer Nov 17 '16 at 10:22
1

Avoid defining static bind mounts to directories that reside on filesystems that aren't "guaranteed" to exist. You're bound to run into multiple problems as time goes on, and this is only one example. Consider what happens when this CIFS mount inevitably drops during operation.

In most situations, this kind of scenario is better suited to a symbolic link than a bind mount. Symlinks handle their target dropping gracefully by becoming a "broken" link until the target is restored. Is there some reason you can't use a symlink for this?

3
  • Yes, I tried with symlinks before but cannot do this here: The link / bind is for a specific read-only SFTP user that is jailed to a certain subfolder structure. Hence I need the bind mount (from all I found at least) – silent Nov 17 '16 at 9:00
  • Yeah, symlinks can't escape your jail. Why not mount the CIFS share into your chroot directory directly? It will reduce dependence on other mounts, and there's nothing stopping you from mounting the same CIFS export in two places. You could change options and mount it read-only. – Spooler Nov 17 '16 at 9:16
  • Well, I simplified my question a bit ;-) The cifs share was just an example. I actually depend on a MapR (Hadoop distro) mount. But from the answers I guess I have to follow the way to build a script to be executed later in the boot process. – silent Nov 17 '16 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.