Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In my situation I need to ensure one particular filesystem is mounted before a few subsequent filesystems should be. In this case, for example, I want to mount a USB disk before bind mounting some other directories on it.

I am comfortable enough to write an init script to accomplish this, however before doing that I would like to know if there might be a more prudent or common solution to this problem--I'm skeptical that this problem is a rare one.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Do you want it only to happen at system start up? If not you could maybe do something with automount, along the lines of an executable map which checks to see if the USB device is available and if so makes the dependent locations available for mounting.

Something like:

auto.magic:

#/bin/sh
if [[ -z /media/usb ]] then
    echo "films    /media/usb/films"
    echo "photos   /media/usb/photos"
fi

auto.master:

/magic auto.magic

You'll need to do a service autofs (re)start.

Then when you do ls /magic/films, automount will call your script and mount the film share if /media/usb is available.

share|improve this answer
add comment

What distribution are you using?

I'm quite sure that either the init scripts mount filesystems one by one top to bottom in /etc/fstab or look for dependencies.

Either way I never had any problems with mountpoints residing in other mount points and use them extensively, together with mount --bind.

On the other hand, when the mount point doesn't exist, mount will print an error and init scripts go on (as long as the mount point is set as non critical by setting 0 in last column in /etc/fstab)

share|improve this answer
    
You bring a good point, and if the USB disk is for some reason unavailable, then the USB disk's directories that I'm binding are probably unreachable since the local mount point should be empty. I may need to re-evaluate my situation. –  andyortlieb Jul 18 '11 at 17:37
    
I don't believe there's a way to imply dependencies in /etc/fstab by the way. It just runs top to bottom, I assume one at a time. I am using Debian 5 (lenny). –  andyortlieb Jul 18 '11 at 17:38
    
there's no way to set a dependency in /etc/fstab, but you're mounting all of them in a single tree, so just by looking at a path you can assume dependencies. Still, can't think of a situation in which top to bottom processing won't be good enough. –  Hubert Kario Jul 18 '11 at 21:57
    
According to man 5 fstab zero in last field only disables running fsck on partition. There is nothing about partition being critical/non-critical. –  AlexD Jul 19 '11 at 3:39
    
I speak from experience, not quote man pages. If fsck can't be run on partition it will force you to recovery prompt, otherwise it will continue as if nothing happened effectively marking partition "system critical" or "system non-critical". –  Hubert Kario Jul 19 '11 at 7:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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