[ltp] External 1394 drive on Mandrake 9.1 (was Reserving disk drive identities?)

Richard Neill linux-thinkpad@linux-thinkpad.org
Fri, 27 Jun 2003 03:07:26 +0100


This is a multi-part message in MIME format.
--------------060309070705060202060304
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Dear All,

Thanks for your help earlier with this thread. I've finally got it 
working (and attached a short shell script/ugly hack).

There are two problems it solves:

1)The ohci1394/ieee1394/sbp2 modules need removing and re-inserting in 
order to create the correct entry in /dev

2)I have 2 different removable external disks (a firewire and a 
microdrive) - and depending on conditions, either could be /dev/sda or sdb.
The fix is to identify which is which and create a symlink to the right 
one as /dev/1394da1 .
This means that /etc/fstab can always know that /mount/1394 is 
associated with /dev/1394da1.

Regards

Richard


P.S. If there's a better way to do this, please let me have your comments.

--------------060309070705060202060304
Content-Type: text/plain;
 name="1394mount"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="1394mount"

#!/bin/bash

# Modprobe and mount the 1394 disk
# Invoke as "1394mount -m", or "1394mount -u"
# It deals with modules, creating symlink, and mounting.
# N.B. We must find out which /dev/sdX is the right one!
# Written on 2003-06-26 by Richard Neill <rjn@richardneill.org> and released under the terms of the GNU GPL.

MOUNTPOINT="/mnt/1394"					#This is the mountpoint (must be in /etc/fstab already, and must exist in /mnt, modes 777)
GEOMETRY="15017/255/63"					#This identifies the physical device...
							#The symlink to create is defined in /etc/fstab:  /dev/1394da1 /mnt/1394 reiserfs user,noauto,notail,noatime 1 2
DEVICES_TO_CHECK="/dev/sda /dev/sdb /dev/sdc /dev/sdd"  #These are the possibilities where it could be.
MODULES_TO_REMOVE="raw1394 sbp2 ohci1394 ieee1394"	#These are the modules to remove in REMOVAL order
MODULES_TO_PROBE="ieee1394 ohci1394 sbp2"		#These are the modules to probe in INSERT order.
MODULES_TO_UNPLUG="sbp2"				#This needs removed before the drive can be unplugged/switched off.



if [ `whoami` != "root" ] ;then
	echo "You need to be root to do this." ;  exit 1
fi

if [ ! -w $MOUNTPOINT ]; then
	echo "Mountpoint $MOUNTPOINT does not exist, or is not writeable" ; exit 1
fi

SYMLINK=`grep $MOUNTPOINT /etc/fstab | awk '{print $1}'` 	#This is the symlink to create in /dev to guarantee correspondance with /etc/fstab
if [ -z "$SYMLINK" ];then
	echo "Cannot find device in /etc/fstab to associate with $MOUNTPOINT " ; exit 1
fi

#----------------------------

if [ "$1" == "-m" ]; then

	echo "Attempting to mount $MOUNTPOINT..."		#Mount

	if mount | grep -i $MOUNTPOINT > /dev/null ;then	#Are we already mounted?
		echo "$MOUNTPOINT is already mounted"; exit 0
	fi

	for MODULE in $MODULES_TO_REMOVE; do			#Remove modules so they can be reinserted...
		if /sbin/lsmod | grep -e ^$MODULE > /dev/null; then
			echo -ne "Removing module $MODULE..."
			if /sbin/modprobe -r $MODULE ;then
				echo "[OK]"
			else
				echo "FAILED to remove module $MODULE"; exit 1
			fi
		fi
	done

	for MODULE in $MODULES_TO_PROBE; do			#Re-insert modules in order...this ensures that the entry is created in /dev
		echo -ne "Modprobing module $MODULE..."
		if /sbin/modprobe $MODULE ;then
			echo "[OK]"
		else
			echo "FAILED to insert module $MODULE"; exit 1
		fi
	done


	for DEVICE in $DEVICES_TO_CHECK; do			#Now check the possible devices which could be our 1394 disk.
		echo -ne "Checking device $DEVICE..."
		if [ -e $DEVICE ]; then
			if [ "`hdparm $DEVICE | grep geometry | awk  '{print $3}'`" == "$GEOMETRY," ]; then	#Check geometry
				echo "Found it"
				THE_DEVICE=$DEVICE;
				break;
			else
				echo "[Not this one]"
			fi
		else
			echo "[Non-existent]"
		fi
	done

	if [ -z "$THE_DEVICE" ];then				#Exit if we haven't found it.
		echo "Disk not found among devices: $DEVICES" ; exit 1
	fi

	THE_DEVICE_PARTITION_1=${THE_DEVICE}1			#/dev/sda1 not /dev/sda

	ln -s $THE_DEVICE_PARTITION_1 $SYMLINK			#Create the relevant symlink.
	
	echo -ne "Mounting $MOUNTPOINT..."

	if mount $MOUNTPOINT ;then				#Mount it.
		echo "[OK]" ; exit 0
	else
		echo "[Failed]" ; exit 1
	fi

#----------------------------

elif [ "$1" == "-u" ]; then

	echo  "Attempting to unmount $MOUNTPOINT..."		#Unmount

	if ! mount | grep -i $MOUNTPOINT > /dev/null ;then	#Are we already mounted?
		echo "$MOUNTPOINT was not mounted"; exit 0
	fi

	if ! umount $MOUNTPOINT ;then				#Unmount
		echo "Failed to unmount $MOUNTPOINT." ;	exit 1
	fi

	for MODULE in $MODULES_TO_UNPLUG; do			#Remove module so the drive may be unplugged and powered off.
		if /sbin/lsmod | grep -e ^$MODULE > /dev/null; then
			echo -ne "Removing module $MODULE..."
			if /sbin/modprobe -r $MODULE ;then
				echo "[OK]"
			else
				echo "FAILED to remove module $MODULE"; exit 1
			fi
		fi
	done

	rm $SYMLINK						#remove the relevant symlink from /dev

	echo "Unmounted $MOUNTPOINT successfully."
	echo "It's NOW OK to switch off and unplug the drive."
	exit 0

#----------------------------

else
	echo "Please invoke as '1394mount -m' (to mount) or '1394mount -u' (to unmount)"
fi
exit

--------------060309070705060202060304--