6

I have a Ubuntu 8.04 LTS (server edition), and I need to write a udev rule for it to act upon plugging a USB thumb drive. However, I need a different action depending on the filesystem of the drive. I know I can use the ID_FS_TYPE environment variable to check for the filesystem on the drive.

Following instructions found here, I try a dummy udev rule as such :

KERNEL!="sd[a-z][0-9]", GOTO="my_udev_rule_end"
ACTION=="add", RUN+="/usr/bin/touch /tmp/test_udev_%E{ID_FS_TYPE}"
ACTION=="add", ENV{ID_FS_TYPE}=="vfat", RUN+="/usr/bin/touch /tmp/test_udev_it_works"
LABEL="my_udev_rule_end"

However, when I plug in a thumb drive with a vfat filesystem (which should trigger both rules), I end up with a file called /tmp/test_udev_vfat, meaning the first rule was triggered successfully, and that the ID_FS_TYPE environment variable is "vfat", but I don't have the other file, meaning that although I know the ID_FS_TYPE env variable is "vfat", I can't seem to check against it for a match.

I tried googling the thing, but pretty much every result seems to assume ENV{ID_FS_TYPE}=="vfat" works. I also tested the exact same udev rule on Ubuntu 10.04 LTS server, and I have the same result.

I'm probably missing something very simple, but I just don't get it. Does anyone see what is wrong with my udev rule that would prevent it from matching on ENV{ID_FS_TYPE}?

Thanks.

Fred
  • 303
  • 1
  • 4
  • 7
  • What happens if you reverse the order of the two? I can't see anything that should cause a problem. Check the file for extraneous white space and DOS/Windows line endings. – Dennis Williamson Jan 27 '11 at 00:01
  • 1
    @Dennis Williamson : same behavior when I switch the order. Also, there are no extra white spaces. I tried launching a script that dumps the environment in a file instead of using touch, and the environment clearly shows ID_FS_TYPE is vfat with no extra space or odd line endings. – Fred Jan 27 '11 at 19:01

2 Answers2

1

Try adding the following line at the start of your file:

IMPORT{program}="/sbin/blkid -o udev -p %N"

JamieH
  • 111
  • 1
  • # /sbin/blkid -o udev -p /dev/sda1 : Invalid output format udev. Chose from value, device, or full – Fred Feb 17 '11 at 16:20
  • 1
    Apologies, this works for me with Ubuntu 10.10 but it looks like 8.04 uses an older version – JamieH Feb 18 '11 at 15:45
0

Did you try to add this line?

KERNEL=="sd[a-z][]", IMPORT{program}="/lib/udev/vol_id /dev/%k"

You may locate "vol_id" at other place.