Auto-mounting the pendrive or the flash cards
Translation of the original in Catalan. Read it in: CatalàCastellano

If you work with udev and you install the autofs package, with four tweaks to the kernel and four lines of configuration you can make it so that when you plug in a pendrive with linux it mounts and unmounts automatically. In fact, this solution is explained in a thousand different ways in a whole lot of howtos and other similar things. There are people who reach brutal levels of sophistication. But after looking 'long and hard' at all this information I have decided not to complicate things and set up something really simple that lets me get on with the job with pendrives and flash cards; which is what I use most on the laptop.
Well then to start with what we will do is that when it is detected that a device of type /dev/sdX1 has been connected (where X=a,b,c,d,etc) it mounts automatically. As you know the virtual file system udev automatically generates the files that represent the devices and also generates some events that can be captured. If you want to monitor these events you can run the udevmonitor command and you can try plugging and unplugging, for example, a pendrive and you will see how the events I mention are generated.
Well then the first thing I have done is to make an automatic symlink be generated when a partition is detected on one of these devices I mentioned, in order for this to happen we only have to modify the file: /etc/udev/rules.d/00.rules to get the functionality I mentioned we only have to add this:
BUS="usb", KERNEL="sd?1", NAME="%k", SYMLINK="pendrive"
As I was saying if you search a bit you can improve it a great deal by making, for example, that the dynamic link (symlink) is only generated if the device is of such and such brand, model I do not know which, or that it is of the usb mass-storage type, etc. Well then, once we already have the dynamic link now what we will do is that when we try to access this device it mounts automatically and that if after X's seconds the device has not been used it unmounts by itself.
As I mention we will do it with autofs, to configure the daemon we can do it in the file /etc/conf.d/autofs the only thing I have touched in the daemon configuration file is the timeout so that it unmounts 2s after not being used:
...
# additional options for automount, ie. timeout
daemonoptions = '--timeout 2'
...
Before launching the daemon, I have modified the following of the configuration files found in /etc/autofs in the file auto.master I have added this:
/var/autofs/removable /etc/autofs/auto.removable
Afterwards I have created the file auto.removable:
pendrive -sync,dirsync,fstype=vfat,uid=1000,gid=100,umask=002 :/dev/pendrive
With this we manage that when an attempt is made to access the /dev/pendrive resource it mounts at /var/autofs/removable/pendrive and then in order to keep the directory structure of a lifetime what I do is create a link at /mnt/pendrive that points to /var/autofs/removable/pendrive:
ln -s /var/autofs/removable/pendrive /mnt/pendrive
Now if we go to /mnt/pendrive (cd /mnt/pendrive) and do an ls we will see the content of the device, maybe the first ls you do does not work give it a few seconds so that the whole thing can react, it takes me about 3 or 4s between plugging in the device and being able to access it. If when you finish using the pendrive you leave the directory you will see that when you do a df -a it is no longer mounted.
As I was saying there are thousands of howtos much better than the one I have just done, but with this one I have already got out of the difficulty. Some howto's you can look at: