LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Laptop and Netbook (http://www.linuxquestions.org/questions/linux-laptop-and-netbook-25/)
-   -   Modifying mount options (ro/rw etc.) during automount via udev (http://www.linuxquestions.org/questions/linux-laptop-and-netbook-25/modifying-mount-options-ro-rw-etc-during-automount-via-udev-510341/)

kamal.n2 12-14-2006 04:54 AM

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.

Many thanks in advance.

Regards,
- Kamal N

nx5000 12-14-2006 05:06 AM

This doesn't mean anything, check with mount directly:

mount -t ntfs

edit:
to change options to a mounted system:

mount /mnt/windows -o remount,rw

nx5000 12-14-2006 05:09 AM

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

jschiwal 12-14-2006 05:45 AM

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.
Code:

udevinfo -q path -n /dev/hda1
/block/hda/hda1
jschiwal@hpamd64:~/Documents> udevinfo -q env -p /sys/block/hda/hda1
ID_TYPE=disk
ID_MODEL=FUJITSU_MHU2100AT
ID_SERIAL=NQ07T4825B7P
ID_REVISION=00000008
ID_BUS=ata
ID_PATH=pci-0000:00:08.0-ide-0:0
ID_FS_USAGE=filesystem
ID_FS_TYPE=ntfs
ID_FS_VERSION=3.1
ID_FS_UUID=4B1135F8699960E7
ID_FS_LABEL=
ID_FS_LABEL_SAFE=

This howto should help you write your rule and determine where to put it. Also read through the SuSE documentation on it.
http://reactivated.net/writing_udev_rules.html

nx5000 12-14-2006 06:11 AM

This only sets permissions, which udev does right.
But here we're talking of mounting options if I understand correctly?

kamal.n2 12-14-2006 06:14 AM

Quote:

Originally Posted by nx5000
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.

Thanks,
- Kamal N

kamal.n2 12-14-2006 06:25 AM

Quote:

Originally Posted by nx5000
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.

Thanks,
- Kamal N

nx5000 12-14-2006 06:46 AM

No clue for gnome.. sorry

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)

kamal.n2 12-14-2006 02:19 PM

Quote:

Originally Posted by nx5000
No clue for gnome.. sorry

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...

Thanks again,
- Kamal N


All times are GMT -5. The time now is 02:03 AM.