From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alan Jenkins Date: Thu, 21 May 2009 10:21:13 +0000 Subject: Re: udev questions Message-Id: <4A152B19.9020608@tuffmail.co.uk> List-Id: References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-hotplug@vger.kernel.org David A. Roth wrote: > Hi Alan. > > Thanks very much for your kind and helpful reply. I wasn't aware of > this mailing list you mentioned, thanks. Please see my comments > below. > > On Thu, May 21, 2009 at 3:46 AM, Alan Jenkins > wrote: > >> David A. Roth wrote: >> >>> Hello Alan. >>> >>> I hope I have the right Alan Jenkins. I've seen your name while >>> Googling regarding udev. If you aren't the right person, please >>> forgive the error. >>> >>> >> Well, you're not very specific about who you're looking for :-). I'm not >> the maintainer, if that's what you mean. >> You certainly have the wrong email address. I've CC'd linux-hotplug, which >> is the mailing list for Udev. >> > > No, I saw a bunch of postings of yours with udev in them, figured > you'd know more than most. :-) > >>> I have some udev questions and was wondering if you could shed any >>> light on the problems I'm having. Here is a posting of mine to the >>> CentOS forum concerning udev, udevinfo and udevtest. >>> >>> Thanks in advance, >>> >>> David A. Roth >>> davidalanroth@gmail.com >>> >>> Background: >>> >>> I have two external USB drives (Maxtor and LaCie), and I want them to >>> be assigned the same device at boot. /dev/sda for the Maxtor and >>> /dev/sdb for the LaCie. >>> >>> With a default rules installation of CentOS 5.3 the LaCie gets >>> assigned /dev/sda and the Maxtor /dev/sdb, which is the reverse order >>> of what I want. >>> >>> >> That sounds like a really bad idea. >> >> >>> So it was suggested to me that I look into udev and write some rules. >>> I looked at two web pages for help with udev being: >>> >>> http://www.axllent.org/docs/data_storage/udev_and_external_devices >>> http://reactivated.net/writing_udev_rules.html >>> >>> I added the file 10-local.rules to /etc/udev/rules.d with these two lines: >>> >>> >>> KERNEL="sd*",SYSFS{manufacturer}="Maxtor",NAME:="sda%n",SYMLINK+="usbmaxtor%n" >>> >>> KERNEL="sd*",SYSFS{manufacturer}="LaCie",NAME:="sdb%n",SYMLINK+="usblacie%n" >>> >>> After booting, a 'df' shows that sda and /dev/usbmaxtor is indeed >>> assigned to the Maxtor. >>> >>> Problem: >>> >>> While the 'df' shows that the sda is assigned to the Maxtor >>> (/dev/usbmaxtor), udevinfo -a -p /sys/block/sda indicated that sda is >>> the LaCie drive. When doing dmesg, it has a remark that fsck should be >>> run on sdb3, but sdb only has one partition of sdb1. It's the Maxtor >>> which has sda3. >>> >>> Questions: >>> >>> Is the problem here with my rules statement above? If so, what do I >>> need to change? >>> >>> >> There's no way change the name printed in kernel messages (dmesg) or under >> /sys. Udev only controls the name in /dev. (The exception is networking >> devices, which don't appear in /dev; I think they can have their kernel >> names changed). I hope that clears things up. >> >> If you only use the links, it should be fine. Btw, if you don't mind long >> link names, you may find udev already creates useful links under >> /dev/disk/by-id/. >> > > I see, wow, that's great! I wasn't aware of that. > >>> I constructed the above from examples, but wasn't able to find >>> documentation that goes into detail. For example, what is the >>> different between NAME:= vs. NAME= ? >>> >>> >> I think you're right that udev isn't comprehensively documented. But I this >> particular one is covered in the manual page ("man udev"). ":=" assignment >> is final, and cannot be overridden by an assignment in a subsequent rule. >> > > Thanks again, Alan. > > After reviewing your reply, I believe this makes more sense to me. I > shouldn't care if the drive is sda or sdb, since I should be > referencing the symlink? In the past, I am use to doing backups and > with rsync, for example and would mount /dev/sda3 to /mnt/maxtor, for > example. After I adding the second USB external drive, sda was no > longer the Maxtor drive but the Lacie. So I felt I needed to force the > maxtor to always be sda in order for my scripts to work. My real goal, > is that the correct drive and partition is being reference to it's > ultimate mount point after boot time regardless of which drive is > assigned to sda or sdb. > > Sounds like I should remove NAME:= altogether from the rules here so I > shouldn't be forcing sda or sdb on the drives? > Yes, remove NAME:= and use symlinks. I mentioned "by-id" since that was closest to what you were trying. This is not word of god, but I would recommend trying "by-uuid" instead. Modern distributions use links under "/dev/disk/by-uuid", which are generated based on filesystem serial numbers. This has the advantage of not hard-coding the partition number (or the device). The filesystem UUID will remain stable even if you resize it or re-order the partition table for some reason. You can generally expect UUIDs to be unique, so long as you aren't copying raw parition images around. You can use "ls -l /dev/disk/by-uuid" to see which UUID link corresponds to the desired partition. > Thanks in advance for allow me pester you. I will check out the > mailing list you mentioned as well. > > Best regards, > > David >