Below is what I have come up with so far, and it works. Really though it's
probably pretty easy to use the standardized /dev/disk/by-uuid symlinks
that udev creates on all Linux systems these days. Then all you have to do
is put in a mount statement for each partition using the known UUID's on
each partition/disk.
Anyway, I do have multiple mount statements here, and it seems to work
great, because it only tries to mount the disk/partition with the UUID that
was just plugged in. I would like to add functionality so that when a disk
is un-plugged, it automatically gets un-mounted. Again, I know this is
possible, but so far in experiments, I have not had luck in getting rules
to listen to ACTION=="remove" Any feedback is appreciated.
# Filename
# /etc//udev/rules.d/52-external.rules
SUBSYSTEM!="block", GOTO="disk_plugin"
# tell the kernel to listen for events like disks being plugged in
# we are assuming that the disk will be sdd or higher (lots of room for
improvement here) because we already have three disks in the machine.
# we know that the disk will only have one partition, so we have 1 hard
coded in here.
KERNEL=="sd[d-z]1", SYSFS{removable}=="0"
# use the vol_id or blkid command to create a temporary node id of the disk
ACTION=="add", IMPORT{program}="/lib/udev/vol_id --export $tempnode"
# we can probably use the blkid command here instead of vol_id command if
we wanted. syntax to get UUID is different, but result is same.
#IMPORT{program}="/sbin/blkid -o value -s UUID $tempnode"
# This step is more or less extra / optional but I wanted to do it.
# Consider using the standardized /dev/disk/by-uuid symlinks that are
created by default on all systems.
# create a symlink in /dev called external, and put the exact UUID of the
file system in there, so we will get: /dev/external/xxxx-xxxx-xxxx-xxxx
ENV{ID_FS_UUID}=="?*", SYMLINK+="external/$env{ID_FS_UUID}"
# downside here is that **any** new disk connected will get a symlink
created in /dev/external. See next section below.
# NOTE - the RUN statement below is where we specify if we want to mount
any disk connected or just ones with specific UUID's.
# if we want to mount any new disk connected by UUID just do this:
##RUN+="/bin/mount -o noatime,nodiratime /dev/external/$env{ID_FS_UUID}
/my-mount-point/"
# if we want to just mount specific disks that we know about, do this with
a new line and UUID for each disk:
# this is the method we are using because we know the UUID of the external
disks and we only want those mounted at
# our special purpose mount point called /my-mount-point
RUN+="/bin/mount -o noatime,nodiratime /dev/external/xxxx1 /my-mount-point/"
RUN+="/bin/mount -o noatime,nodiratime /dev/external/xxxx2 /my-mount-point/"
RUN+="/bin/mount -o noatime,nodiratime /dev/external/xxxx3 /my-mount-point/"
RUN+="/bin/mount -o noatime,nodiratime /dev/external/xxxx4 /my-mount-point/"
RUN+="/bin/mount -o noatime,nodiratime /dev/external/xxxx5 /my-mount-point/"
# Add more run statements with UUID's here
LABEL="disk_plugin"
#if we needed to mount each disk to a specific mount point, that would be
doable here as well. Just substitute /mymount-point for /mount-point1,
mount-point2, etc.
_______________________________________________
Discuss mailing list
[email protected]
https://lists.lopsa.org/cgi-bin/mailman/listinfo/discuss
This list provided by the League of Professional System Administrators
http://lopsa.org/