# mount options with HAL

## snake111

Hi all, I'm trying do define mount options using HAL policies, but I have problems due to lack of documentation.

I have a "mediacenter like" box, where xbmc mounts removable devices when started, and unmount them when closed; using hal I suppose.

My problem is that ntfs volumes are mounted with root permissions, and I can't read them from xbmc. Since I don't need write support I'd prefer not to install ntfs3g, even better would be mount every usb device read-only (regardless of fs type).

I tried googling, but seems that lots of people have the same problem but nobody a solution.

I tried to define some policies in /etc/hal/fdi/policy/10osvendor like this:

```

<match key="volume.fstype" string="ntfs">

        <match key="/org/freedesktop/Hal/devices/computer:system.kernel.name" string="Linux">

          <append key="volume.mount.valid_options" type="strlist">uid=</append>

          <append key="volume.mount.valid_options" type="strlist">gid=</append>

          <append key="volume.mount.valid_options" type="strlist">umask=</append>

          <append key="volume.mount.valid_options" type="strlist">locale=</append>

          <append key="volume.mount.valid_options" type="strlist">utf8</append> -->

          <merge key="volume.mount.valid_options.umask" type="string">0222</merge>

```

but no way.

I think that the first block is not needed, because even without it I get the following from lshal output for my ntfs usb disk (look at volume.mount.valid_options line):

```

udi = '/org/freedesktop/Hal/devices/volume_uuid_7054AC9654AC6098'

  block.device = '/dev/sdb1'  (string)                           

  block.is_volume = true  (bool)                                 

  block.major = 8  (0x8)  (int)                                  

  block.minor = 17  (0x11)  (int)                                

  block.storage_device = '/org/freedesktop/Hal/devices/storage_serial_Hitachi_HDT725050VLAT80_54AC0620_0_0'  (string)

  info.capabilities = {'volume', 'block'} (string list)                                                              

  info.category = 'volume'  (string)                                                                                 

  info.interfaces = {'org.freedesktop.Hal.Device.Volume'} (string list)                                              

  info.parent = '/org/freedesktop/Hal/devices/storage_serial_Hitachi_HDT725050VLAT80_54AC0620_0_0'  (string)         

  info.product = 'IOMEGA_HDD'  (string)                                                                              

  info.udi = '/org/freedesktop/Hal/devices/volume_uuid_7054AC9654AC6098'  (string)                                   

  linux.hotplug_type = 3  (0x3)  (int)                                                                               

  linux.sysfs_path = '/sys/devices/pci0000:00/0000:00:04.1/usb1/1-5/1-5:1.0/host8/target8:0:0/8:0:0:0/block/sdb/sdb1'  (string)

  org.freedesktop.Hal.Device.Volume.method_argnames = {'mount_point fstype extra_options', 'extra_options', 'extra_options'} (string list)

  org.freedesktop.Hal.Device.Volume.method_execpaths = {'hal-storage-mount', 'hal-storage-unmount', 'hal-storage-eject'} (string list)    

  org.freedesktop.Hal.Device.Volume.method_names = {'Mount', 'Unmount', 'Eject'} (string list)                                            

  org.freedesktop.Hal.Device.Volume.method_signatures = {'ssas', 'as', 'as'} (string list)                                                

  storage.model = ''  (string)                                                                                                            

  volume.block_size = 512  (0x200)  (int)                                                                                                 

  volume.fstype = 'ntfs'  (string)                                                                                                        

  volume.fsusage = 'filesystem'  (string)                                                                                                 

  volume.fsversion = '3.1'  (string)                                                                                                      

  volume.ignore = false  (bool)                                                                                                           

  volume.is_disc = false  (bool)                                                                                                          

  volume.is_mounted = true  (bool)                                                                                                        

  volume.is_mounted_read_only = true  (bool)                                                                                              

  volume.is_partition = true  (bool)                                                                                                      

  volume.label = 'IOMEGA_HDD'  (string)                                                                                                   

  volume.linux.is_device_mapper = false  (bool)                                                                                           

  volume.mount.valid_options = {'ro', 'sync', 'dirsync', 'noatime', 'nodiratime', 'noexec', 'quiet', 'remount', 'exec', 'uid=', 'gid=', 'umask=', 'locale=', 'utf8'} (string list)                                                                                                    

  volume.mount_point = '/media/IOMEGA_HDD'  (string)                                                                                       

  volume.num_blocks = 976768002  (0x3a384c02)  (uint64)                                                                                    

  volume.partition.flags = {'boot'} (string list)                                                                                          

  volume.partition.label = ''  (string)                                                                                                    

  volume.partition.media_size = 500107862016  (0x7470c06000)  (uint64)                                                                     

  volume.partition.number = 1  (0x1)  (int)                                                                                                

  volume.partition.scheme = 'mbr'  (string)                                                                                                

  volume.partition.start = 32256  (0x7e00)  (uint64)                                                                                       

  volume.partition.type = '0x07'  (string)                                                                                                 

  volume.partition.uuid = ''  (string)                                                                                                     

  volume.size = 500105217024  (0x7470980400)  (uint64)                                                                                     

  volume.unmount.valid_options = {'lazy'} (string list)                                                                                    

  volume.uuid = '7054AC9654AC6098'  (string)                     

```

