I think that the heading of this doc explains pretty much what am I going to talk about, but for those of you who still wonder I am talking about UDEV. UDEV allows Linux users to have a dynamic /dev directory and it provides the ability to have persistent device names. YES persistent device names..God knows how many times I was in need of connecting devices for quick copy or upload and ALWAYS had to check and tinker with : is it a /dev/sda or is it sdb, because I had another device connected before this one. If you wanted to use FSTAB to allow users to mount devices you could just forget it because none of the devices had the same reference name ~ ergo FSTAB was useless for this. Because of this (and many other things that I don't remember right now) I decided to use UDEV.
I presume that UDEV is installed and working, as I am not gonna explain how to install it. For those of you who want to read more about it here is link to look at UDEV and Gentoo
Since my all external devices are USB2 based and compatible with Linux its was matter of digging in kernel to make them work with my system. Same rule goes here as for UDEV installation. I don't know what hardware you have and can't help you with it, you need to worked that out for your self. Howto is based on hardware that I have and it should apply to most of the hardware out there. So first thing is to make them work with out UDEV and then install UDEV and make them work together.
We are gonna use udevinfo to find out information about our devices. Lets start figuring out where my usb-drive is. Just to remind you almost all devices connected over USB can be found as /dev/sd* Simple
udevinfo -a -p /sys/block/sda | grep SYSFS #(or sdb and so on)
will show you information on devices that are connected to PC over USB2. After running command few times on different devices I found out that USB is connected as /dev/sdc. Here is SYSFS output:
SYSFS{idProduct}=="6830"
SYSFS{idVendor}=="04b4"
SYSFS{manufacturer}=="Cypress Semiconductor"
SYSFS{maxchild}=="0"
SYSFS{product}=="USB2.0 Storage Device"
SYSFS{serial}=="DEF10997A434"
SYSFS{speed}=="480"
SYSFS{version}==" 2.00"
SYSFS{bConfigurationValue}=="1"
SYSFS{bDeviceClass}=="09"
SYSFS{bDeviceProtocol}=="01"
SYSFS{bDeviceSubClass}=="00"
SYSFS{bMaxPacketSize0}=="64"
SYSFS{bMaxPower}==" 0mA"
SYSFS{bNumConfigurations}=="1"
SYSFS{bNumInterfaces}==" 1"
SYSFS{bcdDevice}=="0206"
SYSFS{bmAttributes}=="c0"
SYSFS{configuration}==""
SYSFS{devnum}=="1"
SYSFS{idProduct}=="0000"
SYSFS{idVendor}=="0000"
SYSFS{manufacturer}=="Linux 2.6.16.5 ehci_hcd"
SYSFS{maxchild}=="10"
SYSFS{product}=="EHCI Host Controller"
SYSFS{serial}=="0000:00:02.1"
SYSFS{speed}=="480"
SYSFS{version}==" 2.00"
SYSFS{class}=="0x0c0320"
SYSFS{device}=="0x005b"
SYSFS{irq}=="19"
SYSFS{local_cpus}=="ff"
SYSFS{modalias}=="pci:v000010DEd0000005Bsv00001019sd00001B51bc0Csc03i20"
SYSFS{subsystem_device}=="0x1b51"
SYSFS{subsystem_vendor}=="0x1019"
SYSFS{vendor}=="0x10de"
There is lots of info here and we are going to use just one of them, so don't let this scare you. If I did it then anybody can...
To simplify the output
udevinfo -a -p /sys/block/sda | egrep "SYSFS{model} | SYSFS{product}"
gives us:
SYSFS{product}=="USB2.0 Storage Device"
So "USB2.0 Storage Device" is the one thing we are gonna use and add it to udev rule later on.
So far so good ..and its easy right ? The other device that I want to add is my LEXAR USB2 Card-reader that can read 4-5 different memory cards. Process of finding out where the device is, is the same as for usb drive only you have to remember that this device is seen as 4 different devices.
Lets start finding out this to shell we ? We can eliminate sdc because its already in use for usb drive. So running
udevinfo -a -p /sys/block/sdx | grep SYSFS
until you find all of yours slots.
udevinfo -a -p /sys/block/sda | egrep SYSFS
and look for card type explanation
SYSFS{model}=="Media Inc. CF " where CF stands for Compact Flash.
udevinfo -a -p /sys/block/sdd | grep SYSFS
and look for SYSFS{model}=="Media Inc. SD " where SD is for secure digital
udevinfo -a -p /sys/block/sde | grep SYSFS
and look for SYSFS{model}=="Media Inc. SM/xD" where SM/xD is for Smart media xD-picture card
udevinfo -a -p /sys/block/sdf | grep SYSFS
and look for SYSFS{model}=="Media Inc. MS " where MS is for memory stick.
We have now all that we need of information that's gonna be added to udev rules. The configuration file is going to be placed in /etc/udev/rules.d/ and we are gonna call it 10-udev-early.rules. There are some other files in this directory but we are not gonna use or change anything in them.
The number in front of the name of config file is actually telling the system which of all conf files in this directory is gonna be read first, 5 before 10 and 10 before 50 and so on. So after making new file called 10-udev-early.rules open it in your favorite text editor (for me its nano) and add following lines.
BUS="usb",KERNEL="sd*",SYSFS{idProduct}="6830",NAME="%k",SYMLINK="usbdisk"
BUS="scsi", KERNEL="sd*", SYSFS{model}="Media Inc. CF ", NAME:="sda%n",SYMLINK="CF"
BUS="scsi", KERNEL="sd*", SYSFS{model}="Media Inc. SD ", NAME:="sda%n",SYMLINK="SD"
BUS="scsi", KERNEL="sd*", SYSFS{model}="Media Inc. SM/xD", NAME:="sda%n",SYMLINK="XDSD"
BUS="scsi", KERNEL="sd*", SYSFS{model}="Media Inc. MS ", NAME:="sda%n",SYMLINK="MS"
What does this all mean you ask ? Its self explainable but here are some guidelines about it
BUS = bustype like usb, scsi ...
Kernel = matching the kernel name for the respective device
SYSFS = is already explained earlier in this howto
Name = the name that shall be used for the device node
Symlink = symbolic link which act as alternative names for the device node
After adding things to out conf file we are ready to reload rules for udev and that we can do like this:
udevcontrol reload_rules
after which you are gonna have symlinks for your devices in your /dev/
Now simple mount /dev/CF /mnt/cf is gona mount your CF card to /mnt/cf. To make it even more simple and make it so that users can mount devices self lets add them to /etc/fstab
/dev/hda1 /boot ext3 noauto,noatime 1 2
/dev/hda3 / reiserfs noatime 0 1
/dev/hda2 none swap sw 0 0
/dev/hda4 /home reiserfs noatime 0 1
/dev/hdd /mnt/cdrom iso9660 noauto,ro 0 0
/dev/fd0 /mnt/floppy auto noauto,users 0 0
/dev/CF /mnt/cf auto noauto,users 0 0
/dev/SD /mnt/sd auto noauto,users 0 0
/dev/MS /mnt/ms auto noauto,users 0 0
/dev/XDSD /mnt/xdsd auto noauto,users 0 0
/dev/usbdisk /mnt/usbdisk auto noauto,users 0 0
So now simple mount /dev/usbdisk will mount your usb drive to /mnt/usbdisk
UPDATE: I recently bought a new 250 GB drive which I split into 3 parts, making 3 vfat partitions for my files and other things :) Why vfat you ask? Because I am going to use this both on linux and winblows windows. Having 3 partitions on my usb drive presented a problem for usb-drive line in UDEV rules. It took me a while to figure out this and here is solution.
BUS=="usb", SYSFS{serial}=="DEF10997A434", KERNEL=="sd?", NAME="%k", SYMLINK+="usbdisk", GROUP="storage"
BUS=="usb", SYSFS{serial}=="DEF10997A434", KERNEL=="sd?[1-9]", NAME="%k", SYMLINK+="usbdisk%n", GROUP="storage"
You can make group storage and add your self to it but I think it works with out it too.
Hope this howto helps you get your hardware working with udev.
Author: Adis Beglerovic