baslinux AT lists.ibiblio.org
Subject: Baslinux mailing list
List archive
- From: Christof Lange <cce.zizkov AT volny.cz>
- To: baslinux AT lists.ibiblio.org
- Subject: [BL] mounting USB storage device
- Date: Thu, 4 Jan 2007 12:59:22
David, Sindi, Steven, others,
I enclose my first attempt to make mounting USB storage devices
more user-friendly. The scripts below will probably be included
on the RAM disk I am going to create for one of Sindi's 2.4.31
kernels.
The quoted files are:
1. usbinit
2. usbdetect
3. usbmount
4. usbumount
5. issue
6. profile
I uploaded only these scripts at:
http://www.volny.cz/cce/linux/sb-usb/
I apologize for the length, but this is probably the best way to
give a report about my tests during the last days.
Christof
1. usbinit
==========
a script to load all the necessary modules.
------- usbinit ------------------------------------
#!/bin/sh
for i in scsi_mod sd_mod usbcore usb-uhci uhci usb-ohci usb-storage
do insmod $i; done
mount -t usbdevfs /proc/bus/usb /proc/bus/usb
----------------------------------------------------
2. usbdetect
============
contains commands that help to find the devices on the system,
after they have been plugged in.
------- usbdetect ----------------------------------
#!/bin/sh
# Screen output to detect USB devices that are attached at this
# moment or were attached before .
#detected=`grep 'Attached: Yes' /proc/scsi/*/*|
sed -e 's/.*\///;s/:.*//'`
#mounted=`mount|cut -d ' ' -f 1 |grep '\/dev\/sd.1'|
sed -e 's/\/dev\/sd//g'`
#echo $mounted
#echo $detected
#mount|grep '\/dev\/sd.1'
cat /proc/scsi/*/*|more
----------------------------------------------------
3. usbmount
===========
is an ugly script (will anybody on the list be able to simplify it
or make it more compact?) to mount the attached storage devices.
It follows the approach from usbdetect and scans /proc/scsi. Then
it mounts the devices from /dev/sda1, /dev/sda2, etc. to /USB-A,
/USB-B, /USB-C, etc. This allows to mount up to four different
devices, while user does not have to care for the locations.
Screen output is minimized. When a device is plugged in, however,
the screen output is still enormous.
There is one big problem with this script. As the system puts every
new device that is plugged into the computer on a new /dev/sdX1
address, you can only use up four memory sticks (when you use
the same memory stick for a second time, it seems to be recognized
and goes to its forner location). After unplugging a device, it stays
in /proc/scsi, only gets the desciption "Attached: No". The address
cannot be used by the next device.
A hardly satisfying work around would be to add more devices (I got
to work /dev/sde1 four the fifth memory stick, but /dev/sdf1 to
/dev/sdh1 seemed not to be supported by the kernel). In that case
you need only to add theses addresses to the scripts usbmount and
usbumount and you will be able to mount more than four different
devices. Has anybody an idea how this problem could be solved
basically?
------- usbmount -----------------------------------
#!/bin/sh
# Unmounts and deletes mount points of all devices which are no
longer attached.
# Then mounts all devices which are attached and have not been
mounted yet.
detected=`grep 'Attached: Yes' /proc/scsi/*/*|
sed -e 's/.*\///;s/:.*//'`
mounted=`mount|cut -d ' ' -f 1 |grep '\/dev\/sd.1'|
sed -e 's/\/dev\/sd//g'`
#echo $mounted
#echo $detected
echo $detected | grep -v '0' >/dev/null && echo $mounted |
grep 'a' >/dev/null && umount /dev/sda1 && rmdir /USB-A
echo $detected | grep -v '1' >/dev/null && echo $mounted |
grep 'b' >/dev/null && umount /dev/sdb1 && rmdir /USB-B
echo $detected | grep -v '2' >/dev/null && echo $mounted |
grep 'c' >/dev/null && umount /dev/sdc1 && rmdir /USB-C
echo $detected | grep -v '3' >/dev/null && echo $mounted |
grep 'd' >/dev/null && umount /dev/sdd1 && rmdir /USB-D
echo $detected | grep '0' >/dev/null && echo $mounted | grep -v
'a' >/dev/null && mkdir /USB-A && mount /dev/sda1 /USB-A
echo $detected | grep '1' >/dev/null && echo $mounted | grep -v
'b' >/dev/null && mkdir /USB-B && mount /dev/sdb1 /USB-B
echo $detected | grep '2' >/dev/null && echo $mounted | grep -v
'c' >/dev/null && mkdir /USB-C && mount /dev/sdc1 /USB-C
echo $detected | grep '3' >/dev/null && echo $mounted | grep -v
'd' >/dev/null && mkdir /USB-D && mount /dev/sdd1 /USB-D
mount|grep '\/dev\/sd.1'
----------------------------------------------------
4. usbumount
============
is a simple script to unmount the USB devices. It deletes the mount
points as well. So in Midnight commander the user can see at first
glance which devices (also floppy and CD-ROM) are available.
---------- usbumount -------------------------------
#!/bin/sh
# Unmounts and deletes mount points of one or all USB devices
attached.
# Specify one USB device with letters A, B, C, etc.
mounted=`mount|cut -d ' ' -f 1 |grep '\/dev\/sd.1'|
sed -e 's/\/dev\/sd//g'`
case $1 in
A|a) echo "Unmounting USB storage device on /USB-A"
echo $mounted | grep 'a' >/dev/null && umount
/dev/sda1 && rmdir /USB-A >/dev/null
;;
B|b) echo "Unmounting USB storage device on /USB-B"
echo $mounted | grep 'b' >/dev/null && umount
/dev/sdb1 && rmdir /USB-B >/dev/null
;;
C|c) echo "Unmounting USB storage device on /USB-C"
echo $mounted | grep 'c' >/dev/null && umount
/dev/sdc1 && rmdir /USB-C >/dev/null
;;
D|d) echo "Unmounting USB storage device on /USB-D"
echo $mounted | grep 'd' >/dev/null && umount
/dev/sdd1 && rmdir /USB-D >/dev/null
;;
*) echo "Unmounting all USB storage devices"
echo $mounted | grep 'a' >/dev/null && umount
/dev/sda1 && rmdir /USB-A >/dev/null
echo $mounted | grep 'b' >/dev/null && umount
/dev/sdb1 && rmdir /USB-B >/dev/null
echo $mounted | grep 'c' >/dev/null && umount
/dev/sdc1 && rmdir /USB-C >/dev/null
echo $mounted | grep 'd' >/dev/null && umount
/dev/sdd1 && rmdir /USB-D >/dev/null
;;
esac
----------------------------------------------------
5. issue
========
explains the future RAM disk to new users.
---------- /etc/issue ------------------------------
Welcome to USB storage support in BasicLinux
This RAM disk is based on BasicLinux 2.1 (compatible with Slackware
7.1) and can be run with a USB-capable 2.4.31 kernel. Its main
purpose is to provide support for USB storage devices and CD burner.
Users will be able to copy the contents of their USB storage devices
from or to hard disk partitions or save them to CD-ROM.
Commands
~~~~~~~~
usbinit initializes USB storages (necessary for u: and :u)
mc file manager
edit edit a file
zgv browse graphic files (not yet included)
a: and :a mount and unmount floppy on /A
c: and :c mount and unmount 1st hard disk partion on /C
d: and :d mount and unmount 2nd hard disk partion on /D
e: and :e mount and unmount 3rd hard disk partion on /E
r: and :r mount and unmount CD-ROM on /R
u: mount all attached USB devices on /USB-A, /USB-B etc.
:u [X] unmount device on /USB-X or all attached USB devices
cdhelp display commands for CD burning (not yet included)
To start BasicLinux, enter root at the login prompt.
----------------------------------------------------
6. profile
==========
runs at login time and defines aliases to mount and unmount devices.
------ /root/.profile ------------------------------
alias a:='mkdir /A ; mount /dev/fd0 /A'
alias c:='mkdir /C ; mount /dev/hda1 /C'
alias d:='mkdir /D ; mount /dev/hda2 /D'
alias e:='mkdir /E ; mount /dev/hda3 /E'
alias r:='mkdir /R ; mount /dev/hdc /R'
alias u:='usbmount'
alias :a='umount /A;rmdir /A'
alias :c='umount /C;rmdir /C'
alias :d='umount /D;rmdir /D'
alias :e='umount /E;rmdir /E'
alias :r='umount /R;rmdir /R'
alias :u='usbumount '
----------------------------------------------------
________________________________________________________________
Ceskobratrska cirkev evangelicka - Betlemska kaple na Zizkove
Prokopova 4/216, 130 00 Praha 3, Czech Republic
Tel. (+420) 222 78 06 73 / 222 78 20 02 / 603 18 87 53
http://www.volny.cz/cce.zizkov
- [BL] mounting USB storage device, Christof Lange, 01/04/2007
Archive powered by MHonArc 2.6.24.