Just today I bought a new Verbatim external hard drive for my Linux machine. It’s a nice, small 160GB USB 2.0 hard drive. Getting it set up on ArchLinux with autofs was super simple. When you access the drive, it automatically mounts, and unmounts after a couple seconds of no activity. It works great. Here’s how to do it.
Setting up udev
The first order of business is getting udev to recognize the device and assign it the same device file everytime. I wanted it to show up as /dev/verbatim. First of all, I needed to see how it’s identified by Linux. So I plugged in the device, ran dmesg, and determined the USB address:
scsi 6:0:0:0: Direct-Access TOSHIBA MK1637GSX PQ: 0 ANSI: 2
Now I went into the sys filesystem to get the vendor and model information to help udev identify this device in the future. Using the USB address above — 6:0:0:0, I descended into the directory:
cd /sys/bus/scsi/devices/6:0:0:0
cat vendor
cat model
That gave me the values of “TOSHIBA” and “MK1637GSX”. Ok, so I could have gotten that from the dmesg output, but I wanted to make sure I was looking at the right fields.
Now I was ready to create my udev rule. I put the following in /etc/udev/rules.d/60-verbatim.rules:
BUS=="scsi", SYSFS{vendor}=="TOSHIBA", SYSFS{model}=="MK1637GSX", NAME="verbatim", GROUP="storage", MODE="0660"
Since my user wasn’t in the storage group I had to add him:
sudo gpasswd -a username storage
Alright! Now we have a stable device everytime we plug in the drive.
Setting up autofs
This part is simple. We just want the autofs daemon to pay attention every time the /dev/verbatim device shows up on the system, and handle auto-mounting and unmounting it as it is accessed.
I made sure the following line is in /etc/autofs/auto.master:
/media /etc/autofs/auto.media --timeout 2
Then I added the following line to /etc/autofs/auto.media (where 95 is the storage group id) to automount the device onto /media/verbatim:
verbatim -fstype=vfat,async,rw,gid=95,umask=002 :/dev/verbatim
Now, just restart the autofs daemon:
/etc/rc.d/autofs restart
All done!
That’s all it takes. Make sure the drive is unmounted, unplug it, plug it back in and take a look at your /media/verbatim directory. As you access it, you’ll see it’s automatically mounted (run mount). After a couple seconds of no activity, the drive will auto-unmount.
Was this helpful? Please let me know!