HAL
From ArchWiki
| i18n |
|---|
| English |
| Polish |
| Русский |
| 简体中文 |
| Español |
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 |
[edit] HAL and hotplugging
There are a number of things 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 takes places (roughly):
- The kernel becomes aware of a new device and writes it up in /sys.
- Udev creates a device node (e.g. /dev/sdb1), and runs 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 it's database
- The addition of the new device is broadcast over D-Bus to whatever programs are subscribing, e.g. thunar which shows it as an icon in the shortcuts side pan, 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 or automount drives. Problems with hotplugged devices not being properly detected, useable, or mounted should be investigated, knowing that it is a long chain and there are more components.
[edit] Initial configuration
The hal daemon requires the presence of the dbus daemon, so we need to make sure both are installed. Open a terminal and type the following as root:
# pacman -S dbus hal
Then edit the file /etc/rc.conf as root with your favorite editor and add hal to the DAEMONS array, for example:
DAEMONS=(syslog-ng hal network netfs ...)
The hal daemon will now load at boot time. When hal initializes it will check for the presence of dbus and load it automatically. If you have dbus in your list of daemons, remove it, since it can cause problems.
You can also manually start hal by issuing the following command as root:
# /etc/rc.d/hal start
For dbus and hal to function properly, local user accounts must be members of the following groups: optical', storage , "hal"'. To achieve this, open a terminal and type the following commands as root:
# gpasswd -a username optical # gpasswd -a username storage # gpasswd -a username hal
Replace username with your actual username (e.g. johndoe).
To check that you've successfully added the user to the groups, you can try
$ groups USERNAME
If you started the hal daemon before adding yourself to these groups, you should restart both dbus and hal for these changes to take affect. You can achieve this by typing as root:
# /etc/rc.d/dbus restart # /etc/rc.d/hal restart
[edit] Policies
[edit] Permissions policies
The configuration file /etc/dbus-1/system.d/hal.conf specifies HAL-specific security policies. These are defined as exceptions to the overall restrictions imposed on using the D-Bus, specified in /etc/dbus-1/system.conf, granting users or groups of users the right to access specific DBUS/HAL services, such as ejecting a drive or mounting a partition.
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):
<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. 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>
Which is why you will want to add your user to those groups (see 'Initial configuration'), thus reducing the number of customized configuration files. A less elegant solution is inserting your user name into the user policy section granting access to all the HAL devices listed (replace the zero with your user name):
<policy user="0"> <allow send_interface="org.freedesktop.Hal.Device.SystemPowerManagement"/> <allow send_interface="org.freedesktop.Hal.Device.VideoAdapterPM"/> <allow send_interface="org.freedesktop.Hal.Device.LaptopPanel"/> <allow send_interface="org.freedesktop.Hal.Device.Volume"/> <allow send_interface="org.freedesktop.Hal.Device.Volume.Crypto"/> </policy>
[edit] Device specific policies
[edit] NTFS
Add the following to /usr/share/hal/fdi/policy/10osvendor/20-ntfs-config-write-policy.fdi (create file if it doesn't exist)
<?xml version="1.0" encoding="UTF-8"?>
<deviceinfo version="0.2">
<device>
<match key="volume.fstype" string="ntfs">
<match key="@block.storage_device:storage.hotpluggable" bool="true">
<merge key="volume.fstype" type="string">ntfs-3g</merge>
<merge key="volume.policy.mount_filesystem" type="string">ntfs-3g</merge>
<append key="volume.mount.valid_options" type="strlist">locale=</append>
</match>
</match>
</device>
</deviceinfo>
[edit] mount.ntfs linking
As of hal => 0.5.10 the above policy may not work. This is a workaround forcing hal to use the ntfs-3g driver instead of the standard ntfs driver. Please note that this method will use the ntfs-3g driver for all NTFS drives on your system! 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 "-i" option it doesn't work
- possible issues with the kernels ntfs module
[edit] Locale issues
If you use KDE, you may have problem with filenames containing non-latin characters. This happens because kde's mounthelper is not parsing correctly the policies and locale option. There is a workaround for this:
1) Remove the "/sbin/mount.ntfs-3g" which is a symlink. code: rm /sbin/mount.ntfs-3g
2) 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
3) Make it executable: chmod +x /sbin/mount.ntfs-3g
4) Add NoUpgrade=sbin/sbin/mount.ntfs-3g to pacman.conf.
[edit] Allow dmask and fmask for ntfs-3g
dmask and fmask are very useful for setting different access rights for directories and files, e.g. dmask=000,fmask=111 will make directories accessible to all, while files will stay non-executable.
<device>
<match key="volume.fstype" string="ntfs">
<append key="volume.mount.valid_options" type="strlist">dmask=</append>
<append key="volume.mount.valid_options" type="strlist">fmask=</append>
</match>
</device>
[edit] Set iPod mountpoint
If you don't tell hal where to mount ipods it will mount them under whatever you name your ipod. To change this you must make a policy for hal.
<device>
<match key="@block.storage_device:storage.model" string="iPod">
<merge key="volume.policy.desired_mount_point" type="string">ipod</merge>
<merge key="volume.policy.mount_option.iocharset=iso8859-15" type="bool">true</merge>
<merge key="volume.policy.mount_option.sync" type="bool">true</merge>
</match>
</device>
[edit] Auto-mount only removable media
By default hal automounts all available partitions not mounted in /etc/fstab and create desktop icons for them. To override this behavior and automount only removable drives, just add this rule:
<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>
If you are running KDE, and the device is being automounted (i.e. it comes up in Konquerer), but it is not on the desktop go to control center -> Desktop -> Behavior -> Device Symbols (3rd Tab) and make sure the box is checked.
[edit] Put sync and noatime on for devices smaller than 8GB and off for devices larger than that
This could avoid data corruption on small drives (like USB flash drives), while improving performances with larger drives (assumed 1GB = 1000000000 byte).
<device>
<match key="block.is_volume" bool="true">
<match key="volume.size" compare_lt="8000000000">
<match key="@block.storage_device:storage.hotpluggable" bool="true">
<merge key="volume.policy.mount_option.sync" type="bool">true</merge>
<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.sync" type="bool">true</merge>
<merge key="volume.policy.mount_option.noatime" type="bool">true</merge>
</match>
</match>
<match key="volume.size" compare_ge="8000000000">
<match key="@block.storage_device:storage.hotpluggable" bool="true">
<merge key="volume.policy.mount_option.sync" type="bool">false</merge>
<merge key="volume.policy.mount_option.noatime" type="bool">false</merge>
</match>
<match key="@block.storage_device:storage.removable" bool="true">
<merge key="volume.policy.mount_option.sync" type="bool">false</merge>
<merge key="volume.policy.mount_option.noatime" type="bool">false</merge>
</match>
</match>
</match>
</device>
[edit] ... finally
Remember to restart the hal-daemon for your changes to take effect immediately:
# /etc/rc.d/hal restart
[edit] Troubleshooting
[edit] Security error
If inserted CD/DVDs are recognized and an icon is placed on the desktop, but you are not able to open and explore the device, then the device is recognised by the udev system but something is preventing HAL from mounting it. If double-clicking the icon gives the error window "A security policy prevents this sender from sending this message to this recipient...", you will need to check your permissions settings (see the 'Initial configuration' and 'Permissions policies' sections).
[edit] Inserted CD/DVD are not recognized by hal
If inserted CDs/DVDs are not recognized by hal (no icon on the desktop), check the /etc/fstab and remove the lines for the optical drives.
[edit] 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 automounting 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 this file:
/usr/share/hal/fdi/policy/gparted-disable-automount.fdi
as being mentionned at the end of this thread [1]
[edit] Using PMount
If like me you couldn't get any of the above to work you may try to install pmount. PMount is a wrapper around the standard mount program which permits normal users to mount removable devices without a matching /etc/fstab entry.
# pacman -Sy pmount
[edit] External links
HAL 0.5.10 specifications - A comprehensive HAL specification and introduction
Dam's blog - An attempt to clarify the division of labour among the kernel, udev, d-bus and hal with links to howtos and faqs on each.
Dynamic Device Handling (pdf) - A presentation of device handling.