LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices



Reply
 
Search this Thread
Old 08-16-2010, 06:10 PM   #1
mscole
Member
 
Registered: Nov 2004
Location: Gainesville, Florida
Distribution: Slackware 10.0
Posts: 97

Rep: Reputation: 16
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.
 
Old 08-16-2010, 06:34 PM   #2
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: Carrollton, Texas
Distribution: Slackware64 14.1
Posts: 1,578

Rep: Reputation: 468Reputation: 468Reputation: 468Reputation: 468Reputation: 468
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.
 
Old 08-16-2010, 06:59 PM   #3
mscole
Member
 
Registered: Nov 2004
Location: Gainesville, Florida
Distribution: Slackware 10.0
Posts: 97

Original Poster
Rep: Reputation: 16
KDE. Can you point me to something that explains how to make the changes in HAL?
 
Old 08-16-2010, 07:11 PM   #4
GazL
Senior Member
 
Registered: May 2008
Posts: 3,503

Rep: Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026
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.
 
Old 08-16-2010, 07:18 PM   #5
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.1
Posts: 2,298

Rep: Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722
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.
 
Old 08-16-2010, 07:21 PM   #6
mscole
Member
 
Registered: Nov 2004
Location: Gainesville, Florida
Distribution: Slackware 10.0
Posts: 97

Original Poster
Rep: Reputation: 16
The first thing I did was delete the original partition, create a linux partition, and format it ext3. Mike.
 
Old 08-16-2010, 07:25 PM   #7
GazL
Senior Member
 
Registered: May 2008
Posts: 3,503

Rep: Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026
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.
 
Old 08-16-2010, 07:35 PM   #8
mscole
Member
 
Registered: Nov 2004
Location: Gainesville, Florida
Distribution: Slackware 10.0
Posts: 97

Original Poster
Rep: Reputation: 16
But won't that be temporary? I would have to do that every time I boot, or unplug and re-plug, wouldn't I?

Last edited by mscole; 08-16-2010 at 07:38 PM.
 
Old 08-16-2010, 07:43 PM   #9
GazL
Senior Member
 
Registered: May 2008
Posts: 3,503

Rep: Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026
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.
 
Old 08-16-2010, 07:46 PM   #10
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: Carrollton, Texas
Distribution: Slackware64 14.1
Posts: 1,578

Rep: Reputation: 468Reputation: 468Reputation: 468Reputation: 468Reputation: 468
Quote:
Originally Posted by mscole View Post
KDE. Can you point me to something that explains how to make the changes in HAL?
http://www.mythic-beasts.com/~mark/random/hal/ is the best thing that I could find.

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.
 
Old 08-16-2010, 07:48 PM   #11
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: Carrollton, Texas
Distribution: Slackware64 14.1
Posts: 1,578

Rep: Reputation: 468Reputation: 468Reputation: 468Reputation: 468Reputation: 468
Quote:
Originally Posted by GazL View Post
No. the permissions/ownership are stored in the filesystem itself.
Unless he's using the links autogenerated in /media. In Gnome, Nautilus would be responsible for creating the directories; in KDE something else is doing that work.
 
Old 08-16-2010, 07:56 PM   #12
GazL
Senior Member
 
Registered: May 2008
Posts: 3,503

Rep: Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026
Quote:
Originally Posted by Richard Cranium View Post
Unless he's using the links autogenerated in /media. In Gnome, Nautilus would be responsible for creating the directories; in KDE something else is doing that work.
Once the filesystem is mounted though, those directories will have been overmounted so their permissions won't matter. That's Unless gnome/kde desktops do a chmod/chown after the filesystem is mounted to alter the permissions of the top directory (In which case; OMFG! NO!!!!! and I'm even more glad I do things the old fashioned way! ).
 
Old 08-16-2010, 08:01 PM   #13
mscole
Member
 
Registered: Nov 2004
Location: Gainesville, Florida
Distribution: Slackware 10.0
Posts: 97

Original Poster
Rep: Reputation: 16
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.
 
Old 08-16-2010, 08:09 PM   #14
GazL
Senior Member
 
Registered: May 2008
Posts: 3,503

Rep: Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026
Quote:
Originally Posted by mscole View Post
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.
It's certainly simpler than all this udev/hal nonsense.

Glad you got it sorted Mike.

 
Old 11-04-2010, 06:46 PM   #15
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Udev creates the external usb hard disk device node too late pastoreerrante Linux - Software 2 05-24-2010 01:42 AM
Udev, disk, disk1, rules and udevinfo arubin Slackware 3 11-19-2009 01:18 AM
help with udev rules and write permisions teodor_b Linux - Software 2 08-17-2009 04:00 AM
USB flash disk read problems using udev rules janfranken Linux - Desktop 6 02-18-2009 07:33 PM
udev rules fail on identical sata hard disk drives xushi Linux - Hardware 5 01-03-2008 02:49 AM


All times are GMT -5. The time now is 09:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration