Implementation of auto-mount on embedded Linux under U-disk __linux

Source: Internet
Author: User
implementation of embedded Linux under U-disk automatic mounting One, method one

Because I am debugging the system is based on LSDK, so can not directly use the HotPlug in OpenWrt to complete this function. So the following methods are used.

The way I realized it was simple, the main is the cycle of reading file/proc/partitions file, when you insert, the file will have U disk information: "SDB1, SDB2" and so on, when the system detects this information, execute the command mount, the U disk mounted to the file system. You can open a thread in your application to read a file periodically/proc/partition

I implemented the method is very simple, mainly is the cycle read file/proc/partitions file, when you insert the disk, the file will have U disk information: "SDB1, SDB2," and so on,

When the system detects this information, it executes a command mount and mounts the U disk to the file system.

You can open a thread cycle in your application to read file/proc/partitions files, and to automatically mount your internship files.


This is simply a U-disk automatic mount, you can also use HotPlug to achieve the automatic Mount U disk.


Two, method two

Here's how to use Mdev on the Web:

Under Arm Embedded Linux, to let U disk automatically mount, you can use the Mdev way to achieve (Mdev is a busybox in a Udev management program of a compact version, it can achieve the automatic device node creation and equipment mount automatically), the following is the steps to achieve: 1, Confirm that BusyBox does the root file system with the following options selected: Linux system utilities-> [*] Mdev
[*] Support/etc/mdev.conf
[*]         Support command execution at Device Addition/removal 2, to determine HOTPLUG because it is a config_hotplug=y feature that utilizes the Linux kernel. 3, modify the root file system inside the Etc/init.d/rcs file, add the following: Mount-t tmpfs mdev/dev mount-t Sysfs Sysfs/sys Ir/dev/pts mount-t devpts devpts/dev/pts
        # Mdev For/dev          Echo/sbin/mdev >/proc/sys/kernel/hotplug         mdev-s          echo "***************starting mdev ..... [OK] "     4, add the corresponding to hot plug events, support U disk automatic mount:          Modify the etc/mdev.conf file in the root file system as follows:         sd[a-z][0-9]         0:0 666            @/etc/mdev/udisk_insert       & nbsp                            & nbsp            sd[a-z]                0 : 0 666            $/etc/mdev/udisk_remove         &NBsp    Note: @ Indicates that the following script is executed after inserting (creating the device node), and $ indicates that the following              is executed before unplugging (removing the device node)        Scripts.         5, adding corresponding script files:           the etc/mdev/in the root file system Udisk_insert file content:              #!/bin/sh              if [-d/sys/block/*/$MDEV]; Then               mkdir-p/media/$MDEV         &NB Sp     mount/dev/mdev/media/mdev/media/mdev-t vfat-o utf8=1           &nbs p;  fi              root file system Etc/mdev/udisk_remove file contents:      & nbsp       #!/bin/sh              umount-l/media/$MDEV   &NB Sp          rm-rf/media/$MDEV         At this point, you can implement automatic Plug and pull mount

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.