All the mount options seems to be there, but I can't set them. I even tried to set the preferred mount point, lshal shows it, but it's ignored, and the disk still mounts in /media/IOMEGA_HDD.

Any help will be greatly appreciated, thanks!  :Smile: 

----------

## honp

Try tu use udev instead  :Smile:  (it is well documented and great:) )

----------

## i92guboj

I wouldn't waste much time in hal, according to freedesktop, it's in "maintenance mode". Udev alone can do the same, and it's well documented.

http://www.reactivated.net/writing_udev_rules.html

----------

## snake111

Thanks, I also read it's in "maintenance mode" so not a good news to look for docs..

Didn't know that udev could do the same, thanks, I'll have a look and post my results!  :Smile: 

----------

## snake111

The thing begin getting complicated... With my AMD64 system I couldn't start udev because the init script needs baselayout-2. So switched to baselayout-2 and openRC, added the following rule in /etc/udev/rules.d/

```

ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/lib/udev/vol_id -t /dev/%k", RESULT=="ntfs", RUN+="/bin/mount -t ntfs -o ro,uid=1000,gid=100,dmask=0047,fmask=0133 /dev/%k /mnt/usb", OPTIONS="last_rule"

```

Now the disk mounts, but I lost some nice hal behavior, like mounting in a path reflecting file system label, but I think I can fix this (tuning the RUN+= statement).

Is it possible to make udev delete the mount folder when unmountig the volume?

For example when I plug the hd it creates the /media/IOMEGA_HDD folder and mount the device in it, and when I unmount it, or swich off the system it deletes the /media/IOMEGA_HDD folder.

----------

## i92guboj

I am not sure if when unmounting, but if not, at least you could use ACTION="remove", for when the device is detached.

You could as well try to investigate the future substitute for hal, which seems to be going devicekit. I have no idea what it's current status is.

----------

## snake111

ACTION="remove" is even better, being a media center box, people won't have the option to "unmount" but just to physically unplug the usb drive (hope won't be a problem, being mounted ro).

I'll do some testing tomorrow and be back with results here, thanks!

----------

## i92guboj

 *snake111 wrote:*   

> ACTION="remove" is even better, being a media center box, people won't have the option to "unmount" but just to physically unplug the usb drive (hope won't be a problem, being mounted ro).
> 
> I'll do some testing tomorrow and be back with results here, thanks!

 

It won't be a problem if you mount "ro". It can be problematic when mounting "rw", because the pc has no means to know that your fingers are about to detach the drive, hence data can be lost (just like when you unplug a pendrive on a Windows machine without using the safe removal feature). Even this could be somewhat aleaviated by using the "sync" mount option, but even then, if the kernel is in the middle of something that's non-interruptable and it hangs for some time there for a reason, then there can be data loss. Mounting "ro" should be no problem though, as said.

----------

## snake111

Thanks, that's exactly what i was thinking about ro and rw.

I can say that the issue is solved, although i don't like very much this solution, because involves manuals mount/umount commands instead of defining rules for the mount manager, a much more "cleaner" solution in my opinion.

Anyway, after a long test-fix phase, these are the udev rules i use:

```

ACTION=="add", KERNEL=="sd[b-z][0-9]", PROGRAM=="/lib/udev/vol_id -t /dev/%k", RESULT=="ntfs", RUN+="/bin/mkdir /mnt/usb_disk_%k" RUN+="/bin/mount -t ntfs -o ro,noexec,uid=1000,gid=100,dmask=0007,fmask=0337 /dev/%k /mnt/usb_disk_%k", OPTIONS="last_rule"

ACTION=="add", KERNEL=="sd[b-z][0-9]", PROGRAM=="/lib/udev/vol_id -t /dev/%k", RESULT!="ntfs", RUN+="/bin/mkdir /mnt/usb_disk_%k" RUN+="/bin/mount -o ro,noexec /dev/%k /mnt/usb_disk_%k", OPTIONS="last_rule"

ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/umount /mnt/usb_disk_%k" RUN+="/bin/rm -r /mnt/usb_disk_%k"

```

First one is for ntfs volumes, because defines uid, dmask and fmask usefull for setting user access to ntfs files and dir.

The second is for everything else.

Both rules creates a dir under /mnt/ with the format "usb_disk_%k" where %k is the partition (ex. sdb1).

The final rule applies when the usb disk is physically unplugged, the rule umounts the volume and deletes the device directory under /mnt.

Any comment, or suggestion will be appreciated, thanks  :Smile: 

----------

