How to setup to mount/unmount USB drives automatically on SP7021

This document describes how to setup SP7021 (Plus1) platform (embedded Linux system) to mount and unmount USB drives automatically when you insert or remove an USB drive.

The only thing you need to do is to setup rules in configuration file /etc/mdev.conf of mdev, for asking Linux system to mount or unmount USB drives automatically. mdev is a light-weight alternative to udev for using in embedded Linux system in which Busybox is running. It handles the creation of device files in /dev and starts actions when certain events happen.

The configuration file (/etc/mdev.conf) of mdev lets you to control, setup permission and actions for the devices. The file has the format:

<device-name> <uid>:<gid> <permissions> [<@|$|*> <command>]

where <device-name> is device name. Regular expression is acceptable, <uid> is user id, <gid> is group id , <permissions> is octal file permission.

The special characters have the meaning:

@ Run after creating the device.
$ Run before removing the device.
* Run both after creating and before removing the device.

<command> is the commands you want to run when events happen.

For example:

sd[a-z][0-9] 0:0 777 @ mount /dev/$MDEV /mnt

The command is executed via the system() function. For your convenience, the shell environment variable $MDEV is set to the device name. For example, if the device sda0 is matched, $MDEV would be set to "sda0". The shell environment variable $ACTION is set to the events of hot-plug. The possible value is “add” or “remove”.

The following example rule asks mdev to mount an USB drive into /mnt when it is plugged in ($ACTION = “add”) and unmount the USB drive when it is removed ($ACTION != “add”).

sd[a-z][0-9] 0:0 777 * if [ $ACTION = "add" ]; then mkdir -p /mnt/$MDEV; mount /dev/$MDEV /mnt/$MDEV; else umount /mnt/$MDEV; rmdir /mnt/$MDEV; fi

Refer to attached file ‘mdev.conf’.