LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 05:10 PM   #1
mscole
Member
 
Registered: Nov 2004
Location: Florida
Distribution: Slackware 15
Posts: 129

Rep: Reputation: 24
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, 05:34 PM   #2
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
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, 05:59 PM   #3
mscole
Member
 
Registered: Nov 2004
Location: Florida
Distribution: Slackware 15
Posts: 129

Original Poster
Rep: Reputation: 24
KDE. Can you point me to something that explains how to make the changes in HAL?
 
Old 08-16-2010, 06:11 PM   #4
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
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, 06:18 PM   #5
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.1
Posts: 2,367

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
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, 06:21 PM   #6
mscole
Member
 
Registered: Nov 2004
Location: Florida
Distribution: Slackware 15
Posts: 129

Original Poster
Rep: Reputation: 24
The first thing I did was delete the original partition, create a linux partition, and format it ext3. Mike.
 
Old 08-16-2010, 06:25 PM   #7
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
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, 06:35 PM   #8
mscole
Member
 
Registered: Nov 2004
Location: Florida
Distribution: Slackware 15
Posts: 129

Original Poster
Rep: Reputation: 24
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 06:38 PM.
 
Old 08-16-2010, 06:43 PM   #9
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
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, 06:46 PM   #10
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
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, 06:48 PM   #11
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
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, 06:56 PM   #12
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
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, 07:01 PM   #13
mscole
Member
 
Registered: Nov 2004
Location: Florida
Distribution: Slackware 15
Posts: 129

Original Poster
Rep: Reputation: 24
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, 07:09 PM   #14
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
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, 05:46 PM   #15
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
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



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 12:42 AM
Udev, disk, disk1, rules and udevinfo arubin Slackware 3 11-19-2009 12:18 AM
help with udev rules and write permisions teodor_b Linux - Software 2 08-17-2009 03:00 AM
USB flash disk read problems using udev rules janfranken Linux - Desktop 6 02-18-2009 06:33 PM
udev rules fail on identical sata hard disk drives xushi Linux - Hardware 5 01-03-2008 01:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 04:40 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
Open Source Consulting | Domain Registration