#StackBounty: #usb #udev #automounting #busybox How to mount usb drive in udev rule?

Bounty: 50

I setup a rule in udev to run a script in background to automount the usb drive. It managed to run the script fine, but the mounting is failed for some reason.

RULE:

ACTION=="add", KERNEL=="sd[a-z]*", RUN+="/etc/mntUsbChk.sh &"

In this script:

#!/bin/sh

sleep 2

mkdir /mnt/usb

foundUsb=false

if [ -e /dev/sda1 ]; then
 mount /dev/sda1 /mnt/usb
 $foundUsb=true
fi

if [ -e /dev/sdb1 ]; then
  mount /dev/sdb1 /mnt/usb
  $foundUsb=true
fi

if [ -e /dev/sdc1 ]; then
  mount /dev/sdc1 /mnt/usb
  $foundUsb=true
fi

if [ $foundUsb -eq false ]; then
 exit
fi

echo "USB MOUNTED"

[ 1610.868626] FAT-fs (sdb1): Volume was not properly unmounted. Some
data may be corrupt. Please run fsck.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.