LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Reliably mount different external drives to the same points? (https://www.linuxquestions.org/questions/linux-general-1/reliably-mount-different-external-drives-to-the-same-points-4175422158/)

j_h 08-15-2012 03:50 AM

Reliably mount different external drives to the same points?
 
I'm maintaining a system which utilises external drives. Previously the system has been set up to mount these using device names (/dev/sdxY) in fstab. This appeared to work fine for a while, but today I saw it detect an external drive as /dev/sdaY, which messed everything up.

Relevant info:
-various scripts expect the two drives to be at specific mount points
-the drives are all the same make and filesystem type, though a few different sizes
-up to two drives can be connected at any one time, so I don't believe I can add a single udev rule to always mount drives of this type to a particular point
-there is a large pool of drives and more may be purchased at any time, so I can't know all the UUIDs to add a rule for each drive

How can I guarantee that any one of these drives will always get mounted to one of the two mount points I specify?

Thanks in advance for any ideas!

Wim Sturkenboom 08-15-2012 05:49 AM

You can use labels in fstab; never tried it though.

j_h 08-15-2012 06:00 AM

Thanks for your response, but as mentioned in the OP, there's a large pool of possible drives and new ones are added ad-hoc (without going through me), so I wouldn't be able to set the label manually for every drive. Unless there's a way to programatically do it? Also, can you set labels on NTFS drives?

I'd still need to solve the problem of mounting two distinct drives of the same fstype to separate mount points anyway.

I think what I really need is a way to set udev rules that copes with two 'identical' drives, without relying on me knowing the serial numbers. Does such a thing exist? S:

TobiSGD 08-15-2012 06:05 AM

That is impossible, as far as I see. The udev rule can't know the serial numbers (or whatever else is used to recognize the disks), so it can't reliably mount unknown devices to one specific mountpoint when several possibilities for that exist.
The only solution I see is to change your workflow, so that new drives have to be approved by you so that you can change the udev rules accordingly.

j_h 08-15-2012 07:01 AM

Hmm, that's a shame. Thanks for your help, anyway.

j_h 08-15-2012 07:40 AM

Had another thought: while the drives are interchangeable, they will always be plugged into the same two ports. 'lsscsi' gives me 1:0:0:0 and 2:0:0:0 as the (addresses?) for the two drives. Is there any way I can use this information to specify that anything connected to the first port gets mounted to one point, and anything connected to the second gets mounted to another?

jschiwal 08-15-2012 08:34 AM

I don't see why the mount command the udev rule runs couldn't be "mount <mountpoint1> || mount <mountpoint2>". I haven't tried this however.
Code:

SUBSYSTEMS=="scsi", KERNEL=="sd[a-h]1",
RUN+="/bin/mount /dev/%k /media/removable || /bin/mount /dev/%k /media/removable2"

If you can pass ID_PATH to a script, the script can use variable expansion to add a "1" or "2" to the mountpoint variable.

Have separate rules depending on the ID_PATH value.

schneidz 08-15-2012 08:47 AM

i think this is what uuid was created for ?

j_h 08-15-2012 09:03 AM

Ha, wonderful! ID_PATH seems to be exactly what I need. Many thanks

j_h 08-16-2012 04:32 AM

Just to follow up on this in case anyone else comes across a similar issue (for instance, this would allow replacing external devices attached to a particular port and get it to mount to the same place as the old one without needing to update udev):

udev rule with ID_PATH in didn't seem to work (when I ran udevadm info -a -p /path, ID_PATH was not in the list of attributes), but the suggestion put me on the right path (no pun intended). Using the info from the 'looking at parent device' section, I managed to get the following rule to work:

Code:

SUBSYSTEM=="block", KERNEL=="sd*1", KERNELS=="1:0:0:0", SYMLINK+="<label_1>"
SUBSYSTEM=="block", KERNEL=="sd*1", KERNELS=="2:0:0:0", SYMLINK+="<label_2>"

and then modify the entries in my fstab to

Code:

/dev/<label_1>  /mnt/<mountpoint_1>  <attributes>
/dev/<label_2>  /mnt/<mountpoint_2>    <attributes>

Thanks to jschiwal for the helpful pointer.

TobiSGD 08-16-2012 05:23 AM

Thanks for posting back your solution. If you feel that you have solved your problem please mark this thread as solved using the thread tools at the top of the thread.


All times are GMT -5. The time now is 09:40 PM.