Disable automount for specific USB drives
Q Is there any way that I can disable automount for a specified external USB drive on Ubuntu 9.04? I'd still like all the other USB drives on the system to mount normally.
A This used to be done by creating udev rules to give that particular device a specific name and then telling your volume manager or automounter to ignore it. Now, however, it's a single-stage process of telling HAL to ignore the device. This means a device node will still be created by udev, but HAL won't do anything with this information. This has the advantage of being a single solution that works with all systems, whichever volume manager they use. However, if you thought udev rules files were a pain, you've never tried to edit HAL policy files. The files are kept in /etc/hal/fdi/policy and you can either add to the existing preferences.fdi file or create a separate file for this task.
The easiest way to differentiate your drive from all others is to use its UUID (Universally Unique Identifier). If you've looked in an Ubuntu /etc/fstab file, you'll have seen these before. First, we have to find the HAL details for your drive, so plug it in and see which device name it receives - you can run the mount command in a terminal and look at the last line. If you have a single internal drive, it'll probably be /dev/sdb1. Now run this command:
hal-find-by-property --key block.device --string /dev/sdb1
This returns the HAL identifiers of all devices containing the key block.device with the value /dev/sdb1. There really should be only one, something like /org/freedesktop/Hal/devices/volume_uuid_623C_6219_0. Now plug this identifier into lshal, which will show all the HAL properties of the device. The one we're interested in is volume.uuid, so run the following:
lshal --show /org/freedesktop/Hal/devices/volume_uuid_623C_6219_0 | grep volume.uuid
and put the resulting value into an FDI file in /etc/hal/fdi/policy:
<?xml version="1.0" encoding="UTF-8"?>
<match key="volume.uuid" string="623C_6219">
<merge key="volume.ignore" type="bool">true</merge>
If you're adding to an existing preferences.fdi file, just use the part from <device> to </device> and put it before </deviceinfo>. This looks for a match on volume.uuid against the string given. If it's positive, it adds (merges) a new key of volume.ignore, set to true. In plain English that equates to: if the UUID has the value you want to bypass, ignore this volume so that nothing from it is then passed on to the volume manager. You need to restart HAL to have it pick up the new configuration. You could do this from the Service Manager, but since you already have the terminal open, just type:
sudo /etc/init.d/hal restart
Hopefully, when DeviceKit replaces HAL, it will make this whole process far less cryptic.
Follow us on Identi.ca or Twitter