Linux auto mount daemon (flashd)

Modern linux Window Managers (KDE/Gnome) are equipped with utilities which allow their user base to access external storage devices (flash drive/usb stick/external HD) with a single mouse click. The trade-off for acquiring such functionality is installing the Window Manager and most (if not all) its libraries and dependency packages.
Unfortunately such solution is not convenient for users who want to take advantage of the entire linux potential with a lean build or those who are not interested by definition on running such heavy graphical solutions (i.e Home Theater PC).

flashd aim to provide this functionality without the requirement of a window manager. It is coded to operate under the Slackware linux structure and therefore can easily be modified to operate under other linux distributions.
It consist of two bash files, flashd (the daemon) and rc.flashd (the daemon control file).
NOTE: As of 08/07/2011 flashd (v1.5) will automatically mount detected NTFS partitions using the ntfs-3g driver should it be installed on the system it's running.

How To Install
To install the daemon on Slackware, copy the first file (preferably) in a binary path on your system like /usr/local/bin/ and the second in /etc/rc.d/. Make sure both have the right permissions by issuing the following commands:
chmod 755 /usr/local/bin/flashd
chmod 755 /etc/rc.d/rc.flashd

Then edit /etc/rc.d/rc.local and append at the end of the file the following piece of code:
if [ -x /etc/rc.d/rc.flashd ] ; then
. /etc/rc.d/rc.flashd start
fi

HINT: SlaXBMC users add sh /etc/rc.d/rc.flashd "start" & before the su - root -c startx & line in your rc.local to activate the script at boot time.

How To Configure
If you choose to copy flashd into another binary path location i.e /usr/bin please make sure to edit the FLASHD_PATH variable in /etc/rc.d/rc.flashd control file accordingly so it points to the correct directory structure under which the daemon binary is located.

In flashd binary the following two variables can be used to configure further the daemons behavior:
EXCLUDE_HD Must contain a ";" separated list of all fixed device drives on the system i.e "sda;sdb" etc.
EXCLUDE_MOUNT_PATH Must contain a ";" separated list of protected directories under /mnt i.e "cdrom;dvd;tmp"

What To Expect
When a USB flash and/or external drive is plugged in the daemon will attempt to read that device partition tables and their names (labels). If a labeled partition table is identified it will create a directory under /mnt using the label name and mount that partition, otherwise the partitions table name is being used.
When the user unplug the device after umount or just pull it off its USB slot (it's not recommended but relatively safe if there is no data read/write taking place at the time on the device) the daemon will umount the unplugged partition and delete the created folders under /mnt.

No comments: