Monday, March 08, 2010

Automounting removable eSata drive on Centos 5.4

So my boss says, "I don't get it. When I have a gnome desktop open on the Centos box, my new eSata II removable mounts. But if I don't have a desktop open it doesn't get mounted when I reboot the box."

I ask The Google about it, and it tells me:

But try as I might, gnome-volume-manager fails to detect and mount the eSata drive. The idea of running gnome daemons when in fact I'm working with a server in which gnome is rarely utilized (except for when my boss runs a remote desktop) gives me pause. Hmmm, I think, wouldn't this be a good job for udev rules?

Running dmesg tells me that the device is present and that it's getting mounted as /dev/sdb1. (Or you can tail /var/log/messages) Running the following gives me a list of attributes that are visible to udev on my device.

# udevinfo -a -p $(udevinfo -q path -n /dev/sdb)

With this is see several attributes which can be used for matching when the udev rules are applied. I take the following two:

SYSFS{model}=="Hitachi HDT72101"

I want to mount the block device as /media/removable each time the device is plugged. I also want to unmount when the device is removed. The following worked for me.

ACTION=="add",SYSFS{rev}=="ST6O",SYSFS{model}=="Hitachi HDT72101",KERNEL=="sd?1",NAME="REMOVABLE", RUN+="/bin/mount /dev/REMOVABLE /media/removable"
ACTION=="remove",SYSFS{rev}=="ST6O",SYSFS{model}=="Hitachi HDT72101",RUN+="/bin/umount /media/removable"

For more information, refer to this helpful page.

No comments: