Why mounts HAL in /media?

openSUSE 10.3 and KDE 3.5.

When I insert an USB storage device, the kernel detects this and signals udevd.
udevd makes the device files (using the udev rules found in /etc/udev/) and signals HAL.
HAL does the mounting of the partition (only 1 partition on the device). On my system the mounting is done on a directory (created by HAL for this purpose) in /media.

If I am informed correctly, the HAL configurations are in /usr/share/hal/fdi and /etc/hal/fdi. But I fail to find there any information why HAL uses /media as mount root and also why it chooses disk as mountpoint (on another device it uses DISK_IMG, so it is probably something read from the device).

Can anybody shed some light on this or point me to info on the net? I found HAL 0.5.10 Specification and it helps somewhat, but not very much.

Does this throw some light on it? Has a section about mount points…

HAL - ArchWiki

Just been fighting hal myself still not sure I understand much more since starting but solved my problem.

Edit
hehe can’t believe I might be helping you ;p

I noticed that whenever Volume Labels were available, it used that to name the mount point. I burned a CD with a volume label and it used exactly that. However, I didn’t dig into further details.

@FeatherMonkey
Thanks for the link. I found it already, but nevertheless. It does shed some light on how to use these config files (which is not ver easy), but it is all about mount options (in fact file system options) and not about the mountpoint.

O and I think you helped me often without knowing. I do read a lot of threads. I am always interested in what certain ppl post. You are one of them.

@syampillai
That is correct. In the meantime I found that also. When there is no label it will just take the device class (IIRC) wich is ‘disk’ in this case and when needed wil add numbers (something like disk-1).

hcvv wrote:
> openSUSE 10.3 and KDE 3.5.
>
> When I insert an USB storage device, the kernel detects this and
> signals udevd.
> udevd makes the device files (using the udev rules found in
> /etc/udev/) and signals HAL.
> HAL does the mounting of the partition (only 1 partition on the
> device). On my system the mounting is done on a directory (created by
> HAL for this purpose) in /media.
>
> If I am informed correctly, the HAL configurations are in
> /usr/share/hal/fdi and /etc/hal/fdi. But I fail to find there any
> information why HAL uses /media as mount root and also why it chooses
> disk as mountpoint (on another device it uses DISK_IMG, so it is
> probably something read from the device).

I think if you have a device… let’s say one that can make more than one
piece of “media” available… yet only provides ONE name, the first device
(?) get the identifier from the device, and the other will just get disk (not
sure what happens when there are more than one extra, maybe disk2, etc… I’d
have to look).

Personally, I don’t have much problem with udev… it makes sense to me.
But hal? I predict a rewrite at some point. But in that process it may
LOSE functionality instead of making guesses that are often times right. :slight_smile:
(and sometimes VERY wrong)

