HAL
From ArchWiki
Article summary |
---|
Information on installing, configurating and troubleshooting HAL. |
Languages |
English |
Español |
简体中文 |
Français |
Italiano |
Polish |
Русский |
Türkçe |
HAL (Hardware Abstraction Layer) is a daemon that allows desktop applications to readily access hardware information so that they can locate and use such hardware regardless of bus or device type. In this way a desktop GUI can present all resources to its user in a seamless and uniform manner.
Contents |
Overview
There are a number of factors involved in 'hotplugging' and HAL is only one of them. When a new device is added, e.g. a USB drive is plugged in, the following occurs (roughly):
- The kernel becomes aware of a new device and registers it in /sys.
- Udev creates a device node (e.g. /dev/sdb1), and loads the drivers/modules needed.
- The HAL daemon is notified by D-Bus and adds the device and what it can find out about it to its database.
- 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.
- Another program listening may be a volume manager, such as thunar-volman or AutoFS, configured to automatically create mount points and mount certain types of drives, start Rhythmbox whenever an iPod is connected, etc.
HAL does not detect the hardware (kernel), manage the devices or the drivers (udev) or automount drives (volume managers). As a hardware abstraction layer, its role is more akin to a communications center, providing your applications with a clean interface to the devices. Problems with hot-plugged devices not being properly detected, usable, or mounted should be investigated, knowing that it is a long chain and there are more components involved (see 'Troubleshooting').
About volumes mount points
HAL mounts your volumes under /media/some_folder. To determine what some_folder should be it uses the label of a volume or, if the volume does not have a label, it uses the volume's type (eventually followed by a number if the directory already exists), for example: /media/disk, /media/disk-1 ...
To give a label to a partition you can use GParted (available in extra) or its KDE equivalent PartitionManager (available in AUR).
Also keep in mind these three common problems that stop HAL from mounting a device:
- the directory /media/label_of_your_volume must not exist, it will be dynamically created and destroyed by HAL
- the device must not be listed in fstab, otherwise HAL will refuse to mount it
- you must have the right to mount the device, see Permission Denied for more details
If for some reason you cannot give a label to your partition you can give a fake label to HAL, you will need two things to do so:
- $device_uuid, the uuid of the device (ls -l /dev/disk/by-uuid/ may help you for that)
- $device_name, the fake label you chose
Place this into /etc/hal/fdi/policy/20-$device_name.fdi without forgetting to replace $device_uuid and $device_name by their values.
<?xml version="1.0" encoding="UTF-8"?> <deviceinfo version="0.2"> <device> <match key="volume.uuid" string="$device_uuid"> <merge key="volume.label" type="string">$device_name</merge> </match> </device> </deviceinfo>
Install and configure HAL
Step 1: Install
The HAL daemon requires the presence of the D-Bus daemon, so we need to make sure both are installed.
# pacman -S hal dbus
Edit /etc/rc.conf as root with your favorite editor and add dbus & hal to the DAEMONS array, for example:
DAEMONS=(syslog-ng dbus hal network netfs ...)
The DBus and HAL daemons will now load at boot time. While HAL would load dbus automatically if it was not already running it would not unload it properly at shutdown. Therefore to avoid any complications it is best to load DBus before HAL through your daemons array.
NOTE: Some people have reported problems with this setup. If you also experience problems also you should try loading hal first followed by dbus.
Or, you could start HAL manually by issuing the following command as root:
# /etc/rc.d/hal start
For D-Bus and HAL to be of any practical use, local user accounts should be members of the following groups: optical and storage. To achieve this, open a terminal and type the following commands as root:
# gpasswd -a username optical # gpasswd -a username storage Replace username with your actual username (e.g. johndoe).
For those group changes to take effect, you have to completely logout and login again.
Step 2: Configure
Your programs communicate with HAL controlled devices through a D-Bus interface. A number of interfaces are defined, each associated with a number of methods: The storage device interface, for example, has the methods 'eject' and 'close tray' (for optical drives). In order to 'mount' a partition on a USB key, you need access to the relevant D-Bus interface ('volume' in this case).
The configuration file /etc/dbus-1/system.d/hal.conf specifies HAL-specific privileges, i.e. which users have access to which interfaces. These are defined as exceptions to the overall restrictions imposed on using D-Bus interfaces, specified in /etc/dbus-1/system.conf. In short, you will need to see that hal.conf grants your user the right to access specific DBUS/HAL interfaces, because the D-Bus default is not to let you access them.
The default hal.conf will contain a number of policies denying and allowing access, amongst them this default (the later of two defaults and therefore seemingly the deciding one):
<!-- Default policy for the exported interfaces --> <policy context="default"> <deny send_interface="org.freedesktop.Hal.Device.SystemPowerManagement"/> <deny send_interface="org.freedesktop.Hal.Device.VideoAdapterPM"/> <deny send_interface="org.freedesktop.Hal.Device.LaptopPanel"/> <deny send_interface="org.freedesktop.Hal.Device.Volume"/> <deny send_interface="org.freedesktop.Hal.Device.Volume.Crypto"/> </policy>
In short, users are by default denied access to interfaces like Volume which has methods such as mount and unmount. This is overruled by policies allowing users of the groups 'power' and 'storage' to access their respective devices:
<policy group="power"> <allow send_interface="org.freedesktop.Hal.Device.SystemPowerManagement"/> <allow send_interface="org.freedesktop.Hal.Device.LaptopPanel"/> </policy> <policy group="storage"> <allow send_interface="org.freedesktop.Hal.Device.Volume"/> <allow send_interface="org.freedesktop.Hal.Device.Volume.Crypto"/> </policy>
That is why you will want to add your user to those groups, thus reducing the number of customized configuration files.
Device specific policies
NTFS write access
Upon installing ntfs-3g, a HAL policy file will be created at /usr/share/hal/fdi/policy/10osvendor. This will use ntfs-3g for all NTFS volumes. Simply restart HAL, and NTFS volumes should be writeable.
Enable the noatime mount option for removable devices
This will speed up file operations and also reduce wear on flash memory devices like USB sticks or SD cards.
<device> <match key="block.is_volume" bool="true"> <match key="@block.storage_device:storage.hotpluggable" bool="true"> <merge key="volume.policy.mount_option.noatime" type="bool">true</merge> </match> <match key="@block.storage_device:storage.removable" bool="true"> <merge key="volume.policy.mount_option.noatime" type="bool">true</merge> </match> </match> </device>
Disable Automount on login
You may want to disable automounting of ntfs(/or other filesystem) partitions on login.
<device> <match key="storage.hotpluggable" bool="false"> <match key="storage.removable" bool="false"> <merge key="storage.automount_enabled_hint" type="bool">false</merge> </match> </match> </device>
Step 3: Start or re-start HAL
For your changes to take effect you need to (re)start HAL:
# /etc/rc.d/hal restart
Troubleshooting
Mounting fails
IsCallerPrivileged failed
If you get a message "IsCallerPriviliged failed" and are not using KDM or GDM, use ck-launch-session (part of the consolekit package) to start your DE/WM.
For example with startx/KDE, this was originally in ~/.xinitrc:
exec startkde
The new version:
exec ck-launch-session startkde
Cannot mount internal drives from Gnome
If you cannot mount your internal drives in Gnome (by clicking on them in Nautilus), open Authorizations under System -> Preferences, then navigate to org.freedesktop.hal.storage. Select Mount file systems from internal drives, click on Edit, and change Active Console to Yes.
Permission Denied
If you just upgraded to hal-0.5.11-7 and suddenly mounting a device stopped working for non-root users with one of these errors:
- "PermissionDeniedByPolicy mount-removable no"
- "PermissionDeniedByPolicy mount-removable-extra-options no"
- "org.freedesktop.hal.storage.mount-removable no <-- (action, result)"
- "org.freedesktop.hal.storage.mount-removable-extra-options no <-- (action, result)"
you can fix the situation by editing /etc/PolicyKit/PolicyKit.conf and paste the following into the <config> section:
<match user="$USER"> <!-- replace with your login or delete the line if you want to allow all users to manipulate devices (keep security issues in mind though) --> <match action="org.freedesktop.hal.storage.*"> <return result="yes"/> </match> <match action="hal-storage-mount-fixed-extra-options"> <!-- for internal devices mounted with extra options like a wished mount point --> <return result="yes" /> </match> <match action="hal-storage-mount-removable-extra-options"> <!-- for external devices mounted with extra options like a wished mount point --> <return result="yes" /> </match> </match> <!-- do not forget to delete this line if you deleted the first one -->
Restart dbus and hal. If you used KDE you will have to restart KDE as well (the device notifier will not get it otherwise and will stop responding altogether). This was taken from Gullible Jones' "So long, Arch" thread as a hotfix for exactly this type of breakage and is probably not the best fix (especially for machines with a large number of users), but it works.
Alternate Fixes
- Allowing everything (not recommended because of security constraints):
<match user="yourusername"> <return result="yes"/> </match>
- If you start your window manager from .xinitrc, see suggestion 2 entries up under HAL:IsCallerPrivileged failed
- You could also:
<config version="0.1"> <define_admin_auth user="USER"/> </config>
Where USER is your username
This gives the user specified admin authority which is the same hal authority level used by the hal and root users:
exec ck-launch-session window-manager
Auto-mounting fails
Inserted CD/DVD does not get recognized by HAL
If inserted CDs/DVDs are not recognized by HAL (no icon on the desktop or notification), check /etc/fstab and remove the lines for the optical drives.
If that does not work, it may be because your device is not "checked" for automount by HAL. I am not sure why but you may have a file under /etc/hal/fdi/information/media-check-disable-storage_model_$YOUR_DEVICE.fdi which should have a content similar to:
<deviceinfo version="0.2"> <device> <match key="info.udi" string="/org/freedesktop/Hal/devices/storage_model_DV$ <merge key="storage.media_check_enabled" type="bool">false</merge> </match> </device> </deviceinfo>
If the key is set to false (it was in my case), all you have to do is to change the value of the key to true.
USB sticks and drives do not automount correctly
This sub-section is sourced from this forum page.
If you are experiencing problems with automounting USB sticks and/or drives, but do not have problems with mounting CDs or DVDs, and if you are able to manually mount the USB device in question, then you should create the file "preferences.fdi" in the folder /etc/hal/fdi/policy and paste the following line into the file
<merge key="volume.ignore" type="bool">false</merge>
Also, if you have GParted installed, you might need to delete /usr/share/hal/fdi/policy/gparted-disable-automount.fdi as mentioned at the end of [1].
Also you should remove from /etc/fstab lines, corresponding to usb devices which should be mounted by hal automatically.
If this still doesn't work, follow the guidelines in [2].
Removing USB flash causes improper unmount
If you remove your USB flash without previously unmounting it, automatic unmount by HAL may work improperly.
You may find that corresponding records from /media/.hal-mtab is not deleted, and in nautilus device list (and also on GNOME desktop) remains link to an empty folder, where the device was previously mounted.
This may be corrected by unmounting flash drive with "lazy" parameter. To do so, you should do some tweaking:
1) Create an executable script /usr/lib/hal/hal-unmount.sh with access rights 755 and the following content
#!/bin/sh # sanity check. DEVNAME should start with a / [ "$DEVNAME" != "${DEVNAME#/}" ] || exit 0 # Lazily unmount drives which are removed, but still mounted if [ "$ACTION" = remove ] ; then if [ -x /usr/bin/pumount ] ; then /usr/bin/pumount -l "$DEVNAME"; else /bin/umount -l "$DEVNAME"; fi fi exit 0
2) Then you should tell HAL to run this script when you remove your usb stick. To do so, you should add to /etc/udev/rules.d/90-hal.rules the following line:
SUBSYSTEM=="block", ACTION=="remove", RUN+="/usr/lib/hal/hal-unmount.sh"
3) Execute
# /etc/rc.d/hal restart
NTFS issues
The last resort
If the above policy does not work (make sure you restarted hal) you can force HAL (and all your other programs) to use the ntfs-3g driver instead of the standard ntfs driver. As root create a symbolic link from mount.ntfs to mount.ntfs-3g:
# ln -s /sbin/mount.ntfs-3g /sbin/mount.ntfs
Possible issues using this method:
- if mount is called with the "-i" option it does not work
- possible issues with the kernel ntfs module
Locale issues
You may have problem with filenames containing non-latin characters. This happens because your mounthelper is not parsing the policies and locale option correctly. There is a workaround for this:
- Remove this symlink: rm /sbin/mount.ntfs-3g
- Replace it with a new bash script containing:
#!/bin/bash /bin/ntfs-3g $1 "$2" -o locale=en_US.UTF-8,$4 # put your own locale here
- Make it executable: chmod +x /sbin/mount.ntfs-3g
- Add a line to the pacman configuration file:
... NoUpgrade = sbin/mount.ntfs-3g ...
External links
- A comprehensive HAL specification and introduction
- An attempt to clarify the division of labor among the kernel, udev, D-Bus and HAL with links to HOWTOs and FAQs on each
- A presentation of device handling