How to write udev rules for USB hard disk drives
Hi, I just bought a USB hard disk and when I plug it in it gets mounted as owner root and group root. I tried writing a udev rule for it based on the following guide:
http://www.reactivated.net/writing_udev_rules.html Nothing seems to work, it always mounts as root. Slackware 13.1, KDE, Dell Optiplex GX280, Western Digital Passport USB 320 gig drive. I am a member of the plugdev group, so it seems to me a rule should not even be necessary. Any ideas? Mike. |
Well, the mounting is done via HAL so you'd have to change stuff there.
What desktop environment are you running? That's what should be listening to hald via dbus and generating the mount command. |
KDE. Can you point me to something that explains how to make the changes in HAL?
|
HAL/The Desktop should obey any settings in /etc/fstab when mounting, so just put an entry in there specifying whatever options you want it to use.
Because it's an external usb device I'd recommend you use LABEL= or UUID= rather than the /dev/sd?? device in the /etc/fstab because the device name may vary when the drive is plugged-in in future. |
Is it an NTFS-formatted drive? If so it is possible that it is trying to mount read-only using the standard kernel module instead of using ntfs-3g through FUSE. I do not know why it would mount as root:root though -- it should still be using the plugdev group. An fstab entry is a foolproof solution but it would not explain why it is getting mounted with the wrong ownership (and permissions?) by default when using HAL.
|
The first thing I did was delete the original partition, create a linux partition, and format it ext3. Mike.
|
Ahh, I was working on the principle that it was a NTFS.
if it's an ext filesystem, then the permissions will be those of the top level directory of the filesystem it contains. Just mount it as root and then do a standard chown/chmod on it. |
But won't that be temporary? I would have to do that every time I boot, or unplug and re-plug, wouldn't I?
|
No. the permissions/ownership are stored in the filesystem itself. So next time you mount the filesystem the values will still be as you set them.
Just remember to chmod after you mount it, otherwise you'll be setting the permissions of the mountpoint directory it's mounted on and not of the top directory of the filesystem. You might want to consider chmod 1777 which will set it up to work exactly like /tmp. i.e. everyone can use it, but you can only delete your own files/directories. Then if you add an fstab entry with "noauto,user" any user should be able to mount it. That's how I do this sort of thing anyway. |
Quote:
http://freedesktop.org/wiki/Software/hal has what little else there is (and it leads you to the above link). You'd think that someone would have documented the damned thing after a year or so. |
Quote:
|
Quote:
|
GazL, your solution worked. I added a line to /etc/fstab, made a directory for it: /mnt/passport, mounted as root, chown, re-booted, and the disk was mine. I too still prefer the old-fashioned way. Mike.
|
Quote:
Glad you got it sorted Mike. :) |
Here is how I mount usb sticks. The udev rules are not that hard for usb drives, you just create one rule then copy it for all your drives and all you have to change is the serial no. ( ATTRS{serial}== ) which is easy to find using 'lsusb -v|less'.
This is one of my rules in /etc/udev/rules.d/01-automount.rules KERNEL=="sd?1", ATTRS{serial}=="01234567890" , ACTION=="add", RUN+="/usr/local/bin/automountit KINGDT2G01 -m -r" KERNEL=="sd?1", ATTRS{serial}=="01234567890" , ACTION=="remove", RUN+="/usr/local/bin/automountit KINGDT2G01 -u" The automountit script will create the directory /media/KINGDT2G01 then mount the device and set the permissions. And as an added convenience it modifies the Dolphin.desktop file so when I clik on it dolphin opens with split panels and it is already set to the device's root directory and the other panel is $HOME. So all I do is plug in the device, wait a couple seconds and it is mounted and ready to go. Also when I remove the device the automountit script will remove the /media directory and return my Dolphin.desktop back to normal. NOTE: KINGDT2G01 is just a name I made up to identify the device, it stands for Kingston DataTraveler 2G No. 1. I have quite a few usb sticks and this makes it alot easier to keep track of them. Also I use /dev/disk/by-id or /dev/disk/by-label in the /etc/fstab file, as was mentioned in an earlier post /dev/sdX1 is not a reliable way to mount removable usb drives. |
All times are GMT -5. The time now is 10:50 PM. |