Archive

Mounting USB Devices

The method below is deprecated. Modern distros use udev.

By default udev will write unique symlinks for each USB Mass Storage device to

 /dev/disk/by-id/

I’m sure there are less messy solutions but this is how I did it. Assuming you have the same problem I did some time ago….

Problem:

  • You have >1 USB Mass Storage device.

  • You want to guarantee that each device always has a consistent mount point.
  • You cannot guarantee that they will always be inserted in the same order

(and thus show up at the same point on the SCSI chain).

Solution:

For each USB hotplug device you own:

  • Add a line in /etc/fstab which mounts /dev/<DEVICE NAME> under /mnt/<MOUNT

POINT>

  • Put a copy of the script below in /etc/hotplug/usb.
  • Add a line to /etc/hotplug/usb.usermap as to call the script when the disk

is plugged in.

 --- SAMPLE DEVICE HOTPLUG SCRIPT --  {{{  #!/bin/bash  1. Take a bit out of the second relevant line in /proc/scsi/scsi which will  1. uniquely identify the device.  Example: in
  1. Host: scsi2 Channel: 00 Id: 00 Lun: 01
  2. Vendor: USB2.0 Model: CompactFlashCard Rev:

  3. Type: Direct-Access ANSI SCSI revision: 02
  4. you might use “CompactFlashCard“.

DRIVETYPE=”ST316002″ DEVICENAME=”usbdisk” MOUNTPOINT=”/mnt/usbdisk”

  1. it takes a second or so for the drive to appear in /proc/scsi/scsi

sleep 1

  1. we want to find out where the drive is on the scsi bus

LOCATION=/bin/grep -B 1 $DRIVETYPE /proc/scsi/scsi | /bin/head -n 1 HOST=echo $LOCATION | cut -d ” ” -f 2 | sed -e ‘s/scsi/host/’ BUS=echo $LOCATION | cut -d ” ” -f 4 | sed -e ‘s/0/bus/’ TARGET=echo $LOCATION | cut -d ” ” -f 6 | sed -e ‘s/0/target/’ LUN=echo $LOCATION | cut -d ” ” -f 8 | sed -e ‘s/0/lun/’ echo -n “#!/bin/bash umount -f $MOUNTPOINT rm -f $DEVICENAME ” > $REMOVER chmod 755 $REMOVER rm -f $DEVICENAME ln -s /dev/scsi/$HOST/$BUS/$TARGET/$LUN/part1 $DEVICENAME

}}}

— END SAMPLE DEVICE HOTPLUG SCRIPT —

Leave a Reply