<span style= "font-family:arial, Helvetica, Sans-serif;" ><strong> Purpose: The USB stick and SD card can be mounted and unloaded automatically when it is inserted and removed in Linux system without the need of manual mount and Umount. </strong></span>
<span style= "font-family:arial, Helvetica, Sans-serif;" ><strong> Step:</strong></span>
<span style= "font-family:arial, Helvetica, Sans-serif;" ><span style= "color: #ff0000;" >1, add the following statement to the/etc/init.d/rcs </span></span>
Echo/sbin/mdev >/proc/sys/kernel/hotplug
2. Add in the mdev.conf file under/etc (if not, create a new one)
SD[A-Z][0-9] 0:0 666 @ (/etc/hotplug/insert.sh $MDEV $SUBSYSTEM) sd[a-z] 0:0 666 $ (/etc/hotplug/remove.sh $MDEV $SUBSYSTEM) ub[a-z][0-9] 0:0 666 @ (/etc/hotplug/insert.sh $MDEV $SUBSYSTEM) ub[a-z] 0:0 666 $ (/etc/hotplug/ remove.sh $MDEV $SUBSYSTEM) mmcblk[0-9]p[0-9] 0:0 666 @ (/etc/hotplug/insert.sh $MDEV $SUBSYSTEM) mmcblk[0-9] 0:0 666 $ (/etc/hotplug/remove.sh $MDEV $SUBSYSTEM)
3. Set up the HotPlug folder under/etc and create two files under the folder.
insert.sh:
If [-N "$"]; Then if [ -b/dev/$1], then if [!-d/media], then mkdir-p/media fi if [!-d/media/$1]; then mkdir-p/media/$1 fi mount/dev/$1/media/$1 if [$?-ne 0]; then rm-rf/media/$1 fi
fifi
remove.sh:
mounts=$ (Mount | grep $ | cut-d '-f3) umount $MOUNTSrm-rf $MOUNTS
In this way, when inserting a USB flash drive or SD card, the system will generate the media directory in the root directory and mount the USB flash drive or SD card in this directory. These steps can also be performed while the file system is being created, so that the Linux system will be able to carry this automatic Mount feature permanently.
Note: Using the above method requires that support Mdev be selected in the BusyBox configuration as shown below.
Automatic mounting of USB and SD cards under Linux