View previous topic :: View next topic |
Author |
Message |
graffitici Tux's lil' helper
Joined: 04 Feb 2004 Posts: 136 Location: Istanbul-Turkey
|
Posted: Sun Jul 08, 2007 5:25 pm Post subject: udev mix-match udevinfo sections for external hdd [SOLVED] |
|
|
Hi,
I just bought a new hard-drive which I connected to my laptop using a USB enclosure. fdisk -l shows it correctly, so I managed to mount it, partition it etc.. Everything fine there. Then I decided to write some udev rules so that I can differentiate between the new one, and my previous external hdd. I wrote rules before for my old drive, but as I was going over them I realized they weren't supposed to be working! Here's what I had for my previous drive:
Code: |
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0402", ATTRS{dev}=="8:5", NAME="%k", SYMLINK="external_hdd/music"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0402", ATTRS{dev}=="8:6", NAME="%k", SYMLINK="external_hdd/movies"
|
The problem with this is that when looking at the udevinfo output on /dev/sda5 say, SUBSYSTEMS=="usb" is not in the same section as ATTRS(idVendor) or ATTRS(dev). The HOWTO on Gentoo WIKI states that generally this wouldn't work, but I suppose in this case it did work. I tried to fix it, but I couldn't find any way of differentiating between the different partitions, while staying in the same "section" (or sysfs node). I ran
Code: |
udevinfo -a -p `udevinfo -q path -n /dev/sdb5` > sdb5
udevinfo -a -p `udevinfo -q path -n /dev/sdb6` > sdb6
diff sdb5 sdb6
|
Here's the output of that
Code: |
8,9c8,9
< looking at device '/block/sdb/sdb5':
< KERNEL=="sdb5"
---
> looking at device '/block/sdb/sdb6':
> KERNEL=="sdb6"
12,15c12,15
< ATTR{stat}==" 166 332 0 0"
< ATTR{size}=="419424894"
< ATTR{start}=="126"
< ATTR{dev}=="8:21"
---
> ATTR{stat}==" 190 380 0 0"
> ATTR{size}=="136311462"
> ATTR{start}=="419425083"
> ATTR{dev}=="8:22"
|
ATTR{dev} is not reliable, since when I connect the other drive first, it also gets a value of "8:21" and "8:22." The KERNEL name is also useless, since it's dependent on the order with which the drives are connected to the system (the very problem we need to avoid). The size and start values can be used, but I don't want to rewrite rules whenever I re-partition the drive.
So how should I go about writing these rules for my external hard drives?
Do I have to use information from different sections in udevinfo?
Thanks for your help,
Berk
Last edited by graffitici on Sun Jul 08, 2007 9:24 pm; edited 1 time in total |
|
Back to top |
|
|
PaulBredbury Watchman
Joined: 14 Jul 2005 Posts: 7310
|
Posted: Sun Jul 08, 2007 5:34 pm Post subject: |
|
|
Use "size".
I would exclude "dev". |
|
Back to top |
|
|
graffitici Tux's lil' helper
Joined: 04 Feb 2004 Posts: 136 Location: Istanbul-Turkey
|
Posted: Sun Jul 08, 2007 6:02 pm Post subject: |
|
|
PaulBredbury wrote: | Use "size".
I would exclude "dev". |
Is that the typical approach when connecting external drives? Because I'm sure thousands have had to overcome this problem. And honestly I am not quite satisfied with that, because it uses a quantity that is prone to changing.... |
|
Back to top |
|
|
PaulBredbury Watchman
Joined: 14 Jul 2005 Posts: 7310
|
Posted: Sun Jul 08, 2007 6:11 pm Post subject: |
|
|
The size will only change if the disk is repartitioned/reformatted.
The options are limited, as udevinfo shows. |
|
Back to top |
|
|
graffitici Tux's lil' helper
Joined: 04 Feb 2004 Posts: 136 Location: Istanbul-Turkey
|
Posted: Sun Jul 08, 2007 6:19 pm Post subject: |
|
|
PaulBredbury wrote: | The size will only change if the disk is repartitioned/reformatted.
The options are limited, as udevinfo shows. |
That's precisely why I am not too satisfied with it. I don't want to think about this once I set it. So would it not work to use values from different sections of the udevinfo output? For instance I could then match the whole hard drive using the modelname, and then the specific partition using KERNEL=="sd?5" and so on?
Thanks a lot for the help by the way! |
|
Back to top |
|
|
graffitici Tux's lil' helper
Joined: 04 Feb 2004 Posts: 136 Location: Istanbul-Turkey
|
Posted: Sun Jul 08, 2007 6:22 pm Post subject: |
|
|
I also just realized that two of my partitions have the exact same size attribute... |
|
Back to top |
|
|
quatsch Tux's lil' helper
Joined: 24 Apr 2005 Posts: 104 Location: New York, NY
|
Posted: Sun Jul 08, 2007 8:56 pm Post subject: |
|
|
From man udev:
Code: | ATTRS{filename}
Search the devpath upwards for a device with matching sysfs
attribute values. Up to five ATTRS keys can be specified per rule,
but all of them must match on the same device. Trailing whitespace
in the attribute values is ignored, if the specified match value
does not contain trailing whitespace itself.
|
so if you use ATTRS (but not ATTR), you can specify attributes from different sections of the udevinfo output.
I give my partitions labels. You can then use vol_id (in /lib/udev) in your udev rules. See man vol_id and also the provided rules for persistent naming for clues on how to do it. And it seems that the man page for udev is the most up-to-date documentation.
cheers |
|
Back to top |
|
|
graffitici Tux's lil' helper
Joined: 04 Feb 2004 Posts: 136 Location: Istanbul-Turkey
|
Posted: Sun Jul 08, 2007 9:13 pm Post subject: |
|
|
I decided to skip the size attribute, and use attributes from different sections instead. I have ATTRS{model} to match the hard-drive, and use KERNEL=="sd?5" and so on to match the specific partition. This way, even if I resize the partition (which I probably will), I wouldn't have to change any udev settings (it's another story if i decide to move the partitions around).
Here is a sample rule
Code: |
ATTRS{model}=="S0VVJ1KP302694", KERNEL=="sd?5", NAME="%k", SYMLINK="samsung_hd/music"
ATTRS{model}=="S0VVJ1KP302694", KERNEL=="sd?6", NAME="%k", SYMLINK="samsung_hd/backup"
|
|
|
Back to top |
|
|
graffitici Tux's lil' helper
Joined: 04 Feb 2004 Posts: 136 Location: Istanbul-Turkey
|
Posted: Sun Jul 08, 2007 9:23 pm Post subject: |
|
|
quatsch wrote: | From man udev:
Code: | ATTRS{filename}
Search the devpath upwards for a device with matching sysfs
attribute values. Up to five ATTRS keys can be specified per rule,
but all of them must match on the same device. Trailing whitespace
in the attribute values is ignored, if the specified match value
does not contain trailing whitespace itself.
|
so if you use ATTRS (but not ATTR), you can specify attributes from different sections of the udevinfo output.
I give my partitions labels. You can then use vol_id (in /lib/udev) in your udev rules. See man vol_id and also the provided rules for persistent naming for clues on how to do it. And it seems that the man page for udev is the most up-to-date documentation.
cheers |
Thanks a lot for your help quatsch! You've been really helpful. The idea of assigning labels to partitions is a very good one, but I think I'll stick with my version, now that I know I can use ATTRS with other keys.
Thanks again! |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|