Difference between revisions of "HAL (Italiano)"

From ArchWiki
Jump to: navigation, search
(hal è deprecato.. redirect a udev)
(42 intermediate revisions by 7 users not shown)
Line 1: Line 1:
[[Category: Hardware detection and troubleshooting (Italiano)]]
#REDIRECT [[udev (Italiano)]]
[[Category:Daemons and system services (Italiano)]]
[[Category:HOWTOs (Italiano)]]
{{i18n_entry|简体中文|HAL (简体中文)}}
{{i18n_entry|Español|HAL (Español)}}
{{i18n_entry|Italiano|HAL (Italiano)}}
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.
=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 place (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 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). Its role is more akin to a communications central, providing your applications with a nice, clean interface to the devices. Problems with hotplugged 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').
=Initial configuration=
The HAL daemon requires the presence of the D-Bus daemon, so we need to make sure both are installed.
'''If desired, you may want to install pmount:'''
Open a terminal and type the following as root:
# pacman -S pmount
Besides installing pmount, which lets normal users mount removable devices without the aid of sudo or editing /etc/fstab beforehand, this will also pull in the D-Bus and HAL packages as dependencies.
'''However, you also can just install HAL and D-Bus:'''
# pacman -S hal dbus
No matter if you choose to install pmount or not, continue with the following:
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 D-Bus and load it automatically. If you have '''dbus''' in your list of daemons, remove it, since it can cause problems.
You can also 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.
==Permissions policies==
Your programs communicate with HAL controlled devices through a D-Bus interface. A number of [http://people.freedesktop.org/~david/hal-spec/hal-spec.html#interfaces 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 acces 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. what users have access to what 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'll 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"/>
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 group="storage">
  <allow send_interface="org.freedesktop.Hal.Device.Volume"/>
  <allow send_interface="org.freedesktop.Hal.Device.Volume.Crypto"/>
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):
  <!-- You can change this to a more suitable user, or make per-group -->
  <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"/>
==Device specific policies==
Add the following to /usr/share/hal/fdi/policy/10osvendor/20-ntfs-config-write-policy.fdi (create the file if it doesn't exist)
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- SGML -*- -->
<deviceinfo version="0.2">
        <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>
=== 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 the "-i" option it doesn't work
* possible issues with the kernel ntfs module
=== 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 the policies and locale option correctly. There is a workaround for this:
1) Remove this symlink: <code>rm /sbin/mount.ntfs-3g</code>
2) Replace it with a new bash script containing:
/bin/ntfs-3g $1 "$2" -o locale=en_US.UTF-8,$4 #put your own locale here
3) Make it executable: <code>chmod +x /sbin/mount.ntfs-3g</code>
4) Add "<code>NoUpgrade = sbin/mount.ntfs-3g</code>" to /etc/pacman.conf.
Here's an alternative solution for the problem with non-latin characters:
1) Open a shell as root
2) Type: "<code>mv /sbin/mount.ntfs-3g /sbin/mount.ntfs-3g.sav</code>"
3) Create the file <code>/sbin/mount.ntfs-3g</code> containing:
/sbin/mount.ntfs-3g.sav $1 $2 -o locale=de_DE.UTF-8
Change locale accordingly to your system.
4) Make the newly created file executable
chmod +x /sbin/mount.ntfs-3g
5) Add "<code>NoUpgrade = sbin/mount.ntfs-3g</code>" to <code>/etc/pacman.conf</code>.
6) Change in <code>/usr/share/hal/fdi/policy/10osvendor/20-storage-methods.fdi</code> the section ntfs to the following
<!-- allow these mount options for ntfs -->
<match key="volume.fstype" string="ntfs">
  <match key="/org/freedesktop/Hal/devices/computer:system.kernel.name" string="Linux">
    <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">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">dmask=</append>
  <append key="volume.mount.valid_options" type="strlist">fmask=</append>
  <append key="volume.mount.valid_options" type="strlist">locale=</append>
  <append key="volume.mount.valid_options" type="strlist">utf8</append>
  <match key="/org/freedesktop/Hal/devices/computer:system.kernel.name" string="FreeBSD">
    <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">-u=</append>
  <append key="volume.mount.valid_options" type="strlist">-g=</append>
  <append key="volume.mount.valid_options" type="strlist">-m=</append>
  <append key="volume.mount.valid_options" type="strlist">-a</append>
  <append key="volume.mount.valid_options" type="strlist">-i</append>
  <append key="volume.mount.valid_options" type="strlist">-C=</append>
  <append key="volume.mount.valid_options" type="strlist">-W=</append>
===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.
    <!-- mount ntfs volume with the ntfs-3g driver to enable write support -->
        <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>
===Set iPod mountpoint===
If you don't tell HAL where to mount iPods it will mount them under /media in a directory named after your iPod. To change this you must make a policy for HAL.
    <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>
According to the logic of syntax the line:
<merge key="volume.policy.mount_option.iocharset=iso8859-15" type="bool">true</merge>
might be instead:
<merge key="volume.policy.mount_option.iocharset" type="string">iso8859-15</merge>
To be tested if the first writing doesn't seem to work, because the HAL developers might have changed that.
===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:
    <match key="storage.hotpluggable" bool="false">
      <match key="storage.removable" bool="false">
        <merge key="storage.automount_enabled_hint" type="bool">false</merge>
If you are running KDE and the device is being automounted (i.e. it comes up in Konqueror), but it is not on the desktop go to <tt>Control Center -> Desktop -> Behavior -> Device Symbols (3rd Tab)</tt> and make sure the box is checked.
===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.
    <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 key="@block.storage_device:storage.removable" bool="true">
        <merge key="volume.policy.mount_option.noatime" type="bool">true</merge>
===... finally===
Remember to restart the HAL-daemon for your changes to take effect immediately:
# /etc/rc.d/hal restart
==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).
==Inserted CD/DVD doesn't get recognized by HAL==
If inserted CDs/DVDs are not recognized by HAL (no icon on the desktop), check /etc/fstab and remove the lines for the optical drives.
==USB sticks and drives do not automount correctly==
This sub-section is sourced from [http://bbs.archlinux.org/viewtopic.php?pid=248224 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:
... as being mentioned at the end of this thread: [http://bbs.archlinux.org/viewtopic.php?pid=310284]
# hald --verbose=yes --daemon=no
says something like
18:50:59.028 [I] blockdev.c:502: Probing storage device /dev/sda
Run started hald-probe-storage (10000) (0)  
!  full path is '/usr/lib/hal/hald-probe-storage', program_dir is '/usr/lib/hal'
/usr/lib/hal/hald-probe-storage: error while loading shared libraries: libvolume_id.so.1: cannot open shared object file: No such file or directory
You'd have to create a symlink to the library:
# ln -s /lib/libvolume_id.so.0 /lib/libvolume_id.so.1
=External links=
[http://people.freedesktop.org/~david/hal-spec/hal-spec.html HAL 0.5.10 specifications] - A comprehensive HAL specification and introduction.
[http://dventurin.blogspot.com/2007/04/udev-hal-dbus.html Dam's blog] - An attempt to clarify the division of labor among the kernel, udev, D-Bus and HAL with links to HOWTOs and FAQs on each.
[http://people.freedesktop.org/~david/talks/dynamic-device-handling-OLS-2006.pdf Dynamic Device Handling (pdf)] - A presentation of device handling.

Latest revision as of 21:53, 27 December 2012

Redirect to: