LinuxBasics.org

The community that helps people to run Linux

rss
Table of Contents

Using udev

The following article was written primarily in 2006. I think for the most part, people will find current distos handling USB without their having to edit anything. My experience now is that I plug in the thumb drive or external usb drive and an icon pops up on my desktop showing that it has been recognized. Often the file manager will open to show me the contents of the drive, camera, or whatever. So, for most of us this article is obsolete. For that I am grateful. The old days of making the mount point and putting the mounting information in /etc/fstab seem to have gone. So “using udev” is simply using udev and not preparing the system so that one may use udev. — Anita Lewis 2007/09/03 23:53


Kernel 2.6 has begun the use of udev for handling devices–for making those files in /dev that previous kernels just created permanently. udev creates these files as needed. Setting up udev so that when you plug in a palm and then have /dev/pilot as the assigned device is not difficult. I got the information on how to do this at http://webpages.charter.net/decibelshelp/LinuxHelp_UDEVPrimerMisc.html. I am using Debian Sarge with 2.6.8-2-386 kernel.

General procedure

Jump (thumb) drive

Plug the jump drive into a usb port.

 
$ udevinfo -p /sys/block/sda/sda1 -a |less

Scroll down to where you see the name of your device and find the serial number if you can.

SYSFS{model}="USB DISK 20X    "
SYSFS{serial}="075203150062"

In /etc/udev/rules.d/udev.rules add:

BUS="usb", SYSFS{serial}="075203150062", NAME="jump"

In a later version of udev, udevinfo shows the BUS is “scsi”. The file to edit is /etc/udev/rules.d/20-names.rules. Note also that there is a double equal sign used except for in the NAME. Previously a single equal sign was used.

BUS=="scsi", SYSFS{model}=="USB DISK 20X    ", NAME="jump"

Remove and reinsert jump drive. ‘ls /dev’ and you will see /dev/jump

Put into /etc/fstab:

/dev/jump       /jump           vfat    rw,users,noauto    0       0

‘mount /jump’; check it; ‘umount /jump’; remove drive.

Mp3 Player

Plug the mp3 player into a usb port.

I tried:

 
$ udevinfo -p /sys/block/sda/sda1 -a |less

The result: ‘couldn’t get the class device’

Then I tried:

 
$ udevinfo -p /sys/block/sdb/sdb1 -a |less

In that is for my Creative Nano mp3 player:

    SYSFS{product}="Zen Nano"
    SYSFS{serial}="0002F685B2BB4D10"

In /etc/udev/rules.d/udev.rules add:

BUS="usb", SYSFS{serial}="0002F685B2BB4D10", NAME="mp3player"

Put into /etc/fstab:

/dev/mp3player   /mp3player      vfat    users,exec,suid,dev,rw,noauto  0  0

You will be able to mount your mp3 player on /mp3player and add or delete mp3s just as any other file on your system.

Camera

Plug the camera into a usb port and turn it on.

 
$ udevinfo -p /sys/block/sda/sda1 -a |less

Scroll down to where you see the name of your device and find the serial number as with the jump drive. In my case the serial number was a string of zeros; so I used the product name instead.

 
BUS="usb", SYSFS{product}="PENTAX Optio 60", NAME="camera"

I created directory /camera and wrote this in /etc/fstab and mounted as user:

 
/dev/camera       /camera           vfat    rw,users,noauto    0       0

Then I could ‘mount /camera’; ‘cd /camera’; go down the tree to where the pictures were and copy them to my hard drive; ‘umount /camera’; and remove the camera after I got the prompt back to show me that the download was complete. Looking at the camera light is also an indication of this. Just don’t remove the cable until you are sure /camera has been unmounted.

Palm

Mine is hooked up with usb cable. A serial connection will be different.

Hook up the palm with usb cable and tap the hotsync button

$ udevinfo -p /sys/class/tty/ttyUSB1 -a |less

This is the area I was looking for:

    SYSFS{product}="Palm Handheld"
    SYSFS{serial}="PalmSN12345678"

Looking at udev.rules I saw this already there. It was not commented out.:

#BUS="usb", KERNEL="ttyUSB*", SYSFS{product}="Palm Handheld*", SYMLINK="pilot"

I commented out the above and added this:

BUS="usb", SYSFS{serial}="PalmSN12345678", NAME="pilot"

Jpilot is set to use /dev/pilot for the sync and that is also the default for pilot-xfer; so I just plug in the usb cable; hit the hotsync button, and click on the hotsync on Jpilot and the sync is accomplished. The 2.6.8 kernel is nice, because the visor module does not require the edit that the 2.4 kernel did for my Zire 31. You do need a loaded module for your handheld, of course.

Zip Drive

My Zip Drive is an Iomega 100, external that hooks into the parallel port. I usually mount it as /dev/sda4. Now I can avoid conflicts that used to occur when something else got to /dev/sda4 first.

 
$ udevinfo -p /sys/block/sda/sda4 -a |less

This time I came up with a model and vendor and according to information on http://gentoo-wiki.com/HARDWARE_Zip_Drive I decided to use both:

SYSFS{model}="ZIP 100         "
<snip>
SYSFS{vendor}="IOMEGA  "

Note that the BUS here is scsi and not usb. In /etc/udev/rules.d/udev.rules add:

BUS="scsi", SYSFS{model}="ZIP 100         ", SYSFS{vendor}="IOMEGA  ", NAME="zip"

Make your mountpoint directory (below it is /zip) and add to /etc/fstab:

/dev/zip       /zip           vfat    rw,users,noauto    0       0

For some reason I had to reboot to get this new device in /dev. I already had /dev/zip for some reason. I deleted /dev/zip and tried turning the Zip Drive off and on, but the new /dev/zip was not created. I tried running ‘/etc/init.d/makedev restart’ as well as restarting hotplug. Finally I rebooted and that took care of it.

Syntax change in upgrade udev

Note after upgrade to Ubuntu Edgy: udev syntax has changed a bit using double equal signs except in the NAME. Also I’ve switched to using /media/zip instead of /zip. This gives me a nice little Zipdrive icon on my desktop when mounted.

In /etc/udev/rules.d/20-names.rules :

BUS=="scsi", SYSFS{model}=="ZIP 100         ", SYSFS{vendor}=="IOMEGA  ", NAME="zip"

In /etc/fstab:

/dev/zip        /media/zip      vfat    users,exec,suid,dev,rw,noauto  0  0

Copyright (c) by the authors.
Prior to editing, authors agreed to license their contributions by the terms of the GPL.
See our licensing page for details.


Linux® is a registered trademark of Linus Torvalds.


 
  tutorials/using/using_udev.txt · Last modified: 2007/11/16 12:24

LinuxBasics.org

Start Linux-Course Tutorials Linux Links Security Mailing List Online Chat Blog Forum

Site-Info

Help Get in Touch Making of LBo

Wiki-Control

Powered by

Linux Apache DokuWiki Mailman RUTE ht://Dig