Modifying mount options (ro/rw etc.) during automount via udev
Linux - Laptop and NetbookHaving a problem installing or configuring Linux on your laptop? Need help running Linux on your netbook? This forum is for you. This forum is for any topics relating to Linux and either traditional laptops or netbooks (such as the Asus EEE PC, Everex CloudBook or MSI Wind).
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Modifying mount options (ro/rw etc.) during automount via udev
Hi all:
I know this is not the forum for this question but I tried posting my question in Suse/Novell but nobody responded.. so I'm posting it again here...
The question is: how can I change the mount options when an external harddisk is mounted automatically via udev scripts. I tried browsing through the udev rules in the etc directory but I couldn't figure it out.
The reason I want to do this is because opensuse 10.2 is mounting my external USB drive NTFS partition in rw mode that I don't want.
From the dmesg output...
NTFS driver 2.1.27 [Flags: R/W MODULE].
NTFS volume version 3.1.
it seems the stock ntfs module is compiled with Read-Write support which is not very stable yet. Therefore I want to change the mount options to Readonly.
I have another related question: when I get the icon for the external harddisk. There is an option to unmount it but not eject. How can I have an option to eject (i.e. poweroff the external drive/pen drive). Windows provides me that.
oops via udev you asked?
humm I think udev doesn't set mount options? So you have to put it in /etc/fstab
Like this:
/dev/hda1 /mnt/hda1 ntfs noauto,user,ro,uid=1000,gid=114,umask=007,nls=utf8 0 0
You could add a rule that contains a "MODE=555" entry.
"udevinfo -q env -p $(udevinfo -q path -n /dev/sda1)" after plugging in the drive ( use the correct device in your case ) will print out information that you can use to uniquely identify the device.
oops via udev you asked?
humm I think udev doesn't set mount options? So you have to put it in /etc/fstab
Like this:
/dev/hda1 /mnt/hda1 ntfs noauto,user,ro,uid=1000,gid=114,umask=007,nls=utf8 0 0
Thanks for your prompt reply, I did exactly that but instead of using /dev/sda1 (which is what the device is recognized as) I used /dev/disk/by-label/USB_Drive.
I added the following...
/dev/disk/by-label/<my_disk_label> /media/usbdisk ntfs ro,noauto,users,<other options> 0 0
As the real device name (/dev/sda1) may change a later time, I wanted a solution which is permanent. I browsed through the udev rules and I could find the rules to create symlinks pointing to the real device node by disk-volume-name and other such persistent ids.
Though this has solved 99% of what I wanted, there is a small annoyance though. After doing the above change, when I inserted my disk I got an icon "usbdisk" on my gnome desktop.
The problem is when I unmounted via right-clicking "usbdisk" I got another icon for this same disk labeld "USB Drive" which is the volume label of my disk.
I guess this is done by gnome-volume-manager which was doing the initial r/w mount.
So definetly I don't want two icons pointing to the same volume and I'd be looking out to configure gnome-volume-manager to mount the drive as read-only.
This only sets permissions, which udev does right.
But here we're talking of mounting options if I understand correctly?
Exactly. I am still not able to find any way to provide mount options to the mount command.
But I guess it's not possible... It's not udev which is doing the mount but it only creates the device nodes and symlinks to it. One has to use autofs for automatic mount and there you can specify the mount options.
But I think Suse is using gnome-volume-manager instead of autofs to automount. I will now look how can I change the mount options using gnome-volume-manager.
I particularly don't like autofs because it is kernel based. It happened to me several time (when I was using Mandrake) that the kernel would lock up because I removed the disk manually or the network share was unavailable.
edit:
your right about /by-label/ stuff, I should also do it
(btw, I am using pmount for removable medias, it can integrate with hal to automount)
I particularly don't like autofs because it is kernel based. It happened to me several time (when I was using Mandrake) that the kernel would lock up because I removed the disk manually or the network share was unavailable.
edit:
your right about /by-label/ stuff, I should also do it
(btw, I am using pmount for removable medias, it can integrate with hal to automount)
Hi, I'm back again with some more information.
The mount was indeed happening through gnome-volume-manager which listens to events from HAL.
I could even find the documentation to provide mount options to "high-in-stack" software (i.e. gnome-mount-manager) but it seems it is not honoring these flags.
I added my own policy in HAL which looks like below...
<deviceinfo version="0.2">
<device>
<match key="block.is_volume" bool="true">
<match key="volume.fsusage" string="filesystem">
<match key="volume.fstype" string="ntfs">
<merge key="volume.policy.desired_mount_point" type="string">kamal_usbdisk</merge>
<merge key="volume.policy.mount_option.ro" type="bool">true</merge>
<merge key="storage.policy.mount_option.ro" type="bool">true</merge>
<merge key="storage.policy.default.mount_option.ro" type="bool">true</merge>
</match>
</match>
</match>
</device>
</deviceinfo>
To confirm my policy is loaded and working, I also changed the desired_mount_point which worked. But the drive is still mounted as read-write.
Any ideas... as you use pmount.. which actually is embedded inside gnome-volume-manager, you might give me some clue...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.