writing-udev-rules, the easier way
This will give you a bit of understanding about what a udev-rule is and how can you write a udev rule on the basis of vender-id and product-id.
Here is the other way (Its easier but a bit time consuming):
So here you go..
Insert your usb-device, and watch the log:
# tail -f /var/log/messages
Jul 13 16:47:20 workbench kernel: [ 5418.740803] sd 7:0:0:0: [sdb] 312581808 512-byte hardware sectors (160042 MB)
Jul 13 16:47:20 workbench kernel: [ 5418.743055] sd 7:0:0:0: [sdb] Write Protect is off
Jul 13 16:47:21 workbench kernel: [ 5418.743072] sdb: sdb1
Jul 13 16:47:21 workbench kernel: [ 5419.323103] sd 7:0:0:0: [sdb] Attached SCSI disk
Jul 13 16:47:21 workbench kernel: [ 5419.323163] sd 7:0:0:0: Attached scsi generic sg2 type 0
Jul 13 16:47:20 workbench kernel: [ 5418.743055] sd 7:0:0:0: [sdb] Write Protect is off
Jul 13 16:47:21 workbench kernel: [ 5418.743072] sdb: sdb1
Jul 13 16:47:21 workbench kernel: [ 5419.323103] sd 7:0:0:0: [sdb] Attached SCSI disk
Jul 13 16:47:21 workbench kernel: [ 5419.323163] sd 7:0:0:0: Attached scsi generic sg2 type 0
Notice the third-last line. It shows that the device is mounted as sdb1.
Now lets dig into it.
# udevinfo -q path -n /dev/sdb1
/block/sdb/sdb1
This shows the devpath of the device.
From this devpath you can see a lot of information.
# udevinfo -a -p /block/sdb/sdb1
At the very first line of the output you will see:
"Udevinfo starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device."
This pretty much explains itself.
And the (trimmed-)output is:
looking at device '/block/sdb/sdb1':
KERNEL=="sdb1"
SUBSYSTEM=="block"
DRIVER==""
ATTR{dev}=="8:17"
ATTR{start}=="63"
ATTR{size}=="312576642"
ATTR{stat}==" 11011 11620 0 0"
looking at parent device '/block/sdb':
KERNELS=="sdb"
SUBSYSTEMS=="block"
DRIVERS==""
ATTRS{dev}=="8:16"
ATTRS{range}=="16"
ATTRS{removable}=="0"
ATTRS{size}=="312581808"
ATTRS{stat}==" 206 10881 12228 1688 0 0 0 0 0 1272 1688"
ATTRS{capability}=="12"
...
looking at parent device '/devices/pci0000:00/0000:00:1d.7':
KERNELS=="0000:00:1d.7"
SUBSYSTEMS=="pci"
DRIVERS=="ehci_hcd"
ATTRS{vendor}=="0x8086"
ATTRS{device}=="0x24dd"
ATTRS{subsystem_vendor}=="0x8086"
ATTRS{subsystem_device}=="0x4246"
ATTRS{class}=="0x0c0320"
ATTRS{irq}=="19"
ATTRS{local_cpus}=="ff"
ATTRS{modalias}=="pci:v00008086d000024DDsv00008086sd00004246bc0Csc03i20"
ATTRS{broken_parity_status}=="0"
ATTRS{msi_bus}==""
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
KERNEL=="sdb1"
SUBSYSTEM=="block"
DRIVER==""
ATTR{dev}=="8:17"
ATTR{start}=="63"
ATTR{size}=="312576642"
ATTR{stat}==" 11011 11620 0 0"
looking at parent device '/block/sdb':
KERNELS=="sdb"
SUBSYSTEMS=="block"
DRIVERS==""
ATTRS{dev}=="8:16"
ATTRS{range}=="16"
ATTRS{removable}=="0"
ATTRS{size}=="312581808"
ATTRS{stat}==" 206 10881 12228 1688 0 0 0 0 0 1272 1688"
ATTRS{capability}=="12"
...
looking at parent device '/devices/pci0000:00/0000:00:1d.7':
KERNELS=="0000:00:1d.7"
SUBSYSTEMS=="pci"
DRIVERS=="ehci_hcd"
ATTRS{vendor}=="0x8086"
ATTRS{device}=="0x24dd"
ATTRS{subsystem_vendor}=="0x8086"
ATTRS{subsystem_device}=="0x4246"
ATTRS{class}=="0x0c0320"
ATTRS{irq}=="19"
ATTRS{local_cpus}=="ff"
ATTRS{modalias}=="pci:v00008086d000024DDsv00008086sd00004246bc0Csc03i20"
ATTRS{broken_parity_status}=="0"
ATTRS{msi_bus}==""
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
So you can choose any block and write the rule for that.
Let me zoom into a block
looking at device '/block/sdb/sdb1':
KERNEL=="sdb1"
SUBSYSTEM=="block"
DRIVER==""
ATTR{dev}=="8:17"
ATTR{start}=="63"
ATTR{size}=="312576642"
ATTR{stat}==" 11011 11620 0 0"
KERNEL=="sdb1"
SUBSYSTEM=="block"
DRIVER==""
ATTR{dev}=="8:17"
ATTR{start}=="63"
ATTR{size}=="312576642"
ATTR{stat}==" 11011 11620 0 0"
So here's the rule for this :
KERNEL=="sdb1", SUBSYSTEM=="block", ATTR{dev}=="8:17", ATTR{start}=="63", ATTR{size}=="312576642", SYMLINK+="myDisk"
Now, this is also not the only rule. Go on! Generate your own rule. Mind with the spaces like in case of ATTR{stat}==" 11011 11620 0 0".
Finally place the rule in /etc/udev/rules.d/60-persistent-storage.rules. Then Plug out the device and again plug-in to see the change.
# ls /dev/ | grep my
myDisk
That's it.
If you want to learn more about it:
http://reactivated.net/writing_udev_rules.html
http://ubuntuforums.org/showthread.php?t=168221
No comments:
Post a Comment