Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Udev rule is not working

I have set CFQ as the default I/O scheduler. I often get bad performance when I write data into a Flash device. This is resolved if I use deadline as the I/O scheduler for USB Flash devices. I can't always change the scheduler manually, right? I think writing udev rules is a good idea.

Can someone please write rules for me? I want:

  1. When I plug in a USB device, detect the type of the device.
  2. If it is a portable USB hard disk, do nothing (I think if a device has more than one partitions, it always a portable hard disk.
  3. If it is a USB Flash device, set deadline as it's scheduler.
share|improve this question

marked as duplicate by Tom Wijsman, soandos, Indrek, 8088, MaQleod Oct 3 '12 at 17:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Have you read the udev manual? Have you tried the udev monitor? Have you tried creating a rule? What is the exact actual practical problem that you are experiencing? We can't see your hardware, thus not write rules. – Tom Wijsman Sep 30 '12 at 15:20
Actually, I read lots of article about USB & udev. But they just try to detect new device of /dev/sdx, no matter a USB device or something else. – 比尔盖子 Sep 30 '12 at 16:19
Ok. I read a lots of f**king manuals. And I know how to write the rules now. But udev does not seem to see my rules (any rule), It not working at all. Please see the question – 比尔盖子 Oct 1 '12 at 14:42
If you were to use udevadm monitr like the manuals tell you, you wouldn't put ?? into your rules. – Tom Wijsman Oct 1 '12 at 15:18
up vote 1 down vote accepted

First, put the shell script scheduler4usb into $PATH (e.g: /usr/bin):

# Usage: ./script device scheduler

# If your are using util-linux 2.22, you must change this line to:
# fdisk /dev/$1 -l 2>&1 >/dev/null | grep -q "doesn't contain a valid partition table"
fdisk /dev/$1 -l 2>&1 >/dev/null | grep -q "This doesn't look like a partition table"

# If this device has a partition table.
if (($?==0)); then 
    echo $2 > /sys/block/$1/queue/scheduler


Don't forget to chmod +x scheduler4usb to your script!

Then, write the rule into /etc/udev/rules.d/91-change-schduler.rules:

SUBSYSTEMS=="usb", ACTION=="add", KERNEL=="sd?", RUN+="/usr/local/bin/scheduler4usb %k deadline"
share|improve this answer
Instead of RUN+="some_script" you can directly modify the sysfs attributes: ..., ATTR{queue/scheduler}="deadline" – hurikhan77 Mar 2 at 17:31

Not the answer you're looking for? Browse other questions tagged .