Jul 13, 2008

Writing udev-rules, the easier way

What is udev-rules?
udev is the device manager for the Linux 2.6 kernel series. Its primary function is managing device nodes in /dev. It is the successor of devfs and hotplug, which means that it handles the /dev directory and all user space actions when adding/removing devices, including firmware load.

Okay, here i will show you howto write udev-rule for a USB hardisk.

# lsusb

Bus 005 Device 003: ID 04fc:0c25 Sunplus Technology Co., Ltd
Bus 005 Device 001: ID 0000:0000
Bus 004 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 004: ID 062a:0000 Creative Labs Optical Mouse
Bus 001 Device 001: ID 0000:0000

This gives us two information, one of them is what we want.
Very first line shows that I have a Device with vernder id: 04fc and product id:0c25 named "Sunplus Technology Co., Ltd "

The second-last line points my USB-mouse, which is not of much interest now.

Now move to the /etc/udev/rules.d directory

# cd /etc/udev/rules.d

As the device is a storage device we will be writing the rule in "60-persistent-storage.rules"
So open this file with your prefered editor (I recommend scite in gui and vim in console) and add the following line:
KERNEL=="sd*[0-9]",SYSFS{idVendor}=="04fc",SYSFS{idProduct}=="0c25", SYMLINK+="sata"

This informs udev-manager, that if any storage device with vendour-id, 04fc and product-id 0c25 is plugged into the system add a symlink in /dev with name, sata.

Note: This rule is specific to the device only. And also this is not the only rule that you can write.

This is the easiest way. And there is another way round to work on this: >Here<


Finn said...

Found this site when searching for someone with a Creative mouse working under Linux.
I can not get the mouse to respond. I have the same id with lsusb as you do and dmesg tells me the mouse is found, but no joy.
Is your mouse working?http://www.blogger.com/logout.g?d=https%3A%2F%2Fwww.blogger.com%2Fcomment.g%3FblogID%3D5221947840660016642%26postID%3D7740323286366920936%26page%3D1%26isPopup%3Dtrue

SATA said...

Yes my mouse is working perfectly (I am a ubuntu user).

I cannot guess whats wrong with your sys.