LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   writing udev rules (https://www.linuxquestions.org/questions/linux-software-2/writing-udev-rules-496224/)

doralsoral 10-27-2006 07:23 PM

writing udev rules
 
I want to set my system up so when i plug it my usb hard disk, my camera, and my ipod they are always the same dev name so i can have them automounted. right now when i plug them in they always end up changing to something different than the last time i plugged them in so the fstab entry is useless. I've read some howtos on writing udev rules but i can't seem to get it going. can someone give me a hand?

ilikejam 10-27-2006 08:06 PM

Hi.

Here's my /etc/udev/rules.d/10-cronus.rules to start with:
Code:

KERNEL=="sd?1", SYSFS{manufacturer}=="Sony", SYMLINK+="sony"
KERNEL=="sd?1", SYSFS{product}=="Cruzer Mini", SYMLINK+="cruzer"
KERNEL=="sd?1", SYSFS{product}=="LaCie Hard Drive USB", SYMLINK+="backup"
KERNEL=="sd?2", SYSFS{product}=="LaCie Hard Drive USB", SYMLINK+="transport"
KERNEL=="sd?2", SYSFS{product}=="iPod mini", SYMLINK+="ipod"

So when I plug in my iPod, I get a '/dev/ipod' device, linked to the data-holding /dev/sdX2 partition.
The LaCie drive has two partitions (differentiated by sd?1 and sd?2).

To get all the udev info for a device, run the following:
Code:

udevinfo -a -p `udevinfo -q path -n /dev/DEVICE`
and pick something unique to differentiate the device/partition.

This is the output when the LaCie drive is plugged in and is at /dev/sda, as an example:
Code:

[root@cronus ~]# udevinfo -a -p `udevinfo -q path -n /dev/sda`

udevinfo starts with the device the node belongs to and then walks up the
device chain, to print for every device found, all possibly useful attributes
in the udev key format.
Only attributes within one device section may be used together in one rule,
to match the device for which the node will be created.

  looking at device '/block/sda':
    KERNEL=="sda"
    SUBSYSTEM=="block"
    SYSFS{stat}=="    107      824    1260      390        0        0        0        0        0      227      390"
    SYSFS{size}=="488397168"
    SYSFS{removable}=="0"
    SYSFS{range}=="16"
    SYSFS{dev}=="8:0"

  looking at device '/devices/pci0000:00/0000:00:10.3/usb1/1-3/1-3:1.0/host0/target0:0:0/0:0:0:0':
    ID=="0:0:0:0"
    BUS=="scsi"
    DRIVER=="sd"
    SYSFS{ioerr_cnt}=="0x0"
    SYSFS{iodone_cnt}=="0x72"
    SYSFS{iorequest_cnt}=="0x72"
    SYSFS{iocounterbits}=="32"
    SYSFS{timeout}=="60"
    SYSFS{state}=="running"
    SYSFS{rev}=="15.0"
    SYSFS{model}=="WD2500JB-00FUA0 "
    SYSFS{vendor}=="WDC    "
    SYSFS{scsi_level}=="3"
    SYSFS{type}=="0"
    SYSFS{queue_type}=="none"
    SYSFS{queue_depth}=="1"
    SYSFS{device_blocked}=="0"
    SYSFS{max_sectors}=="240"

  looking at device '/devices/pci0000:00/0000:00:10.3/usb1/1-3/1-3:1.0/host0/target0:0:0':
    ID=="target0:0:0"
    BUS==""
    DRIVER==""

  looking at device '/devices/pci0000:00/0000:00:10.3/usb1/1-3/1-3:1.0/host0':
    ID=="host0"
    BUS==""
    DRIVER==""

  looking at device '/devices/pci0000:00/0000:00:10.3/usb1/1-3/1-3:1.0':
    ID=="1-3:1.0"
    BUS=="usb"
    DRIVER=="usb-storage"
    SYSFS{modalias}=="usb:v059Fp0351d0000dc00dsc00dp00ic08isc06ip50"
    SYSFS{bInterfaceProtocol}=="50"
    SYSFS{bInterfaceSubClass}=="06"
    SYSFS{bInterfaceClass}=="08"
    SYSFS{bNumEndpoints}=="02"
    SYSFS{bAlternateSetting}==" 0"
    SYSFS{bInterfaceNumber}=="00"

  looking at device '/devices/pci0000:00/0000:00:10.3/usb1/1-3':
    ID=="1-3"
    BUS=="usb"
    DRIVER=="usb"
    SYSFS{configuration}==""
    SYSFS{serial}=="10000E0008529A96"
    SYSFS{product}=="LaCie Hard Drive USB"
    SYSFS{manufacturer}=="LaCie"
    SYSFS{maxchild}=="0"
    SYSFS{version}==" 2.00"
    SYSFS{devnum}=="4"
    SYSFS{speed}=="480"
    SYSFS{bMaxPacketSize0}=="64"
    SYSFS{bNumConfigurations}=="1"
    SYSFS{bDeviceProtocol}=="00"
    SYSFS{bDeviceSubClass}=="00"
    SYSFS{bDeviceClass}=="00"
    SYSFS{bcdDevice}=="0000"
    SYSFS{idProduct}=="0351"
    SYSFS{idVendor}=="059f"
    SYSFS{bMaxPower}=="  2mA"
    SYSFS{bmAttributes}=="c0"
    SYSFS{bConfigurationValue}=="1"
    SYSFS{bNumInterfaces}==" 1"

  looking at device '/devices/pci0000:00/0000:00:10.3/usb1':
    ID=="usb1"
    BUS=="usb"
    DRIVER=="usb"
    SYSFS{configuration}==""
    SYSFS{serial}=="0000:00:10.3"
    SYSFS{product}=="EHCI Host Controller"
    SYSFS{manufacturer}=="Linux 2.6.18.1cronus ehci_hcd"
    SYSFS{maxchild}=="6"
    SYSFS{version}==" 2.00"
    SYSFS{devnum}=="1"
    SYSFS{speed}=="480"
    SYSFS{bMaxPacketSize0}=="64"
    SYSFS{bNumConfigurations}=="1"
    SYSFS{bDeviceProtocol}=="01"
    SYSFS{bDeviceSubClass}=="00"
    SYSFS{bDeviceClass}=="09"
    SYSFS{bcdDevice}=="0206"
    SYSFS{idProduct}=="0000"
    SYSFS{idVendor}=="0000"
    SYSFS{bMaxPower}=="  0mA"
    SYSFS{bmAttributes}=="e0"
    SYSFS{bConfigurationValue}=="1"
    SYSFS{bNumInterfaces}==" 1"

  looking at device '/devices/pci0000:00/0000:00:10.3':
    ID=="0000:00:10.3"
    BUS=="pci"
    DRIVER=="ehci_hcd"
    SYSFS{broken_parity_status}=="0"
    SYSFS{enable}=="1"
    SYSFS{modalias}=="pci:v00001106d00003104sv00001458sd00005004bc0Csc03i20"
    SYSFS{local_cpus}=="1"
    SYSFS{irq}=="19"
    SYSFS{class}=="0x0c0320"
    SYSFS{subsystem_device}=="0x5004"
    SYSFS{subsystem_vendor}=="0x1458"
    SYSFS{device}=="0x3104"
    SYSFS{vendor}=="0x1106"

  looking at device '/devices/pci0000:00':
    ID=="pci0000:00"
    BUS==""
    DRIVER==""

Dave

doralsoral 10-28-2006 10:12 AM

Hey that helped me a lot, the only thing i can't get working is my usb card reader. Do you know how to set one of these up, if it makes it easier i only have one kind of card i need read.

ilikejam 10-28-2006 11:21 AM

Hi.

Plug in the card reader (and card), and post the output from:

udevinfo -a -p `udevinfo -q path -n /dev/DEVICE`

where DEVICE is the sdX device which appears when you plug it in.

Dave

doralsoral 10-28-2006 12:52 PM

looking at device '/block/sdb':
KERNEL=="sdb"
SUBSYSTEM=="block"
SYSFS{stat}==" 0 0 0 0 0 0 0 0 0 0 0"
SYSFS{size}=="0"
SYSFS{removable}=="1"
SYSFS{range}=="16"
SYSFS{dev}=="8:16"

looking at device '/devices/pci0000:00/0000:00:02.2/usb1/1-5/1-5:1.0/host9/target9:0:0/9:0:0:0':
ID=="9:0:0:0"
BUS=="scsi"
DRIVER=="sd"
SYSFS{ioerr_cnt}=="0x43b3"
SYSFS{iodone_cnt}=="0x43b4"
SYSFS{iorequest_cnt}=="0x43b4"
SYSFS{iocounterbits}=="32"
SYSFS{timeout}=="30"
SYSFS{state}=="running"
SYSFS{rev}=="3.95"
SYSFS{model}=="Flash HS-CF"
SYSFS{vendor}=="Generic "
SYSFS{scsi_level}=="3"
SYSFS{type}=="0"
SYSFS{queue_type}=="none"
SYSFS{queue_depth}=="1"
SYSFS{device_blocked}=="0"
SYSFS{max_sectors}=="240"

looking at device '/devices/pci0000:00/0000:00:02.2/usb1/1-5/1-5:1.0/host9/target9:0:0':
ID=="target9:0:0"
BUS==""
DRIVER==""

looking at device '/devices/pci0000:00/0000:00:02.2/usb1/1-5/1-5:1.0/host9':
ID=="host9"
BUS==""
DRIVER==""

looking at device '/devices/pci0000:00/0000:00:02.2/usb1/1-5/1-5:1.0':
ID=="1-5:1.0"
BUS=="usb"
DRIVER=="usb-storage"
SYSFS{modalias}=="usb:v050Dp0211d0395dc00dsc00dp00ic08isc06ip50"
SYSFS{bInterfaceProtocol}=="50"
SYSFS{bInterfaceSubClass}=="06"
SYSFS{bInterfaceClass}=="08"
SYSFS{bNumEndpoints}=="02"
SYSFS{bAlternateSetting}==" 0"
SYSFS{bInterfaceNumber}=="00"

looking at device '/devices/pci0000:00/0000:00:02.2/usb1/1-5':
ID=="1-5"
BUS=="usb"
DRIVER=="usb"
SYSFS{configuration}==""
SYSFS{serial}=="0504062049D6"
SYSFS{product}=="15 in 1 MEDIA READER USB 2.0"
SYSFS{manufacturer}=="BELKIN"
SYSFS{maxchild}=="0"
SYSFS{version}==" 2.00"
SYSFS{devnum}=="8"
SYSFS{speed}=="480"
SYSFS{bMaxPacketSize0}=="64"
SYSFS{bNumConfigurations}=="1"
SYSFS{bDeviceProtocol}=="00"
SYSFS{bDeviceSubClass}=="00"
SYSFS{bDeviceClass}=="00"
SYSFS{bcdDevice}=="0395"
SYSFS{idProduct}=="0211"
SYSFS{idVendor}=="050d"
SYSFS{bMaxPower}==" 96mA"
SYSFS{bmAttributes}=="80"
SYSFS{bConfigurationValue}=="1"
SYSFS{bNumInterfaces}==" 1"

looking at device '/devices/pci0000:00/0000:00:02.2/usb1':
ID=="usb1"
BUS=="usb"
DRIVER=="usb"
SYSFS{configuration}==""
SYSFS{serial}=="0000:00:02.2"
SYSFS{product}=="EHCI Host Controller"
SYSFS{manufacturer}=="Linux 2.6.17-gentoo-r8 ehci_hcd"
SYSFS{maxchild}=="8"
SYSFS{version}==" 2.00"
SYSFS{devnum}=="1"
SYSFS{speed}=="480"
SYSFS{bMaxPacketSize0}=="64"
SYSFS{bNumConfigurations}=="1"
SYSFS{bDeviceProtocol}=="01"
SYSFS{bDeviceSubClass}=="00"
SYSFS{bDeviceClass}=="09"
SYSFS{bcdDevice}=="0206"
SYSFS{idProduct}=="0000"
SYSFS{idVendor}=="0000"
SYSFS{bMaxPower}==" 0mA"
SYSFS{bmAttributes}=="e0"
SYSFS{bConfigurationValue}=="1"
SYSFS{bNumInterfaces}==" 1"

looking at device '/devices/pci0000:00/0000:00:02.2':
ID=="0000:00:02.2"
BUS=="pci"
DRIVER=="ehci_hcd"
SYSFS{modalias}=="pci:v000010DEd000000E8sv00001043sd0000813Fbc0Csc03i20"
SYSFS{local_cpus}=="1"
SYSFS{irq}=="193"
SYSFS{class}=="0x0c0320"
SYSFS{subsystem_device}=="0x813f"
SYSFS{subsystem_vendor}=="0x1043"
SYSFS{device}=="0x00e8"
SYSFS{vendor}=="0x10de"

looking at device '/devices/pci0000:00':
ID=="pci0000:00"
BUS==""
DRIVER==""

ilikejam 10-30-2006 09:38 PM

Hi again.

Try the following:
Code:

KERNEL=="sd?1", SYSFS{product}=="15 in 1 MEDIA READER USB 2.0", SYMLINK+="cardreader"
That should create a '/dev/cardreader' device for the first (and probably only) partition of any card you put in the card reader.

Dave

doralsoral 10-31-2006 08:10 AM

That doesn't even create device nodes

ilikejam 10-31-2006 10:55 AM

ORLY?

How about:
Code:

KERNEL=="sd?", SYSFS{product}=="15 in 1 MEDIA READER USB 2.0", SYMLINK+="cardreader"

Quakeboy02 11-18-2006 05:30 PM

I'm also trying to install a cardreader. It's a Microtech CameraMate. My system is Debian 2.6.8. When I mount the CameraMate, the mounted filesystem gives me 4 directories (001, 002, 003, 004) as well as a file named devices. None of the directories has any actual card data in it. The devices file doesn't have anything really useful, either. IOW, I can mount the device, but I can't get at the picture my camera put on it. I checked the card again on the camera, and the picture is fine. I enabled the verbose usb debugging messages, and I get "Not Ready: Medium Not Present" on the console when I insert a card in the device.

doralsoral 11-18-2006 06:09 PM

If you have a several-in-one card reader, you'll probably have to also set Device Drivers --> SCSI device support -->[*] Probe all LUNs on each SCSI device (kernel 2.6). These readers are usually set up with one slot as the primary slot, so if this option isn't set, you won't be able to see the other slots.

Quakeboy02 11-19-2006 02:45 AM

Quote:

Originally Posted by Quakeboy02
I'm also trying to install a cardreader. It's a Microtech CameraMate. My system is Debian 2.6.8. When I mount the CameraMate, the mounted filesystem gives me 4 directories (001, 002, 003, 004) as well as a file named devices. None of the directories has any actual card data in it. The devices file doesn't have anything really useful, either. IOW, I can mount the device, but I can't get at the picture my camera put on it. I checked the card again on the camera, and the picture is fine. I enabled the verbose usb debugging messages, and I get "Not Ready: Medium Not Present" on the console when I insert a card in the device.

After banging on this with a largish hammer, I finally realised that my problem is not the Microtech device. The problem I have is that the camera, an old Fuji MX-1200 isn't putting data on the disk in any format that Linux can read. If I simply do mkdosfs on my cards in the CameraMate, I can use them just fine. Of course, then the Camera can't read them. The file system used by the camera seems to be almost but not quite, MSDOS. Oh well.


All times are GMT -5. The time now is 12:10 AM.