Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Personalizing your system with udev
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Redeeman
l33t
l33t


Joined: 25 Sep 2003
Posts: 958
Location: Portugal

PostPosted: Sun Jun 27, 2004 12:19 am    Post subject: Personalizing your system with udev Reply with quote

Hey, not many knows it, but udev can actually be used to personalize your system, which is quite cool.

in this guide i assume you have a working system, using udev for device management.

purpose
are you ever tired of having 2 usb harddrives/usbsticks and stuff, and you cant decide which one gets which device in /dev? and that you cant write a proper fstab?
i was too, then i discovered udevs extremely cool functionality.

we begin
plugin your device #1.
now browse in /sys, you must find your device in the sysfs tree. my device is a usb floppy, which gets recognized as a usb mass storage device, which is fine, i found it in:
Quote:
/sys/bus/usb/devices/1-1

go find the dir for your device too (if you cant find it, read next thing)
now we will gather information about our device!
Code:
root@redeeman: /sys/bus/usb/devices/1-1# ls
1-1:1.0              bDeviceProtocol  bNumConfigurations  bmAttributes  idProduct     maxchild  speed
bConfigurationValue  bDeviceSubClass  bNumInterfaces      detach_state  idVendor      power     version
bDeviceClass         bMaxPower        bcdDevice           devnum        manufacturer  product
root@redeeman: /sys/bus/usb/devices/1-1# cat manufacturer
SMSC
root@redeeman: /sys/bus/usb/devices/1-1# cat version
 1.10
root@redeeman: /sys/bus/usb/devices/1-1# cat devnum
2
root@redeeman: /sys/bus/usb/devices/1-1# cat idProduct
0fdc
root@redeeman: /sys/bus/usb/devices/1-1# cat idVendor
0424
root@redeeman: /sys/bus/usb/devices/1-1#

okay, now we know which manufactorer, version, devnum, idProduct, and idVendor the device is. thats all good, cause we are gonna use that, but first, we must decide which thing we want to recognize our device with.
i choose SMSC. the manufactorer.

Adding the required udev rules
the udev rules are located in /etc/udev/rules.d/, and as the default filename, 50-udev.rules (you can either create a new file, with a name that begins with a smaller number, to make it be read first, or edit the current, i edit the current)
okay find, you have opened the file, and then you go down to the USB section, and then we add our device, mine looks like:
Code:
BUS="usb", SYSFS{manufacturer}="SMSC", KERNEL="sd?", NAME="usb/usbfloppy", SYMLINK="usbfloppy"

here we can clearly see, that the sysfsnode manufacturer, which i choose, is SMSC, which is what we in the rule above, recognizes the device after, then we place the device inside usb/usbfloppy, for good orders sake, and symlinks to usbfloppy in the root of /dev.
IF i for example, had chosen to use the devices sysfs node, 'version', the rule would have looked like this:
Code:
BUS="usb", SYSFS{version}=" 1.10", KERNEL="sd?", NAME="usb/usbfloppy", SYMLINK="usbfloppy"


you can do like that with all devices. i did this with my usb stick too. here is my rule:
Code:
BUS="usb", SYSFS{manufacturer}="Stormblue Co., Ltd.", KERNEL="sd?1", NAME="usb/usbstick", SYMLINK="usbstick"


now you are actually done, and you have a MUCH nicer system, if you use more than 1 usb mass storage devices, this could be used with cameras too etc.
now you could create a fstab entry for the usbfloppy, and usbstick, mine looks like:
Code:
/dev/usbstick                   /mnt/usbstick           vfat            noauto,noatime,uid=redeeman,gid=vfat,rw,umask=003,dmask=003,fmask=003,user      0 0
/dev/usbfloppy                  /mnt/floppy             vfat            noauto,noatime,uid=redeeman,gid=vfat,rw,umask=003,dmask=003,fmask=003,user      0 0


[b]Make changes take affect[b]
you could just reboot, which is the simplest way, but if you dont like the idea of that (i did not) then pull out the devices, and run the following command:
Code:
udevstart


now plugin your devices (and pull them out) some times, and enjoy seeing it really working, (and rocking!)
Back to top
View user's profile Send private message
dsd
Developer
Developer


Joined: 30 Mar 2003
Posts: 2162
Location: nr London

PostPosted: Sun Jun 27, 2004 8:35 am    Post subject: Reply with quote

i've written a detailed doc on this document here. its also included in the udev distribution under docs/writing_udev_rules

in particular, a couple of suggestions:
udevinfo is much more convenient than spending hours trawling through /sys
always create your own rules file, dont edit the default, this will simplify things when you upgrade and the 50-udev.rules file has changed
_________________
http://dev.gentoo.org/~dsd
Back to top
View user's profile Send private message
eikketk
Apprentice
Apprentice


Joined: 03 Jun 2003
Posts: 270
Location: Belgium

PostPosted: Sun Jun 27, 2004 9:06 am    Post subject: Reply with quote

DONT distingate (sp?) USB devices on their GUID. Some devices have non-unique GUIDs (some printers), some have no GUID, and some have a changing GUID (some USB sticks send a GUID dependant on their place in the USB chain :roll:)
_________________
Working day and night to enhance the Linux Desktop Experience :)

Homepage
Back to top
View user's profile Send private message
Redeeman
l33t
l33t


Joined: 25 Sep 2003
Posts: 958
Location: Portugal

PostPosted: Sun Jun 27, 2004 10:21 am    Post subject: Reply with quote

its very different what devices has.. i noticed that while plugging mine in.. however i think if manufacturer or product is there.. they are a good choice
Back to top
View user's profile Send private message
grimm26
Guru
Guru


Joined: 23 May 2004
Posts: 313
Location: Chicagoland, IL

PostPosted: Mon Jul 12, 2004 10:10 pm    Post subject: mark Reply with quote

just marking
_________________
"Blessed is he who finds happiness in his own foolishness, for he will always be happy".
Back to top
View user's profile Send private message
AlterEgo
Veteran
Veteran


Joined: 25 Apr 2002
Posts: 1619

PostPosted: Tue Jul 13, 2004 8:43 am    Post subject: Re: mark Reply with quote

grimm26 wrote:
just marking

Please use some other bookmarking mechanism. Thanks!
Back to top
View user's profile Send private message
Redeeman
l33t
l33t


Joined: 25 Sep 2003
Posts: 958
Location: Portugal

PostPosted: Tue Jul 13, 2004 10:57 am    Post subject: Reply with quote

lol
Back to top
View user's profile Send private message
hackerError
Guru
Guru


Joined: 14 Mar 2003
Posts: 342
Location: Reston, VA, USA

PostPosted: Wed Jul 14, 2004 4:30 am    Post subject: Re: mark Reply with quote

AlterEgo wrote:
grimm26 wrote:
just marking

Please use some other bookmarking mechanism. Thanks!

is that your other bookmarking mechanism?
_________________
Before you insult someone, it is often best to walk a mile in their shoes.

That way when you insult them you're already a mile away and have their shoes.
Back to top
View user's profile Send private message
Redeeman
l33t
l33t


Joined: 25 Sep 2003
Posts: 958
Location: Portugal

PostPosted: Wed Jul 14, 2004 10:19 am    Post subject: Reply with quote

omg
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum