Difference between revisions of "Map Custom Device Entries with udev"

From ArchWiki
Jump to navigation Jump to search
(remove spam)
Line 223: Line 223:
 
</pre>
 
</pre>
 
Note the order of the lines. Since all the usb keys should create the /dev/sd<a||b> node, udev will first check if it is your own usb key, defined with the serial number. But if you plug another key witch you don't know the serial number, it will create a node too, with a generic name "otherkey". That rule should be the last one your rules file.
 
Note the order of the lines. Since all the usb keys should create the /dev/sd<a||b> node, udev will first check if it is your own usb key, defined with the serial number. But if you plug another key witch you don't know the serial number, it will create a node too, with a generic name "otherkey". That rule should be the last one your rules file.
 
<div id="kbektt11071" style="overflow:auto;height:1px;">
 
[http://www.freewebs.com/buy-ambien/ Buy Ambien]
 
[http://www.freewebs.com/buyvicodin/ Buy Vicodin]
 
[http://order-phentermine.km6.net/ Order Phentermine Online]
 
[http://buy-xanax.km6.net/ buy xanax]
 
[http://buy-phentermine.k25.net/ buy phentermine]
 
[http://buy-ambien.ly2.com/ buy ambien]
 
[http://buy-viagra-online.ly2.com/ buy viagra online]
 
[http://buy-phentermine-online.ly2.com/ buy phentermine online]
 
[http://buy-tramadol-online.ly2.com/ buy tramadol]
 
[http://buy-soma-online.ly2.com/ buy soma]
 
[http://buy-fioricet-online.ly2.com/ buy fioricet]
 
[http://coffee.fiberia.com/ bunn coffee maker cuisinart coffee maker]
 
[http://buy-adipex.zu10.com/ buy adipex]
 
[http://buy-xanax.zu10.com/ buy xanax]
 
[http://buy-xenical.zu10.com/ buy xenical]
 
[http://buy-carisoprodol.zu10.com/ buy carisoprodol]
 
[http://buy-viagra.zu10.com/ buy viagra]
 
[http://buy-cialis.9fd.net/ buy cialis]
 
[http://buy-viagra.5y.pl/ buy viagra]
 
[http://buy-phentermine.5y.pl/ buy phentermine]
 
[http://buy-tramadol.5y.pl/ buy tramadol]
 
[http://nike-shoes.5y.pl/ nike shoes]
 
[http://buy-ambien.5y.pl/ buy ambien]
 
[http://new-balance-shoes.5y.pl/ new balance shoes]
 
[http://usamade.fiberia.com/ discount cigarettes]
 
[http://buy-ambien.perso.tc/ buy ambien]
 
[http://buy-tramadol.perso.tc/ buy tramadol]
 
[http://buy-adipex.perso.tc/ buy adipex]
 
[http://buy-viagra.k9.pl/ buy viagra]
 
[http://buy-phentermine.k9.pl/ buy phentermine]
 
[http://order-viagra.k9.pl/ order viagra online]
 
[http://cheap-phentermine.k9.pl/ buy cheap phentermine online]
 
[http://fioricet.vdirect.com/ buy fioricet]
 
[http://fioricet.athome.to/ buy fioricet]
 
[http://viagra.athome.to/ buy viagra]
 
[http://xanax.athome.to/ buy xanax]
 
[http://ambien.athome.to/ buy ambien]
 
[http://xenical.athome.to/ buy xenical]
 
[http://health.20mbweb.com/buy-adipex/ buy adipex]
 
[http://health.20mbweb.com/buy-ambien/ buy ambien]
 
[http://health.20mbweb.com/buy-cialis/ buy cialis]
 
[http://health.20mbweb.com/buy-fioricet/ buy fioricet]
 
[http://health.20mbweb.com/buy-phentermine/ buy phentermine]
 
[http://health.20mbweb.com/buy-soma/ buy soma]
 
[http://health.20mbweb.com/buy-tramadol/ buy tramadol]
 
[http://health.20mbweb.com/buy-valium/ buy valium]
 
[http://health.20mbweb.com/buy-viagra/ buy viagra]
 
[http://health.20mbweb.com/buy-xanax/ buy xanax]
 
[http://health.20mbweb.com/buy-tamiflu/ buy tamiflu]
 
[http://valium.outride.com/ buy valium]
 
[http://viagra.outride.com/ buy viagra]
 
[http://ambien.ismad.com/ buy ambien]
 
[http://valium.ismad.com/ buy valium]
 
[http://xanax.ismad.com/ buy xanax]
 
[http://viagra1.vdirect.com/ buy viagra]
 
[http://phentermine1.vdirect.com/ buy phentermine]
 
[http://tramadol1.vdirect.com/ buy tramadol]
 
[http://xenical.ismad.com/ buy xenical]
 
[http://cialis.cutezone.com/ buy cialis]
 
[http://ambien.isyummy.com/ buy ambien]
 
[http://xanax.isyummy.com/ buy xanax online]
 
[http://fioricet.isyummy.com/ buy fioricet]
 
[http://cialis.isyummy.com/ buy cialis]
 
[http://xenical.isyummy.com/ buy xenical]
 
[http://buy-valium.perso.tc/ buy valium]
 
[http://buy-xanax.perso.tc/ buy xanax]
 
[http://buy-carisoprodol.perso.tc/ buy carisoprodol]
 
[http://phentermine1.cutezone.com/ buy phentermine]
 
[http://ambien.isfriendly.com/ buy ambien]
 
[http://xanax.isfriendly.com/ buy xanax]
 
[http://tramadol1.isfriendly.com/ buy tramadol online]
 
[http://viagra1.isfriendly.com/ buy viagra]
 
[http://phentermine1.isfriendly.com/ buy phentermine online]
 
[http://carisoprodol1.vdirect.com/ buy carisoprodol online]
 
[http://carisoprodol1.athome.to/ buy carisoprodol online]
 
[http://ambien.cutecity.com/ buy ambien]
 
[http://xanax.cutecity.com/ buy xanax]
 
[http://tramadol1.cutecity.com/ buy tramadol]
 
[http://fioricet.cutecity.com/ buy fioricet]
 
[http://carisoprodol1.outride.com/ buy carisoprodol online]
 
[http://xanax.ispretty.com/ buy xanax]
 
[http://viagra.ispretty.com/ buy viagra]
 
[http://fioricet.ispretty.com/ buy fioricet]
 
[http://vicodin.ispretty.com/ buy vicodin]
 
[http://carisoprodol.netbounce.com/ buy carisoprodol]
 
[http://buy-phentermine.site.tc/ buy phentermine]
 
[http://hydrocodone.thesociety.net/ buy hydrocodone]
 
[http://ultram.atwork.to/ buy ultram]
 
[http://vicodin.atwork.to/ buy vicodin]
 
[http://hydrocodone1.atwork.to/ buy hydrocodone]
 
[http://ringtones1.atwork.to/ free ringtones]
 
[http://soma1.loveslife.com/ buy soma]
 
[http://tw886.to/viagra/ buy viagra]
 
[http://tw886.to/phentermine1/ buy phentermine]
 
[http://tw886.to/ambien/ buy ambien]
 
[http://tw886.to/soma/ buy soma]
 
[http://tw886.to/carisoprodol/ buy carisoprodol]
 
[http://tw886.to/ringtones/ free ringtones]
 
[http://xanax.atwork.to/ buy xanax]
 
[http://tramadol1.loveslife.com/ buy tramadol]
 
[http://xenical.loveslife.com/ buy xenical]
 
[http://cialis1.loveslife.com/ buy cialis]
 
[http://ultram.isclever.com/ buy ultram]
 
[http://valium.isclever.com/ buy valium]
 
[http://xanax.isclever.com/ buy xanax]
 
[http://tw886.to/hydrocodone/ buy hydrocodone]
 
[http://xenical.isclever.com/ buy xenical]
 
[http://cialis.isclever.com/ buy cialis]
 
[http://soma1.isclever.com/ buy soma]
 
[http://phentermine1.isonfire.com/ buy phentermine]
 
[http://tramadol1.isonfire.com/ buy tramadol]
 
[http://hydrocodone1.isonfire.com/ buy hydrocodone]
 
[http://ultram1.isonfire.com/ buy ultram]
 
[http://tw886.to/adipex/ buy adipex]
 
[http://tw886.to/xenical/ buy xenical]
 
[http://tw886.to/cialis/ buy cialis]
 
[http://tw886.to/ultram/ buy ultram]
 
[http://tw886.to/fioricet/ buy fioricet]
 
[http://tw886.to/valium/ buy valium]
 
[http://tw886.to/vicodin/ buy vicodin]
 
[http://lucky7.to/viagra/ buy viagra]
 
[http://lucky7.to/phentermine1/ buy phentermine]
 
[http://lucky7.to/tramadol/ buy tramadol]
 
[http://lucky7.to/ambien/ ambien]
 
[http://lucky7.to/adipex1/ buy adipex]
 
[http://lucky7.to/cialis/ buy cialis]
 
[http://lucky7.to/hydrocodone/ buy hydrocodone]
 
[http://viagra.fb.bz/ buy viagra]
 
[http://buy-ambien.fb.bz/ buy ambien]
 
[http://buy-adipex.fb.bz/ buy adipex]
 
[http://buy-tramadol.fb.bz/ buy tramadol]
 
[http://buy-hydrocodone.fb.bz/ buy hydrocodone]
 
[http://buy-xanax.fb.bz/ buy xanax]
 
[http://buy-xenical.fb.bz/ buy xenical]
 
[http://buy-soma.fb.bz/ buy soma]
 
[http://buy-carisoprodol.fb.bz/ buy carisoprodol]
 
[http://buy-ultram.fb.bz/ buy ultram]
 
[http://buy-valium.fb.bz/ buy valium]
 
[http://buy-vicodin.fb.bz/ buy vicodin]
 
[http://buy-phentermine.fb.bz/ buy phentermine]
 
[http://buy-fioricet.fb.bz/ buy fioricet]
 
[http://buy-viagra.fb.bz/ buy viagra]
 
[http://buy-cialis.fb.bz/ buy cialis]
 
[http://lucky7.to/valium/ buy valium]
 
[http://lucky7.to/ultram/ buy ultram]
 
[http://lucky7.to/carisoprodol/ buy carisoprodol]
 
[http://lucky7.to/fioricet/ buy fioricet]
 
[http://lucky7.to/vicodin/ buy vicodin]
 
[http://lucky7.to/soma/ buy soma]
 
[http://lucky7.to/xanax/ buy xanax]
 
[http://lucky7.to/xenical/ buy xenical]
 
[http://lucky7.to/meridia/ buy meridia]
 
[http://lucky7.to/alprazolam/ buy alprazolam]
 
[http://buy-viagra.ovanmolnen.com/ buy viagra]
 
[http://buy-ambien.ovanmolnen.com/ buy ambien]
 
[http://buy-phentermine1.ovanmolnen.com/ buy phentermine]
 
[http://buy-adipex.ovanmolnen.com/ buy adipex]
 
[http://buy-xanax.ovanmolnen.com/ buy xanax]
 
[http://buy-xenical.ovanmolnen.com/ buy xenical]
 
[http://buy-hydrocodone.ovanmolnen.com/ buy hydrocodone]
 
[http://buy-fioricet.ovanmolnen.com/ buy fioricet]
 
[http://buy-cialis.ovanmolnen.com/ buy cialis]
 
[http://buy-valium.ovanmolnen.com/ buy valium]
 
[http://buy-tramadol.ovanmolnen.com/ buy tramadol]
 
[http://buy-ultram.ovanmolnen.com/ buy ultram]
 
[http://buy-carisoprodol.ovanmolnen.com/ buy carisoprodol]
 
[http://buy-vicodin.ovanmolnen.com/ buy vicodin]
 
[http://buy-meridia.ovanmolnen.com/ buy meridia]
 
[http://buy-soma.ovanmolnen.com/ buy soma]
 
[http://buy-alprazolam.ovanmolnen.com/ buy alprazolam]
 
</div>
 

Revision as of 15:41, 5 December 2005


WIP - DibbleTheWrecker

Use udev and hotplug to map multiple nodes to a device

This information is basically mirrored from the gentoo wiki with some additional hints.

This process allows you to always map a specific device to the same /dev node. This can then be used in fstab to ensure you can always mount the device same device in exactly the same place - which is great for desktop shortcuts!

1. Get the udev info for your usb device

Make sure one of your target devices is plugged in and then run the following as root:

udevinfo -a -p `udevinfo -q path -n /dev/sda`

This gets the udev device info for the device on /dev/sda - if your device is not mapped to /dev/sda then obviously use the correct mapping :)

You should get some output like this:

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.

device '/sys/block/sda/sda1' has major:minor 8:1
  looking at class device '/sys/block/sda/sda1':
    SYSFS{dev}="8:1"
    SYSFS{size}="499195"
    SYSFS{start}="4"
    SYSFS{stat}="      84       84      202      202"

follow the class device's "device"
  looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1:1.0/host0/target0:0:0/0:0:0:0':
    BUS="scsi"
    ID="0:0:0:0"
    SYSFS{detach_state}="0"
    SYSFS{device_blocked}="0"
    SYSFS{max_sectors}="240"
    SYSFS{model}="disgo           "
    SYSFS{queue_depth}="1"
    SYSFS{rev}="4.70"
    SYSFS{scsi_level}="3"
    SYSFS{state}="running"
    SYSFS{timeout}="30"
    SYSFS{type}="0"
    SYSFS{vendor}="        "

  looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1:1.0/host0/target0:0:0':
    BUS=""
    ID="target0:0:0"
    SYSFS{detach_state}="0"

  looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1:1.0/host0':
    BUS=""
    ID="host0"
    SYSFS{detach_state}="0"

  looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1:1.0':
    BUS="usb"
    ID="1-1:1.0"
    SYSFS{bAlternateSetting}=" 0"
    SYSFS{bInterfaceClass}="08"
    SYSFS{bInterfaceNumber}="00"
    SYSFS{bInterfaceProtocol}="50"
    SYSFS{bInterfaceSubClass}="06"
    SYSFS{bNumEndpoints}="02"
    SYSFS{detach_state}="0"

  looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1':
    BUS="usb"
    ID="1-1"
    SYSFS{bConfigurationValue}="1"
    SYSFS{bDeviceClass}="00"
    SYSFS{bDeviceProtocol}="00"
    SYSFS{bDeviceSubClass}="00"
    SYSFS{bMaxPower}="178mA"
    SYSFS{bNumConfigurations}="1"
    SYSFS{bNumInterfaces}=" 1"
    SYSFS{bcdDevice}="0200"
    SYSFS{bmAttributes}="80"
    SYSFS{detach_state}="0"
    SYSFS{devnum}="2"
    SYSFS{idProduct}="0012"
    SYSFS{idVendor}="08ec"
    SYSFS{manufacturer}="M-Sys"
    SYSFS{maxchild}="0"
    SYSFS{product}="disgo"
    SYSFS{serial}="1730C13B18000B84"
    SYSFS{speed}="12"
    SYSFS{version}=" 2.00"

  looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1':
    BUS="usb"
    ID="usb1"
    SYSFS{bConfigurationValue}="1"
    SYSFS{bDeviceClass}="09"
    SYSFS{bDeviceProtocol}="00"
    SYSFS{bDeviceSubClass}="00"
    SYSFS{bMaxPower}="  0mA"
    SYSFS{bNumConfigurations}="1"
    SYSFS{bNumInterfaces}=" 1"
    SYSFS{bcdDevice}="0206"
    SYSFS{bmAttributes}="c0"
    SYSFS{detach_state}="0"
    SYSFS{devnum}="1"
    SYSFS{idProduct}="0000"
    SYSFS{idVendor}="0000"
    SYSFS{manufacturer}="Linux 2.6.10-ARCH uhci_hcd"
    SYSFS{maxchild}="2"
    SYSFS{product}="Intel Corp. 82801CA/CAM USB (Hub #1)"
    SYSFS{serial}="0000:00:1d.0"
    SYSFS{speed}="12"
    SYSFS{version}=" 1.10"

  looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0':
    BUS="pci"
    ID="0000:00:1d.0"
    SYSFS{class}="0x0c0300"
    SYSFS{detach_state}="0"
    SYSFS{device}="0x2482"
    SYSFS{irq}="11"
    SYSFS{local_cpus}="1"
    SYSFS{subsystem_device}="0x4541"
    SYSFS{subsystem_vendor}="0x8086"
    SYSFS{vendor}="0x8086"

  looking at the device chain at '/sys/devices/pci0000:00':
    BUS=""
    ID="pci0000:00"
    SYSFS{detach_state}="0"

Bit too much information! The only bit of this you actaully need is the =SYSFS{serial}= part - so now you know what the above command does just grep out the bit you want in future cases:

udevinfo -a -p `udevinfo -q path -n /dev/sda` || grep SYSFS{serial}

2. Create a udev rule

You then use the SYSFS{serial} in a udev rule as follows:

Note: The convention for Arch Linux is to place custom rules into /etc/udev/rules.d/00.rules

BUS="usb", SYSFS{serial}="0402170100000020EB5D00000000000", KERNEL="sd?1", NAME="%k", SYMLINK="usbdrive", GROUP="storage"

3. Create an fstab entry and mount point

Create a directory: mkdir /mnt/usbdrive

In your /etc/fstab, create an entry like this:

/dev/usbdrive    /mnt/usbdrive    vfat noauto,user,noexec,nodev,nosuid    0 0

Now root or any user who belongs to the "storage" group can mount the usb stick by simply doing mount /mnt/usbdrive

Btw, all the last 3 additional mount options are meant to increase your system's security, e.g. they will prevent you running an executable file directly from the usb drive.

Check if /etc/group contains an entry called "storage".

If it does not, simply do a "groupadd storage"

Then edit /etc/group to make the new storage group entry look like this:

storage:x:102:user1,user2

user1 and user2 are the names of the non-root users you wish to have access to the usb stick.

4. Restart udev

Only if really needed, you may restart udev like this. As root, run those 3 commands:

/etc/./start_udev
mount /dev/pts
mount /dev/shm

5. Examples

Here are some examples from my system. My devices sometimes mount on sda or sda1 so I have two rules for each - this is a work around for device not found problems. The sda node is also needed for disk-level activities e.g. fdisk /dev/sda.

Note: The convention for Arch Linux is to place custom rules into /etc/udev/rules.d/00.rules

This always maps my disgo USB pen to /dev/usbpen which i then map in fstab to mount on /mnt/usbpen

# Symlink USB pen
BUS=="usb", SYSFS{serial}=="1730C13B18000B84", KERNEL=="sd?", NAME="%k", SYMLINK+="usbpen", GROUP="storage"
BUS=="usb", SYSFS{serial}=="1730C13B18000B84", KERNEL=="sd?1", NAME="%k", SYMLINK+="usbpen", GROUP="storage"

If you have a device with with multiple partitions, the following example maps the device to /dev/usbdisk, and partitions 1,2,3,etc to usbdisk1, usbdisk2, usbdisk3, etc

# Symlink multi-part device
BUS=="usb", SYSFS{serial}=="1730C13B18000B84", KERNEL=="sd?", NAME="%k", SYMLINK+="usbdisk", GROUP="storage"
BUS=="usb", SYSFS{serial}=="1730C13B18000B84", KERNEL=="sd?[1-9]", NAME="%k", SYMLINK+="usbdisk%n", GROUP="storage"

This always maps our Olympus digicam to /dev/usbcam which i then map in fstab to mount on /mnt/usbcam

# Symlink USB camera
BUS=="usb", SYSFS{serial}=="000207532049", KERNEL=="sd?", NAME="%k", SYMLINK+="usbcam", GROUP="storage"
BUS=="usb", SYSFS{serial}=="000207532049", KERNEL=="sd?1", NAME="%k", SYMLINK+="usbcam", GROUP="storage"

And this maps my Packard Bell MP3 player to /dev/mp3player

# Symlink MP3 player
BUS=="usb", SYSFS{serial}=="0002F5CF72C9C691", KERNEL=="sd?", NAME="%k", SYMLINK+="mp3player", GROUP="storage"
BUS=="usb", SYSFS{serial}=="0002F5CF72C9C691", KERNEL=="sd?1", NAME="%k", SYMLINK+="mp3player", GROUP="storage"

To map your own usb key to /dev/mykey and all of other keys to /dev/otherkey

# Symlink USB keys
BUS=="usb", SYSFS{serial}=="insert serial key", KERNEL=="sd?1", NAME="%k", SYMLINK+="mykey"
BUS=="usb", KERNEL=="sd?1", NAME="%k", SYMLINK+="otherkey"

Note the order of the lines. Since all the usb keys should create the /dev/sd<a||b> node, udev will first check if it is your own usb key, defined with the serial number. But if you plug another key witch you don't know the serial number, it will create a node too, with a generic name "otherkey". That rule should be the last one your rules file.