>
> Can anybody shed some light on this or point me to info on the net? I
> found ‘HAL 0.5.10 Specification’
> (http://people.freedesktop.org/~david/hal-spec/hal-spec.html) and it
> helps somewhat, but not very much.
>

Not sure where the /media comes in either… it may be more of a
desktop volume manager thing rather than anything having to do with
hal or udev (though I’m sure hal is how that piece knows to mount
things up under /media). If using an older KDE, then obviously
it won’t be hal/dbus but something via dcop (I think?).

One thing I found out some time ago, not sure if in OS 10.2 or 11.0, is that when a device is mounted in /media there is a hidden file that locks the name used to that device. This file is removed when the device is unmounted.

If for some reason the file is not deleted (like in a system freeze/reboot), when reinserted the device will be named <name>-1, or something like that, and you can’t delete the <name> directory. It was mildly irritating…

I’m writing from memory, so some details may differ.

Not sure where the /media comes in either… it may be more of a
desktop volume manager thing rather than anything having to do with
hal or udev (though I’m sure hal is how that piece knows to mount
things up under /media).

Yes, I think this is correct. The gnome and KDE volume managers set the mount location, with info parsed from hal. KDE3 for example has ~/.kde/share/config/mediamananagerrc where particular devices can be assigned specific mount points. I’m not sure if a user has a completely free hand in setting a completely different mount location though. I have a custom udev rule for my backup drive for example, which has a corresponding entry stored in mediamanagerrc:

[/org/freedesktop/Hal/devices/storage_serial_SATA_TOSHIBA_MK8032G_X5CX6959T]
automount=true

[/org/freedesktop/Hal/devices/storage_serial_WD_1200BEVExternal_575845363037433738373630_0_0]
automount=true

[/org/freedesktop/Hal/devices/volume_uuid_086f2492_4ca1_4149_90d3_168cf2f3c239]
atime=true
journaling=ordered
mountpoint=/media/backup
quiet=false
ro=false
sync=false

[/org/freedesktop/Hal/devices/volume_uuid_CAB0555EB0555255]
atime=true
quiet=false
ro=false
sync=false
uid=true
utf8=true

Not sure about KDE4 etc, haven’t had time to look.

Thanks to everybody contributing to increae our meagre knowledge in this subject. I hope we all will benefit from it.

After reading all the above, I did some experimenting.

When I am loged in (my uid=500) and I connect an USB stick, I find in /var/log/messages:

May  3 19:35:14 boven kernel: usb 2-7: new high speed USB device using ehci_hcd and address 7
May  3 19:35:14 boven kernel: usb 2-7: new device found, idVendor=0ea0, idProduct=1001
May  3 19:35:14 boven kernel: usb 2-7: new device strings: Mfr=1, Product=2, SerialNumber=0
May  3 19:35:14 boven kernel: usb 2-7: Product: Flash Disk
May  3 19:35:14 boven kernel: usb 2-7: Manufacturer: USB
May  3 19:35:14 boven kernel: usb 2-7: configuration #1 chosen from 1 choice
May  3 19:35:14 boven kernel: scsi5 : SCSI emulation for USB Mass Storage devices
May  3 19:35:14 boven kernel: usb-storage: device found at 7
May  3 19:35:14 boven kernel: usb-storage: waiting for device to settle before scanning
May  3 19:35:15 boven kernel: scsi 5:0:0:0: Direct-Access     NOR      Flash Disk       2.00 PQ: 0 ANSI: 2
May  3 19:35:16 boven kernel: ready
May  3 19:35:16 boven kernel: sd 5:0:0:0: [sdf] 119574 512-byte hardware sectors (61 MB)
May  3 19:35:16 boven kernel: sd 5:0:0:0: [sdf] Write Protect is off
May  3 19:35:16 boven kernel: sd 5:0:0:0: [sdf] Mode Sense: 03 00 00 00
May  3 19:35:16 boven kernel: sd 5:0:0:0: [sdf] Assuming drive cache: write through
May  3 19:35:16 boven kernel: sd 5:0:0:0: [sdf] 119574 512-byte hardware sectors (61 MB)
May  3 19:35:16 boven kernel: sd 5:0:0:0: [sdf] Write Protect is off
May  3 19:35:16 boven kernel: sd 5:0:0:0: [sdf] Mode Sense: 03 00 00 00
May  3 19:35:16 boven kernel: sd 5:0:0:0: [sdf] Assuming drive cache: write through
May  3 19:35:16 boven kernel:  sdf: sdf1
May  3 19:35:16 boven kernel: sd 5:0:0:0: [sdf] Attached SCSI removable disk
May  3 19:35:16 boven kernel: sd 5:0:0:0: Attached scsi generic sg6 type 0
May  3 19:35:16 boven kernel: usb-storage: device scan complete
May  3 19:35:17 boven hald: mounted /dev/sdf1 on behalf of uid 500

and I (uid 500 has username henk) am the owner of the mounted contents:

boven:/var/log # l /media/
total 40
drwxr-xr-x  3 root root  4096 May  3 19:58 ./
drwxr-xr-x 22 root root  4096 May  3 18:22 ../
-rw-r--r--  1 root root    89 May  3 19:58 .hal-mtab
-rw-------  1 root root     0 May  3 19:35 .hal-mtab-lock
drwxr-xr-x  7 henk root 27136 Jan  1  1970 disk/
boven:/var/log #       

I also of course get a KDE window asking me what I want to do with the device.
I unmounted the device and removed it.

As next step I loged in on a second logical screen with another username/uid (beheerbv/505). I connected the device. Now **both **sessions get the KDE window asking what to do. In /var/log/messages it says (only the last line is of importance here):

May  3 19:58:13 boven hald: mounted /dev/sdf1 on behalf of uid 505

And an ls of /media shows that now beheerbv is the owner of the files.
Now this is a VFAT fs so may be the protection is not so good as on an fs designed for Unix/Linux, but when there are more users loged in it seems to be to the whimsy of the system who will be the owner!

Next step. User beheerbv/505 loged out of the GUI. See /var/log/messages:

May  3 19:49:58 boven hald: unmounted /dev/sdf1 from '/media/disk' on behalf of uid 505

In fact when I looked it was either still mounted, or again remounted, but now the owner was root.
I unmounted and disconnected.

Next step. Also henk/500 loged out. With Cntrl-Alt-F1 I wet to the real console and loged in as root. I connected the device. It was not mounted. I loged in again in the GUI with henk. This was immideatly followed by the mounting of the device on behalf of user 500.

@deano_ferrari. I do not have /.kde/share/config/mediamananagerrc at all.

@brunomcl. I found mentioning of these files on the net including the fact that it could lock things at the wrong moment.

@cjcox. The labels are attached to the partitions, not to the device. found the same as syampillai: when there is label, that is used, else you get disk, disk-1, etc.

Now my first conclusions:

  1. As was allready said, it is is rather clear waht udev does (and my research is not into udev behaviour, but links with HAL are important though).
  2. HAL could mount by itself, but I can not find anything about this in its configs. And the experiments also seem to show that it is not HAL that mounts, but the DE (of course the signal comes from HAL). The experiments also seem to show that in this mount behaviour the fact that Linux is a multi-user OS is more or less forgotten :frowning:

So far from having a direct answer to my question, to me it is a very interesting subject :wink: I wait for more reactions with eagerness.

The owner/group id change to files happen only when an inferior file system like FAT is loaded. In such cases, it emulates the user/group ownership.
Just create an ext2 file system on a USB stick and try. The user/group permissions will be retained.

This was already my suggestion (though I put it more diplomatic, but I like your ‘inferior’ lol!). Nice you can confirm this. Thanks.

Do you think this will also influence for who it will be mounted? Like, when the owner of the root directory of the partition is xx and xx and yy are loged in, it will be mounted for xx? Hm, a lot of combinations are possible here. I am afraid I have to do what you suggest and create an ext2 on the stick for testing.

I still hope someone will point me to documentation on this.

Forgot to mention that the lock file is created in /media.

I am afraid I have to do what you suggest and create an ext2 on the stick for testing. I still hope someone will point me to documentation on this.

I have a memory stick with ext3 partition. Created with:

mkfs.ext3 /dev/sdb1 (Remember to make sure unmounted first).

e2label /dev/sdb1 your_label

(Similar for ext2).

The experiments also seem to show that in this mount behaviour the fact that Linux is a multi-user OS is more or less forgotten

This criticism has been widely broadcast in the past. Some old threads:

Nabble - Gnome - Utopia - Multiuser HAL/gnome-volume-manager

mount point permissions

For those who are interested, here is link to HAL specification.

You can see that also in my post #8 above. They are the .hal-mtab and .hal-mtab-lock files in /media there. They are of course in /media because /media is used as root for these mountings. And we are sill trying to find where that is defined. When we do not find it in any config file it seems to be hard-coded, which would be a major sin.

I think I found it but not sure…

strings /usr/lib/hal/hal-storage-mount | grep media

To me it looks like it is in there, certainly seems to be creating the locks. Different distro so possible hal-storage-mount is on different path.

Just I noticed these 2 why thought so
/media/%s
/media/%s-%d

Inside /usr/lib/hal:

boven:/usr/lib/hal # grep media *
Binary file hal-storage-cleanup-all-mountpoints matches
Binary file hal-storage-cleanup-mountpoint matches
Binary file hal-storage-closetray matches
Binary file hal-storage-eject matches
Binary file hal-storage-mount matches
Binary file hal-storage-unmount matches
Binary file hal-system-power-pmu matches
Binary file hald-addon-input matches
Binary file hald-addon-storage matches
Binary file hald-probe-storage matches
boven:/usr/lib/hal #      

And inside hal-storage-mount (as an example):

boven:/usr/lib/hal # strings hal-storage-mount | grep '/media'
Cannot seek to end of /media/.hal-mtab
Cannot determine size of /media/.hal-mtab
Cannot read from /media/.hal-mtab
%d: XYA creating /media/.hal-mtab~
Cannot create /media/.hal-mtab~
Out of memory appending to /media/.hal-mtab~
Cannot write to /media/.hal-mtab~
%d: XYA closing /media/.hal-mtab~
%d: XYA failed renaming /media/.hal-mtab~ to /media/.hal-mtab
Cannot rename /media/.hal-mtab~ to /media/.hal-mtab
%d: XYA done renaming /media/.hal-mtab~ to /media/.hal-mtab
Cannot obtain lock on /media/.hal-mtab
/media/%s
/media/%s-%d
Cannot open /media/.hal-mtab
/media/.hal-mtab~
%d: XYA released lock on /media/.hal-mtab-lock
%d: XYA attempting to get lock on /media/.hal-mtab-lock
%d: XYA got lock on /media/.hal-mtab-lock
Device to unmount is not in /media/.hal-mtab so it is not mounted by HAL
/media/.hal-mtab-lock
boven:/usr/lib/hal #     

These are most error messages and they mention as well as the lock file(s) as the mount point (including an added number when needed).

To me that is proof that it is hard-coded in HAL. Though it may be an parameter when you build HAL, but that is to far from the normal noob.

My conclusion until this point in the investigation:

  1. HAL and the DE work together in the mounting (at least KDE and Gnome, do not know about others DEs).
  2. When there is no DE-login there is no mounting.
  3. When there is more than one DE-login there is much uncertainty, that may overflow in unsecurity ( in the case of an ‘inferior’ fs like FAT).
  4. The mount root (inside which the mountpoints are generated, something that the user should not do) is /media and seems to be hardcoded in HAL.
  5. The name of the mountpoint is that of the label of the partition when available. When not, it is ‘disk’. A -# sequence wil be added when the name is already in use at the moment of mounting.
  6. Not unimportant and not mentioned in this thread until now (to be found in the HAL description and elsewhere), HAL will not mount when a record for the device file is available in /etc/fstab. This mean that one can have a known mass-storage device mounted on a mountpoint of choice by using one of the links in /dev/disk/by- (either one that is generated by udev according to the deafult rules, or one by adding ones own udev rule.

Did you note the section on hotplugging to me that describes the situation.

The addition of the new device is broadcast by HAL over D-Bus to whatever programs are subscribing, e.g. Thunar, which shows it as an icon in the shortcuts side panel, or Metacity/Nautilus which will add an icon to the desktop.

I say this as using lxde I get the icons in pcmanfm2 but until clicked they are not mounted.

I know that HAL anounces this on the D-Bus. In my KDE3 the “what do you want to do” window shows. Even before I do anything with that window the partition is mounted. That brings one to the idea that HAL signals the device to the DE. And the DE signals back when to mount it (KDE3 imideatly, your DE only after you click on the right spot. Then HAL mounts it inside /media as we fond out earlier.

This also explains why nothing is mounted when no DE is active. Simply no “do mount it now” command comes back.

The fact that different DEs do different things, makes the behaviour more misterious to the end-users. And that will lead to more question on the Forum.

I remember people complaining about “no icon on the desktop”. I never understood, because I never had or have this icon (and I have no wish for it). BTW, I always thought that this complaint was because they started their computer life as Windows users and that the icon behaviour is a feature/bug of this OS and they thought that that means it is something you should have. I understand from your post that either KDE4 or Nautilus (which can of course register with HAL also) does do this. (I stay with KDE3 as long as possible :()

The reason why we love linux the choices, but yes I agree the many different ways to do things does add extra complication.

Not really thought if it before, comes back to standards doubt we’ll get all the DE’s/apps to agree.

From what I can see DE is not involved but app, my other system has a mongrel of a DE it is mainly compiz-fusion but I use pcmanfm now looking at dep’s I don’t see much DE agnostic apps. OK mime maybe…
Deps of pcmanfm …
gtk2
hal
fam
startup notification
shared-mime-info
desktop-file-utils

AFAIA none of those are DE related as such perhaps they’re determined by desktop standards what ever it is. I know I have stumbled across it briefly, and is what I suspect mime and desktop-file-utils are defined by.

I know that many CLI (and alternative DE) users have had to use pmount and ivman to do the same job. Alternative hal user interfaces include exo-mount (xfce) and recently I found this halmount CLI utility.

Thanks deano_ferrari. The links and names (for googling) all point to the same conclusion.

udev seems to be a good solution to the problem of creating device files (in these dynamic days) and also provides us with possibilities to create persistent naming in these device files (already for disks by the udev rules in e.g. openSUSE, but you can e.g. make rules for yourself when you attach more then one printer).

The solution to mount dynamic disk devices is corporated in HAL. But integratiion of HAL in the rest of the system seems to be not very well thought out (at least in a Linux environment: multi user, many choices of UI). The main fault seems to be in the fact that HAL signals the availability to who registers for it and then waits for a signal to do the mount. It then mounts but only in a hard-coded root mount (/media) and only with a mountpoint directory-name it decides for itself. When it is a FAT type fs the uid belonging to the GUI is used (apperently using the uid= and gid= options). Needless to explain that when there is no software in the user environment that does register, no mount by HAL will take place. Worse is that when there are more then one of those user interfaces running on the system that did register with HAL, a competition will take place, the outcome of which may even compromise security.

My personal expirience is only with no GUI, and wth KDE3. In KDE3 the mount is done and a window “A new media is found, what do you want to do with it” is opened. I understand that in KDE4, when using Nautilus an icon is shown somewhere. I also understand that xfce users can try exo-mount.
For the CLI there seem to be several solutions (pmount, ivman, halmount) available on the net, but people are stil having configuration problems with at least some of them.

Let us hope that HAL (or a successor?) will get a better solution for the multi-login problem and that it gets a better interface for deciding where a mount must take place. Also a good description on how to register for HAL and giving it signals on what to do might be of use, so that a less misty interface for writing an automatic mount tool comes available.

My OP was started because brunomcl pointed out to me that there was a lack of description of dynamic mounting in SDB:Basics of partitions, filesystems, mount points - openSUSE. I will now try to put at least the basics of the information all of you contributed above into this Wiki. Many thanks.