Score:0

Udev rule for USB storage device and partitions

sy flag

I am trying to set up a udev rule which symlinks /dev/sda to /dev/cm, /dev/sda1 to /dev/cm1 and /dev/sda2 to /dev/cm2. Of course, depending on what else is connected to the computer, instead of sda, the device could turn up as sdb or anything else. So I have this rule:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0a5c", ATTRS{idProduct}=="0001", GROUP="disk", SYMLINK+="cm"

This rule matches my device and yields the /dev/cm symlink to the correct device node, but not /dev/cm1 or /dev/cm2, even though I can see that /dev/sda1 and /dev/sda2 have turned up. What am I missing?

Score:0
sy flag

Here is one solution:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0a5c", ATTRS{idProduct}=="0001", GROUP="disk", SYMLINK+="cm%n"

See? the symlink name is not cm, but cm%n. Apparently the %n is the name of the partition. For me, this rule yields the following symlink:

  • /dev/cm
  • /dev/cm0 (this one points to /dev/sg0, which is apparently the generic SCSI layer)
  • /dev/cm1 (points to the first partition)
  • /dev/cm2 (points to the second partition)

https://wiki.debian.org/udev is where to go to learn some of this.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.