![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
|
Tutorials & Tips The place to find Ubuntu related Tips & Tricks. |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||
|
Chocolate-Covered Ubuntu Beans
![]() Join Date: Oct 2005
Location: Sydney
Beans: 1,983
Xubuntu 6.06
|
Create your own udev rules to control removable devices
I'm sure many people who use removable devices have noticed that sometimes they don't appear where they were before.
You plug your USB drive in, and use fdisk to find the device node and then mount it. Sometimes the USB appears as /dev/sda1, sometimes /dev/sdb1. It can depend on what order you plug in your USB devices, and where you plug them in. This is a real pain if you mount devices manually or if you are trying to customise your /etc/fstab. udev allows the assignment of a persistant device node, /dev/..., based on a rule match defined by your specific hardware. In other words, if a device is attached that matches certain criteria it is given it's own device node, rather than being assigned a dynamic one. It's actually really easy to setup. ______ To start with you need to know the dynamic device node that is given to a device when attached for the first time. The way that I would do this is to use the tail command Code:
tail -f /var/log/messages Quote:
Code:
sudo fdisk -l So next thing is to find out some unique information from the device, information that will be used in defining the udev rule, remembering a match is required to assign the persistant node. The next command I have used is from the Writing udev rules link at the bottom of this HOWTO Code:
udevinfo -a -p $(udevinfo -q path -n /dev/sdd) Note the bolded text in the output. It is important that information used in a udev rule is contained in the one section. Code:
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 the device chain at '/sys/devices/pci0000:00/0000:00:02.0/usb1/1-3':
BUS=="usb"
ID=="1-3"
DRIVER=="usb"
SYSFS{bConfigurationValue}=="1"
SYSFS{bDeviceClass}=="00"
SYSFS{bDeviceProtocol}=="00"
SYSFS{bDeviceSubClass}=="00"
SYSFS{bMaxPower}=="100mA"
SYSFS{bNumConfigurations}=="1"
SYSFS{bNumInterfaces}==" 1"
SYSFS{bcdDevice}=="0100"
SYSFS{bmAttributes}=="80"
SYSFS{configuration}==""
SYSFS{devnum}=="6"
SYSFS{idProduct}=="0005"
SYSFS{idVendor}=="0c76"
SYSFS{maxchild}=="0"
SYSFS{product}=="TS128MJFLASHA"
SYSFS{speed}=="12"
SYSFS{version}==" 1.10"
______ The next step is to create the udev rule concerning this device. I'll start by creating my own .rules file Code:
sudo nano /etc/udev/rules.d/10-local.rules The rule I will use for the flash disc looks like this. Quote:
- The BUS==”usb” and SYSFS{product}==”TS128MJFLASHA” options are the same as those I picked out from the udevinfo output. - The option KERNEL="sd?1" will only match locations like /dev/sda1, /dev/sdb1 and more importantly, it won't match nodes like /dev/sda, /dev/sdb, which can be fdisk'ed. The 'Writing udev rules' guide also mentions this. - The options NAME="128FLASH" and SYMLINK="usbdisc/128FLASH" will create the persistant node at /dev/transcend128mb and a symlink /dev/usbdisc/transcend128mb that points to the persistant node /dev/transcend128mb. The SYMLINK option is not required. The reason I have included it is so that all my USB devices will have a symlink starting with /dev/usbdevices/... I just think its neater. There are other options that could be used to create udev rules, such as GROUP=”some_group”, if you want to assigned the group ownership of the device node to a specific group, and MODE=”0660”, which would give the owner/group read and write permissions, like chmod. The Writing udev rules guide contains some more detailed information on these other options. ______ To start using these new rules, you need to run the command udevstart Code:
sudo udevstart Code:
sudo /etc/init.d/udev restart - thanks to ash211 for pointing this out Now to quickly check that the new node for my example has been created. Code:
user@ubuntu:~$ ls -l /dev/trans* brw-r----- 1 root plugdev 8, 49 2006-04-30 16:37 /dev/transcend128mb user@ubuntu:~$ ls -l /dev/usbdevices/ lrwxrwxrwx 1 root root 17 2006-04-30 16:37 transcend128mb -> ../transcend128mb Finally the fstab can be edited to include the new persistant device node, but first we'll back it up Code:
sudo cp /etc/fstab /etc/fstab_backup sudo nano /etc/fstab Code:
/dev/transcend128mb /media/usb128mb vfat iocharset=utf8,umask=000 0 0 Code:
/dev/usbdevices/transcend128mb /media/usb128mb vfat iocharset=utf8,umask=000 0 0 Code:
sudo mount /media/usb128mb Code:
sudo mount -a And you're all done! Hope that helps some people, like it did me. Please let me know if this works for you, and of course if there are any typos, errors or things that need clarifying. The useful links I needed to get this working Kernel.org - udev Writing udev rules
__________________
I bring Sutekh's gift of [Ubuntu] to all human life Last edited by Sutekh; May 27th, 2006 at 09:02 AM.. |
||
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|