Re: More Elegant udev rules
<[email protected]> Tue, 22 Nov 2011 09:57:01 +1300
| Newsgroups | gmane.org.user-groups.linux.new-zealand.general |
|---|---|
| Message-ID | <[email protected]> |
Thanks Daniel On Mon, 21 Nov 2011 09:25:26 +1300, Daniel Lawson <[email protected]> wrote: >> I found the following udev rules on the citrix forums designed to expose >> hard drive devices to VMs. By adding these rules to 50-udev.rules it does >> the job but exposes a bunch of other rubbish I could do without. >> >> >> >> ACTION=="add", SYSFS{vendor}=="ATA ", >> ID=="1:0:0:0|2:0:0:0|3:0:0:0|4:0:0:0", >> >> SYMLINK+="xapi/block/%k", \ >> >> RUN+="/bin/sh -c '/opt/xensource/libexec/local-device-change %k 2>&1 >>> /dev/null&'" >> ACTION=="remove", SYSFS{vendor}=="ATA ", >> ID=="1:0:0:0|2:0:0:0|3:0:0:0|4:0:0:0", \ >> >> RUN+="/bin/sh -c '/opt/xensource/libexec/local-device-change %k 2>&1 >>> /dev/null&'" >> >> >> Can anyone see how I could alter these rules to only expose my 3 2Tb Seagate >> sata drives? > > Yes, you can use one of the sysfs variables to limit on the specific > serial number of the drive. Or you could limit it to a model number, > or manufacturer, etc > > In the "ACTION" line, it currently selects based on the SYSFS{vendor} > variable being "ATA ", you could change that to SYSFS{serial} = > "yourserial". Get the serial number via sysfs itself to make sure > you're referring to the right thing > I had considered that but was more looking for code that would work in all instances instead of a specific instance. Not being a programmer I can't fully comprehend why the combination of SYSFS{vendor} and ID doesn't isolate devices more than it seems to already. Literally hundreds of devices appear in the removable storage list using the above code. > >> And while we are at it, is there a way to use IOCTL or hdparm >> within the rules to turn write cache off on each of my three drives without >> turning it off on the drive holding the system? (a completely separate >> drive, SSD in this case, which is also exposed to the VMs by the above >> rules) > > You already run a script in that rule on add/remove events. You could > either modify that script or write a new wrapper script that calls > your hdparm command and then calls the local-device-change script. Or > maybe the semantics of the RUN command allow multiple RUN lines, I > can't recall. Thanks, I'm a little worried about the warning to not run long running tasks using RUN. To make this elegant I would need to run hdparm on all possible hard disk devices. As part of a wrapper script would this be regarded as long? > > Either way, reading the udev manuals will help you a lot. I have read and re-read this site http://reactivated.net/writing_udev_rules.html and tried to understand the man pages prior to asking for help. My lack of programming knowledge is restricting my progress. I'm sorry I'm a real novice, particularly at low level interactions with hardware. Can anyone point me to a link better addressing the specific example with respect to udev rules writing? > > > > > _______________________________________________ > NZLUG mailing list [email protected] > http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug _______________________________________________ NZLUG mailing list [email protected] http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug