A.k.a disabling the device detection dialog box when you insert a usb or SD storage device
Whenever you insert a USB drive or a SD media card on the asus eeepc (version 701p, other models may differ but not by much), three things will happen:
- The storage device (usually in /dev/sd[a-z]) will be mounted as a file system in /media/sd[a-z]
- A prompt will appear asking you what you would like to do with the drive
- A tray icon is added to your task bar to help you unmount/unmount the device before you remove it.
The first feature is necessary, but you don’t really need 2 and 3, and it can be annoying if you’re not running a gui (in fact it will stop your eeepc from auto mounting storage devices if you don’t run a gui with a Qt system tray). This is a guide to configure your eeepc to automatically mount a USB or mmc-sd storage device with minimal overhead.
There have been other solutions to this problem, but they require downgrading to an older versions of the usb storage applet, which isn’t always a good thing to do considering that the applet does a lot more than just manage usb/sd card devices. This hack should work with newer versions of the eeepc with minimal modifications without downgrading any software.
First, create a shell script that mounts storage devices: mount.sh
#/bin/sh MOUNTDIR=/media if [ ! -d $MOUNTDIR/$1 ] then mkdir $MOUNTDIR/$1 fi mount /dev/$1 /media/$1
This will take the kernel name of the device as an argument and mount it in the /media directory
e.g. if the kernel name of the device was sdb, then this would mount /dev/sdb in the directory /media/sdb
invoke the script with
./mount.sh sdb
To manually mount a device. You won’t need to do this manually if you do this hack correctly.
A shell script to unmount devices when you unplug a usb drive: umount.sh
#unmount devices passed as an argument
if [ $# > 0 ]
then
umount /dev/$1
rmdir /media/$1
fi
#unmount all disconnected devices
grep "^/dev/sd[^ ]*[^0-9] " /etc/mtab | \
while read line
do
device=`echo $line | cut -d' ' -f1`
moutdir=`echo $line | cut -d' ' -f2`
if [ ! -e $device ]
then
umount $device
rmdir $mountdir
fi
done
You should run it to unmount your usb/media drive before you unplug your drive, do this with
./umount.sh sdb
if sdb was the name of the device mounted. You may have to check the entry in /etc/mtab to find out which device is mounted where.
Make sure these two scripts are executable:
chmod +x mount.sh chmod +x mount.sh
Now we need these scripts to run automatically when you connect and disconnect a usb or sd card drive. You can do this by modifying the udev rules.
Open the file /etc/udev/rules.d/50-xandros-udev.rules with your favorite text editor and find the line that looks like this:
BUS==”usb”, KERNEL==”sd[!0-9]“, NAME=”%k”, MODE=”0660″, GROUP=”floppy”, SYMLINK+=”disks/Removable/%k”, RUN+=”/usr/bin/usbstorageapplet zip %k”
You can find it under the usb, storage block. This tells udev to run /usr/bin/usbstorageapplet whenever you connect/disconnect a storage device which will mount and manage the device for you, unfortunately, it also makes a popup as well as a tray icon which we don’t want. So comment it out and add this:
BUS==”usb”, ACTION==”add”, KERNEL==”sd[!0-9]“, NAME=”%k”, MODE=”0660″, OPTIONS+=”last_line”, SYMLINK+=”disks/Removable/%k”, RUN+=”/path/to/umount.sh %k
then add another line under it:
BUS==”usb”, ACTION==”remove”, RUN+=”/path/to/umount.sh
Replace /path/to/ with the directory where you put the mount.sh and umount.sh scripts.
%k is the kernel name of the device that has been connected or disconnected. storage devices will match the pattern sd[!0-9]. Notice that our umount.sh script doesn’t take %k as an argument. That’s because once the device is removed, %k no longer holds a value so it can’t be passed to the script, so our script has to manually figure out what was removed. umount.sh reads the /etc/mtab file, which has a list of all the currently mounted devices to remove, and then checks if the device is still connected to your eeepc. A device is connected if it has a file in the /dev/ folder. You can see a lot of device connections/disconnections by running the dmesg command which is very useful for debugging.

