automate echo command on usb event

Peter Schwenke peter at bluetoad.com.au
Thu Feb 21 00:11:26 GMT 2008


Sebastian Spiess wrote:
> hi all,
> 
> I have a FreeAgendGo external 2.5" hdd. the hdd is running fine exept that before I can use it without problems I always 
> have to do the following
> 
> 	dmesg|tail
> 
> which gives me something like
> 
> [ 1280.152000] sdb: assuming drive cache: write through
> [ 1280.152000]  sdb: sdb1 sdb2
> [ 1280.172000] sd 2:0:0:0: Attached scsi disk sdb
> [ 1280.172000] sd 2:0:0:0: Attached scsi generic sg2 type 0
> [ 1280.556000] NTFS-fs warning (device sdb1): parse_options(): Option utf8 is no longer supported, using option nls=utf8. 
> Please use option nls=utf8 in the future and make sure utf8 is compiled either as a module or into the kernel.
> 
> then I can do a
> 
> 	sudo echo 1 >/sys/class/scsi_disk/2\:0\:0\:0/allow_restart
> 
> 
> and the drive works fine.
> troube is sometimes it is not sdb or not scsi_disk/2\:0\:0\:0
> how can I make the command that is will work everytime, or even better, automatically?
> 


Setting up a udev rule would do it.  I've had a fiddle with an external
drive here to work out the udev params

1. With an editor create a file in /etc/udev/rules.d/ for the udev rule
   Call it 85-ext_hd.rules
   I picked 85 since I  see a 85-hdparm.rules there

2. In the rule you'll need to match up the model and vendor.  You can
get that using
 udevinfo -a -p /sys/block/sdb


3. In 85-ext_hd.rules enter the line (all on the one line, thunderbird
has broken this up)

SUBSYSTEMS=="scsi",DRIVERS=="sd",KERNEL=="[0-9]*",
ATTRS{model}=="ST3320620A",ATTRS{vendor}=="Initio",RUN+="/usr/local/bin/fixFreeAgent.sh
%k"

substitute the model and vendor for what you found in step 2

4. With an editor create the file /usr/local/bin/fixFreeAgent.sh

with the contents

#!/bin/sh
echo 1 > /sys/class/scsi_disk/$1/allow_restart


I didn't actually run that line so check it carefully


5. sudo chmod +x /usr/local/bin/fixFreeAgent.sh
   sudo chmod +x /etc/udev/rules.d/85-ext_hd.rules

Then give it a whirl.




The only thing is that I couldn't get the udev rules to match exactly so
that the script was only called once.  It will be called twice.
I looked at using
SUBSYSTEMS=="scsi",KERNEL=="sd[b-z]",RUN+="/usr/local/bin/fixFreeAgent.sh
%k"
and at the output of  udevinfo -a -p /sys/block/sdb
to see if there was an attribute which contained the equivalent of
"2\:0\:0\:0" but no luck.


-- 
                                                              ...Peter



More information about the ubuntu-au mailing list