Home page Latest blog

slef-reflections on Device Drivers

USB Flash Sticks

Fringe Benefits of LUGs: USB Flash Stick Devices

2007-09-03 (Permalink): Here's my latest silly trick with the udev rules discussed previously.

Add a udev rule of ACTION=="add", KERNEL=="sd*[!0-9]", ENV{ID_SERIAL}=="10d6_USB_2.0(HS)_Flash_Disk_A00000000001", RUN+="/usr/local/bin/dapsync" where dapsync is something like this script:-

/sbin/mount /mnt/USB-DAP \
&& cd /opt/Podcasts \
&& { /bin/tar --create --remove-files * \
     | /bin/tar --extract --directory /Mount/USB-DAP }
/sbin/umount /Mount/USB-DAP \
&& /bin/ogg123 -q /home/mjr/House/Audio/three-note.ogg

and fstab has a line for /Mount/USB-DAP pointing to the right device/location thing in /dev/disk/by-id

Then, build up podcasts under /opt/Podcasts, plug the audio player 10d6_USB_2.0(HS)_Flash_Disk_A00000000001 into the right port and wait for the three notes to play...

  • Comment on this

2007-08-17 (Permalink): I might be the last to notice, but when trying to answer the LUG question

"All I want to do is mount a particular USB stick to a directory /mnt/particular_usb_stick/ without having to go check on what device it is and editing the script that does the mounting every time."

I discovered that I seem to have a /dev/disk/by-id/usb- 0930_USB_Flash_Memory_LONGHEXSTRING-part1 and an even less meaningful (but hopefully globally unique) /dev/disk/by-uuid/ device by default already.

That'll make a lot of things much simpler.

Didier Raboud commented:

"For the USB Flash disks, why not use udev rules ? It allows to create correct /dev/* nodes and then automatic mounters (KDE's, ...) mount them on the right place...

I once had a device I wanted to be mounted under /media/iaudio. I created the correct udev rule to get /dev/iaudio addressing always the same device and partition, when connected. KDE was then able to mount it on /media/iaudio (visibly taken from node name).

Hope it helps, regards,


Thanks. The by-id device is created by udev rules, but who needs KDE to auto- mount it? I added a line to my udev rules.d/99-local

"ACTION=="add", KERNEL=="sd*[0-9]", ENV{ID_SERIAL}=="0930_USB_Flash_Memory_LOGHEXSTRING", RUN+="/sbin/mount /Mount/BlueKey""

and a matching line to fstab

"/dev/disk/by-id/usb-0930_USB_Flash_Memory_LOGHEXSTRING-part1 /Mount/BlueKey auto rw,noauto,users,uid=1000,noexec,iocharset=utf8 1 0"

and that seems to work. It would be clever to use automount, which would also sync and unmount it after inactivity, but I don't have it installed on that machine.

Simon Ward commented:

"usbmount is a package I find useful, and doesn't depend on your choice of desktop environment. When a USB storage device is inserted, it will get mounted. Hooks can be used to create symlinks at mount time. There is one that links by model name included in the package. I also have another hook that creates a symlink based on the volume label."

Its homepage suggests its author has abandoned it:

"Many distributions are now adequately handling usb - so I haven't spent much time improving usb-mount."

What does usbmount give that automount wouldn't?

Simon Ward commented:

"(I did not realise that usb-mount is no longer maintained.) usb-mount's main advantage is that it did something useful without configuration: simply by installing it you get USB devices automatically mounted when they are plugged in, and symlinks created based on model name. A mere copy-paste-modify was required to get symlinks created for volume labels.

I think automount can do just as well (better, given that it will unmount the device after inactivity), but requires a little more thought to set up."

Ben Hutchings commented:

"The identifiers used under /dev/disk/by-id encode location, including in this case which USB port is being used. You will probably do better to use the filesystem's label or UUID. Rather than writing out /dev/disk/... you can specify LABEL=<label> or UUID=<uuid> in place of a device name in fstab (or on a mount command line, though this doesn't seem to be documented)."

I always seem to plug devices into the same ports, so it didn't bother me much.

Oracom ORC-200M Media Player with Linux usb-storage driver

2007-07-03: Now that my Samsung YP-U2 was destroyed, I'm left with the Oracom ORC-200M USB Audio Player that I was given a while ago.

It seems that this doesn't work with recent 2.6 kernels. Tales of brokenness abound on livejournal, in ubuntu forums, and in Gentoo forums.

Its USB ID (in lsusb or /proc/bus/usb/devices) is 0f19:0103 and there is a patch available for 0f19:0101, which is the similar ORC-100 and DION-MX player. Simply changing the ID and using that patch didn't work for me. I could see the device appear in /proc/scsi/usb- storage (which was new), but still nothing in /proc/scsi/scsi, so I updated the patch slightly.

The new patch for linux- is:

--- linux/drivers/usb/storage/unusual_devs.h.orig       2007-07-03 18:44:59.000000000 +0100
+++ linux/drivers/usb/storage/unusual_devs.h    2007-07-03 19:01:47.000000000 +0100
@@ -1317,6 +1317,16 @@
                US_SC_DEVICE, US_PR_DEVICE, NULL,

+/* Patch by Leonid Petrov mail at
+ *
+ * Updated to 103 device by MJ Ray mjr at
+ */
+UNUSUAL_DEV(  0x0f19, 0x0103, 0x0100, 0x0100,
+               "Oracom Co., Ltd",
+               "ORC-200M",
+                US_SC_DEVICE, US_PR_DEVICE, NULL,
 /* David Kuehling <>:
  * for MP3-Player AVOX WSX-300ER (bought in Japan).  Reports lots of SCSI
  * errors when trying to write.

Hope that helps someone else. Leave a comment if you have any improvements, please. I don't really know what I'm doing with USB and I didn't find descriptions of the usb-storage flags (US_FL_ right?). I just experimented until it worked.

If you need to learn how to patch, here are the notes that I sent an introduction to koha-devel in March:


"I can't find the guide that I mentioned on IRC, but those looking for tips on better use of diff and patch may find them in this book

"Comparing and Merging Files with GNU diff and patch"

by David MacKenzie, Paul Eggert, and Richard Stallman

My most frequent commands are:

1. generating a patch of changes to one file: cp file file.orig ; edit file ; diff -u file.orig file | tee file.patch

2. generating a patch of all changes in a directory: diff -ruN dir.orig dir.mod > all-changes-in-dir.patch

3. applying a patch to a file: patch file < file.patch

4. applying a patch to a directory: cd dir && patch -p1 < /tmp/all- changes-in-dir.patch

5. reversing that patch out again when it doesn't work: cd dir && patch -Rp1 < /tmp/all-changes-in-dir.patch

There are some handy cvs diff commands:

1. cvs diff -u file # changes since last commit

2. cvs diff -r1.1 -r1.2 -u file # changes between given revisions

and with git:

1. git diff -u file # changes since last commit

2. git diff -u rel22 master file # changes between given branches

This can also give a crude way to reverse a change: use diff to make a patch file and then feed it to patch -R... but there are usually better ways, like cvs update's merge options and git revert.

If you are using patch files without revision control much, you may find wiggle helpful.

Ask questions and I'll try to answer. Mangling files is one thing I have had far too much practice at!"

Comment form for non-frame browsers.

Comments are moderated (damn spammers) but almost anything sensible gets approved (albeit eventually). If you give a web address, I'll link it. I won't publish your email address unless you ask me to, but I'll email you a link when the comment is posted, or the reason why it's not posted.

This is copyright 2007 MJ Ray. See fuller notice on front page.