Automatic mounting of USB and SD cards under Linux

Source: Internet
Author: User

<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.