HAL (Italiano)

From ArchWiki
Revision as of 11:24, 12 November 2008 by Pikiweb (Talk | contribs) (Initial configuration)

Jump to: navigation, search

Tango-preferences-desktop-locale.pngThis article or section needs to be translated.Tango-preferences-desktop-locale.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:HAL (Italiano)#)
Template:I18n links start

Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end

HAL (Hardware Abstraction Layer) è un demone che permette alle applicazioni desktop di accedere velocemente alle informazioni hardware, di modo che possono localizzare e usare tale hardware senza badare al bus o al tipo di device. In questa maniera una GUI può presentare tutte le risorse all'utente in modo uniforme e coerente.

HAL e l'hotplugging

Ci sono più elementi coinvolti nell' 'hotplugging' e HAL è solo uno di loro. Quando si aggiunge un nuovo device, per esempio si connette un'unià USB, succede quanto segue (brevemente):

  • Il kernel si accorge di un nuovo device e lo scrive su /sys.
  • Udev crea un device node (p. es. /dev/sdb1), e carica i driver/moduli necessari.
  • Il demone HAL è informato da D-Bus e aggiunge il device e quanto può sapere di esso al proprio database.
  • L'aggiunta del nuovo device è trasmessa da HAL attraverso D-Bus ad ogni programma che ne faccia richiesta, per esempio Thunar che lo mostra come icona nel pannello laterale delle scorciatoie o Metacity/Nautilus che aggiunge un'icona al desktop.
  • Un altro programma in ascolto potrebbe essere un volume manager, come thunar-volman AutoFS, configurato per creare automaticamente i punti di mount e montare certi tipi di unità , per avviare Rhythmbox quando si connette un iPod, ecc..

HAL non rileva l'hardware (lo fa il kernel), non gestisce i device o i driver (udev) o monta in automatico le unità (volume manager). Il suo ruolo è più affine a una centrale di comunicazioni che offre un'interfaccia pulita e semplice verso i device alle applicazioni. I problemi con device connessi a caldo (hotplug) non propriamente rilevati, usabili, o montati, dovrebbero essere esaminati, sapendo che è una lunga catena e ci sono vari componenti coinvolte (vedere 'Risoluzione di problemi').

Configurazione iniziale

Il demone HAL richiede la presenza del demone D-Bus, perciò è necessario accertarsi che siano installati entrambi.

Se si vuole, si può installare pmount:

Aprite un terminale e digitate quanto segue come root:

# pacman -S pmount

Oltre a installare pmount, che permette agli utenti normali di montare le unità rimovibili senza il contributo di sudo o modificando prima /etc/fstab, questo comando porterà i pacchetti D-Bus e HAL come dipendenze.

Comunque, si può anche installare solo HAL e D-Bus:

# pacman -S hal dbus

Sia che si scelga di installare pmount, sia che no, continuate con quanto segue: Modificate il file /etc/rc.conf da root con il proprio editor preferito e aggiungete hal all'array DAEMONS, per esempio:

DAEMONS=(syslog-ng hal network netfs ...)

Il demone HAL ora si caricherà al boot. Quando HAL si inizializzerà, controllerà la presenza di D-Bus e lo caricherà automaticamente. Se avete dbus nella vostra lista di demoni, cancellatelo, dato che può creare problemi.

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.

Policies

Permissions policies

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 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):

<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>

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>

Device specific policies

NTFS

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"?> 
<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>

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: 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/mount.ntfs-3g" to /etc/pacman.conf.


Here's an alternative solution for the problem with non-latin characters:

1) Open a shell as root

2) Type: "mv /sbin/mount.ntfs-3g /sbin/mount.ntfs-3g.sav"

3) Create the file /sbin/mount.ntfs-3g containing:

#!/bin/bash
/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 "NoUpgrade = sbin/mount.ntfs-3g" to /etc/pacman.conf.

6) Change in /usr/share/hal/fdi/policy/10osvendor/20-storage-methods.fdi the section ntfs to the following

<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>
 <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>
 </match>

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>

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.

  <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>

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:

 <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 Konqueror), but it is not on the desktop go to Control Center -> Desktop -> Behavior -> Device Symbols (3rd Tab) 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.

 <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>

... finally

Remember to restart the HAL-daemon for your changes to take effect immediately:

# /etc/rc.d/hal restart

Troubleshooting

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 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 mentioned at the end of this thread: [1]

If

# 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

HAL 0.5.10 specifications - A comprehensive HAL specification and introduction.

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.

Dynamic Device Handling (pdf) - A presentation of device handling.