Re: More Elegant udev rules

Daniel Lawson <[email protected]> Mon, 21 Nov 2011 09:25:26 +1300
Newsgroups gmane.org.user-groups.linux.new-zealand.general
Message-ID <[email protected]>
> 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


> 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.

Either way, reading the udev manuals will help you a lot.




_______________________________________________
NZLUG mailing list [email protected]
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug