Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating an udev rule for mounting one particular usb stick and discourage HAL from doing so

13 views
Skip to first unread message

boehme...@web.de

unread,
Apr 18, 2008, 9:45:49 AM4/18/08
to
Hello Gentoo people,

I have a quite special situation where I need to usage of udev rules.
I have already read some documentation and stuff about udev but there
are still three problems to be solved:
(1) I need a udev rule which works for one particular usb stick.
(2) My Xfce4 automagically mounts and opens usb drives when plugged
in. This should NOT happen when I plug in this particular device.

For everybody interested the long explanation: I do own a notebook
with fingerprint reader which is used for system authentification. For
security reasons there is an encrypted partition on the laptop which
is mounted to /home/daniel/crypted/ whenever I need it. Important is
that I do not need to mount it for starting my desktop environment and
surfing the net. But it was pretty useless to use the fingerprint
reader to authentification and entering a password later on in order
to mount the partition. Therefor I decided to get some usb sticks
which contain a 1024 byte encryption key.


When the usb stick is plugged in it should be recognized, the
encrypted partition be mounted and HAL/Xfce4 discouraged from opening
the stick. When the partition is mounted I will plug off my usb stick.

I have a script which umounts the encrypted partition when I run
suspend2ram or lock my X session. It would be nice to have a
possibility to check whether this particular usb stick is still
connected when the script runs. If it is safe to leave the stick on
the notebook it is safe to leave the encrypted partition mounted.


Well, this is a bunch of information and, in my point of view, a
pretty complex project. I hope somebody is familiar with udev and
likely to help me with this. I think I will be able to write an udev
rule recognizing my stick in the end but I do not have any clue how to
control HAL/Xfce and how to check the appearance of the stick later
on.

At last I post udevinfo of my usb device:


udevinfo -a -p /sys/block/sdb/sdb1

Udevinfo starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

looking at device '/block/sdb/sdb1':
KERNEL=="sdb1"
SUBSYSTEM=="block"
DRIVER==""
ATTR{dev}=="8:17"
ATTR{start}=="35"
ATTR{size}=="9765"
ATTR{stat}==" 570 570 0 0"

looking at parent device '/block/sdb':
KERNELS=="sdb"
SUBSYSTEMS=="block"
DRIVERS==""
ATTRS{dev}=="8:16"
ATTRS{range}=="16"
ATTRS{removable}=="1"
ATTRS{size}=="1998080"
ATTRS{stat}==" 25 554 642 42 0
0 0 0 0 36 42"
ATTRS{capability}=="13"

looking at parent device '/devices/pci0000:00/0000:00:1d.7/
usb2/2-2/2-2:1.0/host28/target28:0:0/28:0:0:0':
KERNELS=="28:0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS=="sd"
ATTRS{device_blocked}=="0"
ATTRS{type}=="0"
ATTRS{scsi_level}=="3"
ATTRS{vendor}=="USB2.0 "
ATTRS{model}=="FlashDisk "
ATTRS{rev}=="1.00"
ATTRS{state}=="running"
ATTRS{timeout}=="60"
ATTRS{iocounterbits}=="32"
ATTRS{iorequest_cnt}=="0x55"
ATTRS{iodone_cnt}=="0x55"
ATTRS{ioerr_cnt}=="0x1"
ATTRS{modalias}=="scsi:t-0x00"
ATTRS{evt_media_change}=="0"
ATTRS{queue_depth}=="1"
ATTRS{queue_type}=="none"
ATTRS{max_sectors}=="240"

looking at parent device '/devices/pci0000:00/0000:00:1d.7/
usb2/2-2/2-2:1.0/host28/target28:0:0':
KERNELS=="target28:0:0"
SUBSYSTEMS==""
DRIVERS==""
ATTRS{uevent}==""

looking at parent device '/devices/pci0000:00/0000:00:1d.7/
usb2/2-2/2-2:1.0/host28':
KERNELS=="host28"
SUBSYSTEMS==""
DRIVERS==""
ATTRS{uevent}==""

looking at parent device '/devices/pci0000:00/0000:00:1d.7/
usb2/2-2/2-2:1.0':
KERNELS=="2-2:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="usb-storage"
ATTRS{bInterfaceNumber}=="00"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bNumEndpoints}=="02"
ATTRS{bInterfaceClass}=="08"
ATTRS{bInterfaceSubClass}=="06"
ATTRS{bInterfaceProtocol}=="50"
ATTRS{modalias}=="usb:v1516p8628d0200dc00dsc00dp00ic08isc06ip50"

looking at parent device '/devices/pci0000:00/0000:00:1d.7/
usb2/2-2':
KERNELS=="2-2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{dev}=="189:140"
ATTRS{configuration}==""
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bmAttributes}=="80"
ATTRS{bMaxPower}=="100mA"
ATTRS{urbnum}=="270"
ATTRS{idVendor}=="1516"
ATTRS{idProduct}=="8628"
ATTRS{bcdDevice}=="0200"
ATTRS{bDeviceClass}=="00"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{speed}=="480"
ATTRS{busnum}=="2"
ATTRS{devnum}=="13"
ATTRS{version}==" 2.00"
ATTRS{maxchild}=="0"
ATTRS{quirks}=="0x2"
ATTRS{authorized}=="1"
ATTRS{manufacturer}=="USB2.0"
ATTRS{product}=="FlashDisk"
ATTRS{serial}=="000000000000001000002CB0"

looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb2':
KERNELS=="usb2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{dev}=="189:128"
ATTRS{configuration}==""
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bmAttributes}=="e0"
ATTRS{bMaxPower}==" 0mA"
ATTRS{urbnum}=="502"
ATTRS{idVendor}=="0000"
ATTRS{idProduct}=="0000"
ATTRS{bcdDevice}=="0206"
ATTRS{bDeviceClass}=="09"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="01"
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{speed}=="480"
ATTRS{busnum}=="2"
ATTRS{devnum}=="1"
ATTRS{version}==" 2.00"
ATTRS{maxchild}=="6"
ATTRS{quirks}=="0x0"
ATTRS{authorized}=="1"
ATTRS{manufacturer}=="Linux 2.6.24-tuxonice-r4 ehci_hcd"
ATTRS{product}=="EHCI Host Controller"
ATTRS{serial}=="0000:00:1d.7"
ATTRS{authorized_default}=="1"

looking at parent device '/devices/pci0000:00/0000:00:1d.7':
KERNELS=="0000:00:1d.7"
SUBSYSTEMS=="pci"
DRIVERS=="ehci_hcd"
ATTRS{vendor}=="0x8086"
ATTRS{device}=="0x2836"
ATTRS{subsystem_vendor}=="0x17aa"
ATTRS{subsystem_device}=="0x20ab"
ATTRS{class}=="0x0c0320"
ATTRS{irq}=="21"
ATTRS{local_cpus}=="3"

ATTRS{modalias}=="pci:v00008086d00002836sv000017AAsd000020ABbc0Csc03i20"
ATTRS{enable}=="1"
ATTRS{broken_parity_status}=="0"
ATTRS{msi_bus}==""

looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
ATTRS{uevent}==""

I will be thankful for any help!
Greetings
Daniel Böhmer, Germany

Klaus Dahlke

unread,
Apr 18, 2008, 4:25:37 PM4/18/08
to
On Fri, 18 Apr 2008 06:45:49 -0700, boehmerdaniel wrote:

> Hello Gentoo people,
>
> I have a quite special situation where I need to usage of udev rules. I
> have already read some documentation and stuff about udev but there are
> still three problems to be solved: (1) I need a udev rule which works
> for one particular usb stick. (2) My Xfce4 automagically mounts and
> opens usb drives when plugged in. This should NOT happen when I plug in
> this particular device.

Hi Daniel
I have quite some success to use SYSFS{serial} to identify a particular.
IIRC, you can combine that also with additional identifiers like PRODUCT
so that the combination is most likely unique

Here a line from my udev rules:
BUS=="scsi", SYSFS{serial}=="073801503876", NAME="%k", SYMLINK="usbstick"

Cheers,
Klaus

0 new messages