Udev: Difference between revisions
No edit summary |
No edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
For a description how to match rules to network cards see [[Network cards udev persistent binding]] | |||
If you want to match /dev/devicename to a device you own (such as a usb hard drive or usb hard disk) you can use udevinfo to find out what attributes you can map to: | If you want to match /dev/devicename to a device you own (such as a usb hard drive or usb hard disk) you can use udevinfo to find out what attributes you can map to: | ||
First you run dmesg to find out what devicename has been assigned to the drive. This will be towards the bottom of the information. You can also try | |||
dmesg | grep "Attached SCSI disk" -B1 | |||
The first line should tell you which device the computer has attatched the drive to. | |||
udevinfo -a -p $(udevinfo -q path -n /dev/sdh1) | udevinfo -a -p $(udevinfo -q path -n /dev/sdh1) | ||
This will show several devices. You can only match rules from 1 parent device, not from multiple ones! | This will show several devices related to /dev/sdh1. You can only match rules from 1 parent device, not from multiple ones! | ||
eg some of the output for above is: | eg some of the output for above is: | ||
Line 9: | Line 18: | ||
looking at parent device '/devices/pci0000:00/0000:00:1a.7/usb4/4-4/4-4:1.0/ho st3/target3:0:0/3:0:0:0': | looking at parent device '/devices/pci0000:00/0000:00:1a.7/usb4/4-4/4-4:1.0/ho st3/target3:0:0/3:0:0:0': | ||
KERNELS=="3:0:0:0" | KERNELS=="3:0:0:0" | ||
'''SUBSYSTEMS=="scsi"''' | '''''SUBSYSTEMS=="scsi"''''' | ||
DRIVERS=="sd" | DRIVERS=="sd" | ||
ATTRS{device_blocked}=="0" | ATTRS{device_blocked}=="0" | ||
Line 15: | Line 24: | ||
ATTRS{scsi_level}=="3" | ATTRS{scsi_level}=="3" | ||
ATTRS{vendor}=="Iomega " | ATTRS{vendor}=="Iomega " | ||
'''ATTRS{model}=="External HD "''' | '''''ATTRS{model}=="External HD "''''' | ||
ATTRS{rev}==" " | ATTRS{rev}==" " | ||
ATTRS{state}=="running" | ATTRS{state}=="running" | ||
Line 32: | Line 41: | ||
looking at parent device '/devices/pci0000:00/0000:00:1a.7/usb4/4-4': | looking at parent device '/devices/pci0000:00/0000:00:1a.7/usb4/4-4': | ||
KERNELS=="4-4" | KERNELS=="4-4" | ||
'''SUBSYSTEMS=="usb"''' | '''''SUBSYSTEMS=="usb"''''' | ||
DRIVERS=="usb" | DRIVERS=="usb" | ||
ATTRS{configuration}=="USB Mass Storage" | ATTRS{configuration}=="USB Mass Storage" | ||
Line 57: | Line 66: | ||
ATTRS{manufacturer}=="Iomega" | ATTRS{manufacturer}=="Iomega" | ||
ATTRS{product}=="Iomega External HD" | ATTRS{product}=="Iomega External HD" | ||
'''ATTRS{serial}=="948778888888"''' | '''''ATTRS{serial}=="948778888888"''''' | ||
allows you to construct the following rules to match the device: | allows you to construct the following rules to match the device: | ||
KERNEL=="sd?1", SUBSYSTEMS=="scsi", ATTRS{model}=="External HD ", SYMLINK+="test" | KERNEL=="sd?1", SUBSYSTEMS=="scsi", ATTRS{model}=="External HD ", SYMLINK+="test" | ||
KERNEL=="sd?1", SUBSYSTEMS=="usb", ATTRS{serial}=="948778888888", SYMLINK+="iomega1" | KERNEL=="sd?1", SUBSYSTEMS=="usb", ATTRS{serial}=="948778888888", SYMLINK+="iomega1" | ||
Both will work. You only have to use one. | Both will work. You only have to use one. | ||
Line 81: | Line 94: | ||
This can all be found [http://reactivated.net/writing_udev_rules.html here] | This can all be found [http://reactivated.net/writing_udev_rules.html here] | ||
Now if you want this to automount at boot as well, you neet to | |||
cat /etc/mtab | |||
there you can see the fstab options you're going to need. Then you add something like | |||
/dev/iomega1 /media/iomega1 ext3 defaults 0 0 | |||
to /etc/fstab | |||
unmount /media/iomega1 and mount -a to test if it mounts properly. |
Latest revision as of 16:54, 20 January 2012
For a description how to match rules to network cards see Network cards udev persistent binding
If you want to match /dev/devicename to a device you own (such as a usb hard drive or usb hard disk) you can use udevinfo to find out what attributes you can map to:
First you run dmesg to find out what devicename has been assigned to the drive. This will be towards the bottom of the information. You can also try
dmesg | grep "Attached SCSI disk" -B1
The first line should tell you which device the computer has attatched the drive to.
udevinfo -a -p $(udevinfo -q path -n /dev/sdh1)
This will show several devices related to /dev/sdh1. You can only match rules from 1 parent device, not from multiple ones!
eg some of the output for above is:
looking at parent device '/devices/pci0000:00/0000:00:1a.7/usb4/4-4/4-4:1.0/ho st3/target3:0:0/3:0:0:0': KERNELS=="3:0:0:0" SUBSYSTEMS=="scsi" DRIVERS=="sd" ATTRS{device_blocked}=="0" ATTRS{type}=="0" ATTRS{scsi_level}=="3" ATTRS{vendor}=="Iomega " ATTRS{model}=="External HD " ATTRS{rev}==" " ATTRS{state}=="running" ATTRS{timeout}=="30" ATTRS{iocounterbits}=="32" ATTRS{iorequest_cnt}=="0x3d" ATTRS{iodone_cnt}=="0x3d" ATTRS{ioerr_cnt}=="0x0" ATTRS{modalias}=="scsi:t-0x00" ATTRS{evt_media_change}=="0" ATTRS{queue_depth}=="1" ATTRS{queue_type}=="none" ATTRS{max_sectors}=="240"
looking at parent device '/devices/pci0000:00/0000:00:1a.7/usb4/4-4': KERNELS=="4-4" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{configuration}=="USB Mass Storage" ATTRS{bNumInterfaces}==" 1" ATTRS{bConfigurationValue}=="1" ATTRS{bmAttributes}=="c0" ATTRS{bMaxPower}==" 2mA" ATTRS{urbnum}=="287" ATTRS{idVendor}=="059b" ATTRS{idProduct}=="0276" ATTRS{bcdDevice}=="0100" ATTRS{bDeviceClass}=="00" ATTRS{bDeviceSubClass}=="00" ATTRS{bDeviceProtocol}=="00" ATTRS{bNumConfigurations}=="1" ATTRS{bMaxPacketSize0}=="64" ATTRS{speed}=="480" ATTRS{busnum}=="4" ATTRS{devnum}=="4" ATTRS{version}==" 2.00" ATTRS{maxchild}=="0" ATTRS{quirks}=="0x0" ATTRS{authorized}=="1" ATTRS{manufacturer}=="Iomega" ATTRS{product}=="Iomega External HD" ATTRS{serial}=="948778888888"
allows you to construct the following rules to match the device:
KERNEL=="sd?1", SUBSYSTEMS=="scsi", ATTRS{model}=="External HD ", SYMLINK+="test"
KERNEL=="sd?1", SUBSYSTEMS=="usb", ATTRS{serial}=="948778888888", SYMLINK+="iomega1"
Both will work. You only have to use one.
I put these in /etc/udev/rules.d/local.rules
/etc/init.d/udev restart
and then you have to unplug and replug the device for the symlink to appear in /dev (so /dev/iomega1 or /dev/test)
In order to automount, you can add:
, RUN+="/bin/mount -t auto /dev/iomega1 /media/iomega1"
to the rule, so the above rule in local.rules becomes:
KERNEL=="sd?1", SUBSYSTEMS=="usb", ATTRS{serial}=="948778888888", SYMLINK+="iomega1", RUN+="/bin/mount -t auto /dev/iomega1 /media/iomega1"
This can all be found here
Now if you want this to automount at boot as well, you neet to
cat /etc/mtab
there you can see the fstab options you're going to need. Then you add something like
/dev/iomega1 /media/iomega1 ext3 defaults 0 0
to /etc/fstab
unmount /media/iomega1 and mount -a to test if it mounts properly.