https://wiki.archlinux.org/api.php?action=feedcontributions&user=Hit&feedformat=atomArchWiki - User contributions [en]2024-03-28T17:35:43ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=HAL&diff=60245HAL2009-02-06T10:33:40Z<p>Hit: /* Could not get UID and GID */</p>
<hr />
<div>[[Category: Hardware detection and troubleshooting (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
[[Category:HOWTOs (English)]]<br />
<br />
{{i18n_links_start}}<br />
{{i18n_entry|English|HAL}}<br />
{{i18n_entry|Polish|HAL_(Polski)}}<br />
{{i18n_entry|Русский|HAL_(Русский)}}<br />
{{i18n_entry|简体中文|HAL (简体中文)}}<br />
{{i18n_entry|Español|HAL (Español)}}<br />
{{i18n_entry|Italiano|HAL (Italiano)}}<br />
{{i18n_entry|Türkçe|HAL (Türkçe)}}<br />
{{i18n_links_end}}<br />
<br />
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.<br />
<br />
=HAL and hotplugging=<br />
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):<br />
* The kernel becomes aware of a new device and writes it up in /sys.<br />
* [[Udev]] creates a device node (e.g. /dev/sdb1), and runs the drivers/modules needed.<br />
* The HAL daemon is notified by [[D-Bus]] and adds the device and what it can find out about it to its database.<br />
* 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.<br />
* 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.<br />
<br />
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').<br />
<br />
=Initial configuration=<br />
The HAL daemon requires the presence of the D-Bus daemon, so we need to make sure both are installed. <br />
<br />
'''If desired, you may want to install pmount:'''<br />
<br />
Open a terminal and type the following as root:<br />
# pacman -S pmount<br />
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.<br />
<br />
'''However, you also can just install HAL and D-Bus:'''<br />
# pacman -S hal dbus<br />
No matter if you choose to install pmount or not, continue with the following:<br />
Then edit the file ''/etc/rc.conf'' as root with your favorite editor and add '''hal''' to the DAEMONS array, for example:<br />
DAEMONS=(syslog-ng '''hal''' network netfs ...)<br />
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.<br />
<br />
You can also start HAL manually by issuing the following command as root:<br />
# /etc/rc.d/hal start<br />
<br />
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:<br />
# gpasswd -a ''username'' optical<br />
# gpasswd -a ''username'' storage<br />
Replace ''username'' with your actual username (e.g. johndoe).<br />
<br />
For those group changes to take effect, you have to completely logout and login again.<br />
<br />
=Policies=<br />
<br />
==Permissions policies==<br />
<br />
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 access to the relevant D-Bus interface ('volume' in this case). <br />
<br />
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.<br />
<br />
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):<br />
<br />
<!-- Default policy for the exported interfaces --><br />
<policy context="default"><br />
<deny send_interface="org.freedesktop.Hal.Device.SystemPowerManagement"/><br />
<deny send_interface="org.freedesktop.Hal.Device.VideoAdapterPM"/><br />
<deny send_interface="org.freedesktop.Hal.Device.LaptopPanel"/><br />
<deny send_interface="org.freedesktop.Hal.Device.Volume"/><br />
<deny send_interface="org.freedesktop.Hal.Device.Volume.Crypto"/><br />
</policy><br />
<br />
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:<br />
<br />
<policy group="power"><br />
<allow send_interface="org.freedesktop.Hal.Device.SystemPowerManagement"/><br />
<allow send_interface="org.freedesktop.Hal.Device.LaptopPanel"/><br />
</policy><br />
<br />
<policy group="storage"><br />
<allow send_interface="org.freedesktop.Hal.Device.Volume"/><br />
<allow send_interface="org.freedesktop.Hal.Device.Volume.Crypto"/><br />
</policy><br />
<br />
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):<br />
<br />
<!-- You can change this to a more suitable user, or make per-group --><br />
<policy user="0"><br />
<allow send_interface="org.freedesktop.Hal.Device.SystemPowerManagement"/><br />
<allow send_interface="org.freedesktop.Hal.Device.VideoAdapterPM"/><br />
<allow send_interface="org.freedesktop.Hal.Device.LaptopPanel"/><br />
<allow send_interface="org.freedesktop.Hal.Device.Volume"/><br />
<allow send_interface="org.freedesktop.Hal.Device.Volume.Crypto"/><br />
</policy><br />
<br />
==Device specific policies==<br />
<br />
===NTFS===<br />
Add the following to /etc/hal/fdi/policy/20-ntfs-config-write-policy.fdi (create the file if it doesn't exist)<br />
<br />
Note: This config file has been tested with hal = 0.5.11 and correctly identifies/mounts (external) ntfs devices with ntfs-3g. 'mount' should display the filesystem type as 'fuseblk' if this configuration file is correctly detected.<br />
<br />
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- SGML -*- --><br />
<deviceinfo version="0.2"><br />
<device><br />
<match key="volume.fstype" string="ntfs"><br />
<match key="@block.storage_device:storage.hotpluggable" bool="true"><br />
<merge key="volume.fstype" type="string">ntfs-3g</merge><br />
<merge key="volume.policy.mount_filesystem" type="string">ntfs-3g</merge><br />
<append key="volume.mount.valid_options" type="strlist">locale=</append><br />
</match><br />
</match><br />
</device><br />
</deviceinfo><br />
<br />
If you use pcmanfm as FM, you have to tell it explicitely how to manage the ntfs-3g driver. It is not difficult, you just have to edit the config file at /usr/share/pcmanfm/mount.rules like the following:<br />
<br />
[ntfs-3g]<br />
# mount_options=locale=;exec<br />
mount_options=uid=1000;gid=100;fmask=0113;dmask=0002;locale=;exec<br />
<br />
Obviously, you can select the permission that you want.<br />
<br />
=== mount.ntfs linking ===<br />
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.<br />
<br />
Note: This should only be used as a last resort 'hack' if HAL is unable to properly recognize and mount (rw) ntfs drives.<br />
<br />
# ln -s /sbin/mount.ntfs-3g /sbin/mount.ntfs<br />
<br />
Possible issues using this method:<br />
* if mount is called with the "-i" option it doesn't work<br />
* possible issues with the kernel ntfs module<br />
<br />
===Mount a device to a specific mount point===<br />
To tell HAL where to mount a device you need two things:<br />
* $device_uuid, the uuid of the device (<code>ls -l /dev/disk/by-uuid/</code> can help)<br />
* $device_name, the name you want to give to the device, the device will be mounted in '''/media/$device_name'''<br />
{{Box Note | The directory /media/$device_name must '''NOT''' exists, it will be created and deleted by HAL.}}<br />
{{Box Note | The device must '''NOT''' be listed in fstab otherwise HAL will refuse to mount it.}}<br />
<br />
Place this into "<code>/etc/hal/fdi/policy/20-$device_name.fdi</code>" without forgetting to replace $device_uuid and $device_name by their values.<br />
<?xml version="1.0" encoding="UTF-8"?><br />
<deviceinfo version="0.2"><br />
<device><br />
<match key="volume.uuid" string="$device_uuid"><br />
<merge key="volume.label" type="string">$device_name</merge><br />
<merge key="storage.automount_enabled_hint" type="bool">true</merge> <nowiki><!-- if you want automount this should be true even if it may not be taken into account by the Desktop Environment --></nowiki><br />
</match><br />
</device><br />
</deviceinfo><br />
<br />
=== Locale issues ===<br />
{{Box Note | This shouldn't happen anymore with ntfs-3g 2009.1.1 and newer.}}<br />
<br />
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:<br />
<br />
* Remove this symlink: <code>rm /sbin/mount.ntfs-3g</code><br />
* Replace it with a new bash script containing:<br />
#!/bin/bash<br />
/bin/ntfs-3g $1 "$2" -o locale=en_US.UTF-8,$4 # put your own locale here<br />
* Make it executable: <code>chmod +x /sbin/mount.ntfs-3g</code><br />
* Add "<code>NoUpgrade = sbin/mount.ntfs-3g</code>" to /etc/pacman.conf.<br />
<br />
===Allow dmask and fmask for ntfs-3g===<br />
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.<br />
<br />
<!-- mount ntfs volume with the ntfs-3g driver to enable write support --><br />
<device><br />
<match key="volume.fstype" string="ntfs"><br />
<append key="volume.mount.valid_options" type="strlist">dmask=</append><br />
<append key="volume.mount.valid_options" type="strlist">fmask=</append><br />
</match><br />
</device><br />
<br />
===Auto-mount only removable media===<br />
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:<br />
<br />
<device><br />
<match key="storage.hotpluggable" bool="false"><br />
<match key="storage.removable" bool="false"><br />
<merge key="storage.automount_enabled_hint" type="bool">false</merge><br />
</match><br />
</match><br />
</device><br />
<br />
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.<br />
<br />
Edit from LeoSolaris: I tried to add this to /etc/dbus-1/system.d/hal.conf and it kept dbus from loading properly. If this still works, it is meant to be placed somewhere else. (FYI for those less experienced, if dbus fails to load properly, usb keyboards, including the ones on laptops, will cease to function entirely. Use single user mode to gain console access, then remove this piece of code if dbus fails.)<br />
<br />
===Enable the noatime mount option for removable devices===<br />
This will speed up file operations and also reduce wear on flash memory devices like USB sticks or SD cards.<br />
<br />
<device> <br />
<match key="block.is_volume" bool="true"><br />
<match key="@block.storage_device:storage.hotpluggable" bool="true"><br />
<merge key="volume.policy.mount_option.noatime" type="bool">true</merge><br />
</match><br />
<match key="@block.storage_device:storage.removable" bool="true"><br />
<merge key="volume.policy.mount_option.noatime" type="bool">true</merge><br />
</match><br />
</match><br />
</device><br />
<br />
===... finally===<br />
<br />
Remember to restart the HAL-daemon for your changes to take effect immediately:<br />
# /etc/rc.d/hal restart<br />
<br />
=Troubleshooting=<br />
==Permission Denied with automounter==<br />
If you just upgraded and suddenly your automount stopped working with the error "PermissionDeniedByPolicy mount-removable no", you can hotfix the situation by editing /etc/PolicyKit/PolicyKit.conf and paste <br />
<match user="$USER"> <!-- replace with your login --><br />
<match action="org.freedesktop.hal.storage.*"><br />
<return result="yes"/><br />
</match><br />
</match><br />
into the <config> section (replace $USER with your login name). Restart dbus and hal. If you used kde you will have to restart kde as well (the device notifier won't 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. Maybe someone can make it match group "storage" and update this hastily typed thing.<br />
<br />
==Security error==<br />
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).<br />
<br />
==Inserted CD/DVD doesn't get recognized by HAL==<br />
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.<br />
<br />
==USB sticks and drives do not automount correctly==<br />
This sub-section is sourced from [http://bbs.archlinux.org/viewtopic.php?pid=248224 this forum page].<br />
<br />
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<br />
<merge key="volume.ignore" type="bool">false</merge><br />
<br />
Also, if you have GParted installed, you might need to delete this file:<br />
/usr/share/hal/fdi/policy/gparted-disable-automount.fdi<br />
<br />
... as being mentioned at the end of this thread: [http://bbs.archlinux.org/viewtopic.php?pid=310284]<br />
<br />
Also you should remove from '''/etc/fstab''' lines, corresponding to usb devices which should be mounted by hal automatically.<br />
<br />
==Could not get UID and GID==<br />
If you get the following error while starting DBUS:<br />
Failed to start message bus: Could not get UID and GID for username "dbus"<br />
then add the user like so:<br />
# /usr/sbin/groupadd -g 81 dbus<br />
# /usr/sbin/useradd -c 'System message bus' -u 81 -g dbus -d '/' -s /bin/false dbus<br />
<br />
==Removing USB flash causes improper unmount==<br />
If you remove your USB flash without previously unmounting it, automatic unmount by HAL may work improper.<br />
<br />
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. <br />
<br />
This may be corrected by unmounting flash drive with "lazy" parameter. To do so, you should do some tweaking:<br />
<br />
1) Create an executable script /usr/lib/hal/hal-unmount.sh with access rights 755 and the following content<br />
#!/bin/sh <br />
# sanity check. DEVNAME should start with a / <br />
[ "$DEVNAME" != "${DEVNAME#/}" ] || exit 0<br />
# Lazily unmount drives which are removed, but still mounted <br />
if [ "$ACTION" = remove ] ; then<br />
if [ -x /usr/bin/pumount ] ; then<br />
/usr/bin/pumount -l "$DEVNAME";<br />
else<br />
/bin/umount -l "$DEVNAME";<br />
fi<br />
fi<br />
exit 0<br />
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<br />
SUBSYSTEM=="block", ACTION=="remove", RUN+="/usr/lib/hal/hal-unmount.sh"<br />
<br />
3) Execute<br />
# /etc/rc.d/hal restart<br />
<br />
=External links=<br />
*[http://people.freedesktop.org/~david/hal-spec/hal-spec.html HAL 0.5.10 specifications] - A comprehensive HAL specification and introduction.<br />
*[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.<br />
*[http://people.freedesktop.org/~david/talks/dynamic-device-handling-OLS-2006.pdf Dynamic Device Handling (pdf)] - A presentation of device handling.</div>Hithttps://wiki.archlinux.org/index.php?title=Map_Custom_Device_Entries_with_udev&diff=59972Map Custom Device Entries with udev2009-02-03T17:09:51Z<p>Hit: /* Restart udev */</p>
<hr />
<div>[[Category:Hardware detection and troubleshooting (English)]]<br />
[[Category:HOWTOs (English)]]<br />
<br />
{{i18n_links_start}}<br />
{{i18n_entry|English|Using udev to map multiple entries to a device}}<br />
{{i18n_entry|Español|Utilizando udev para relacionar múltiples entradas a un dispositivo (Español)}}<br />
{{i18n_links_end}}<br />
<br />
This information is basically mirrored from the gentoo wiki with some additional hints. Recently it was updated to reflect changes in udev >= 98 syntax.<br />
<br />
This process allows you to always map a specific device to the same <code>/dev</code> node. This can then be used in <code>fstab</code> to ensure you can always mount the device same device in exactly the same place - which is great for desktop shortcuts!<br />
<br />
<br />
==Get the udev info for your USB device==<br />
<br />
Make sure one of your target devices is plugged in and then run the following as root:<br />
udevadm info -a -p `udevadm info -q path -n /dev/sda`<br />
<br />
This gets the udev device info for the device on <code>/dev/sda</code> - if your device is not mapped to <code>/dev/sda</code> then obviously use the correct mapping. :)<br />
<br />
You should get some output like this:<br />
<pre><br />
<br />
Udevadm starts with the device specified by the devpath and then<br />
walks up the chain of parent devices. It prints for every device<br />
found, all possible attributes in the udev rules key format.<br />
A rule to match, can be composed by the attributes of the device<br />
and the attributes from one single parent device.<br />
<br />
looking at device '/block/sda':<br />
KERNEL=="sda"<br />
SUBSYSTEM=="block"<br />
DRIVER==""<br />
ATTR{stat}==" 19 111 137 160 0 0 0 0 0 152 160"<br />
ATTR{size}=="2007040"<br />
ATTR{removable}=="1"<br />
ATTR{range}=="16"<br />
ATTR{dev}=="8:0"<br />
<br />
looking at parent device '/devices/pci0000:00/0000:00:02.2/usb1/1-5/1-5:1.0/host5/target5:0:0/5:0:0:0':<br />
KERNELS=="5:0:0:0"<br />
SUBSYSTEMS=="scsi"<br />
DRIVERS=="sd"<br />
ATTRS{ioerr_cnt}=="0x0"<br />
ATTRS{iodone_cnt}=="0x1c"<br />
ATTRS{iorequest_cnt}=="0x1c"<br />
ATTRS{iocounterbits}=="32"<br />
ATTRS{timeout}=="30"<br />
ATTRS{state}=="running"<br />
ATTRS{rev}=="1.20"<br />
ATTRS{model}=="01GB Tiny "<br />
ATTRS{vendor}=="Pretec "<br />
ATTRS{scsi_level}=="3"<br />
ATTRS{type}=="0"<br />
ATTRS{queue_type}=="none"<br />
ATTRS{queue_depth}=="1"<br />
ATTRS{device_blocked}=="0"<br />
ATTRS{max_sectors}=="240"<br />
<br />
looking at parent device '/devices/pci0000:00/0000:00:02.2/usb1/1-5/1-5:1.0/host5/target5:0:0':<br />
KERNELS=="target5:0:0"<br />
SUBSYSTEMS==""<br />
DRIVERS==""<br />
<br />
looking at parent device '/devices/pci0000:00/0000:00:02.2/usb1/1-5/1-5:1.0/host5':<br />
KERNELS=="host5"<br />
SUBSYSTEMS==""<br />
DRIVERS==""<br />
<br />
looking at parent device '/devices/pci0000:00/0000:00:02.2/usb1/1-5/1-5:1.0':<br />
KERNELS=="1-5:1.0"<br />
SUBSYSTEMS=="usb"<br />
DRIVERS=="usb-storage"<br />
ATTRS{modalias}=="usb:v4146pBA01d0100dc00dsc00dp00ic08isc06ip50"<br />
ATTRS{bInterfaceProtocol}=="50"<br />
ATTRS{bInterfaceSubClass}=="06"<br />
ATTRS{bInterfaceClass}=="08"<br />
ATTRS{bNumEndpoints}=="03"<br />
ATTRS{bAlternateSetting}==" 0"<br />
ATTRS{bInterfaceNumber}=="00"<br />
<br />
looking at parent device '/devices/pci0000:00/0000:00:02.2/usb1/1-5':<br />
KERNELS=="1-5"<br />
SUBSYSTEMS=="usb"<br />
DRIVERS=="usb"<br />
ATTRS{configuration}==""<br />
ATTRS{serial}=="14AB0000000096"<br />
ATTRS{product}=="USB Mass Storage Device"<br />
ATTRS{maxchild}=="0"<br />
ATTRS{version}==" 2.00"<br />
ATTRS{devnum}=="7"<br />
ATTRS{speed}=="480"<br />
ATTRS{bMaxPacketSize0}=="64"<br />
ATTRS{bNumConfigurations}=="1"<br />
ATTRS{bDeviceProtocol}=="00"<br />
ATTRS{bDeviceSubClass}=="00"<br />
ATTRS{bDeviceClass}=="00"<br />
ATTRS{bcdDevice}=="0100"<br />
ATTRS{idProduct}=="ba01"<br />
ATTRS{idVendor}=="4146"<br />
ATTRS{bMaxPower}==" 98mA"<br />
ATTRS{bmAttributes}=="80"<br />
ATTRS{bConfigurationValue}=="1"<br />
ATTRS{bNumInterfaces}==" 1"<br />
<br />
looking at parent device '/devices/pci0000:00/0000:00:02.2/usb1':<br />
KERNELS=="usb1"<br />
SUBSYSTEMS=="usb"<br />
DRIVERS=="usb"<br />
ATTRS{configuration}==""<br />
ATTRS{serial}=="0000:00:02.2"<br />
ATTRS{product}=="EHCI Host Controller"<br />
ATTRS{manufacturer}=="Linux 2.6.18-ARCH ehci_hcd"<br />
ATTRS{maxchild}=="6"<br />
ATTRS{version}==" 2.00"<br />
ATTRS{devnum}=="1"<br />
ATTRS{speed}=="480"<br />
ATTRS{bMaxPacketSize0}=="64"<br />
ATTRS{bNumConfigurations}=="1"<br />
ATTRS{bDeviceProtocol}=="01"<br />
ATTRS{bDeviceSubClass}=="00"<br />
ATTRS{bDeviceClass}=="09"<br />
ATTRS{bcdDevice}=="0206"<br />
ATTRS{idProduct}=="0000"<br />
ATTRS{idVendor}=="0000"<br />
ATTRS{bMaxPower}==" 0mA"<br />
ATTRS{bmAttributes}=="e0"<br />
ATTRS{bConfigurationValue}=="1"<br />
ATTRS{bNumInterfaces}==" 1"<br />
<br />
looking at parent device '/devices/pci0000:00/0000:00:02.2':<br />
KERNELS=="0000:00:02.2"<br />
SUBSYSTEMS=="pci"<br />
DRIVERS=="ehci_hcd"<br />
ATTRS{broken_parity_status}=="0"<br />
ATTRS{enable}=="1"<br />
ATTRS{modalias}=="pci:v000010DEd00000068sv00001043sd00000C11bc0Csc03i20"<br />
ATTRS{local_cpus}=="f"<br />
ATTRS{irq}=="17"<br />
ATTRS{class}=="0x0c0320"<br />
ATTRS{subsystem_device}=="0x0c11"<br />
ATTRS{subsystem_vendor}=="0x1043"<br />
ATTRS{device}=="0x0068"<br />
ATTRS{vendor}=="0x10de"<br />
<br />
looking at parent device '/devices/pci0000:00':<br />
KERNELS=="pci0000:00"<br />
SUBSYSTEMS==""<br />
DRIVERS==""<br />
<br />
</pre><br />
<br />
Bit too much information! The only bit of this you actually need is the <code>ATTRS{serial}</code> part - so now you know what the above command does just grep out the bit you want in future cases:<br />
<br />
udevadm info -a -p `udevadm info -q path -n /dev/sda` | grep ATTRS{serial}<br />
<br />
output:<br />
<br />
ATTRS{serial}=="14AB0000000096"<br />
ATTRS{serial}=="0000:00:02.2"<br />
<br />
Hmm, two serials. Which one to use?<br />
<br />
udevadm info -a -p `udevadm info -q path -n /dev/sda` | grep ATTRS{product}<br />
<br />
and we get<br />
<br />
ATTRS{product}=="USB Mass Storage Device"<br />
ATTRS{product}=="EHCI Host Controller"<br />
<br />
So, we need to use first serial.<br />
<br />
<br />
==Create a udev rule==<br />
<br />
You then use the <code>ATTRS{serial}</code> in a udev rule as follows:<br />
<br />
Note: The convention for Arch Linux is to place custom rules into <code>/etc/udev/rules.d/00.rules</code><br />
You may, however create a file with a different name. Just remember that udev processes these files in alphabetical order.<br />
<br />
BUS=="usb", ATTRS{serial}=="14AB0000000096", KERNEL=="sd?1", NAME="%k", SYMLINK+="usbdrive", GROUP="storage"<br />
<br />
<br />
==Create an fstab entry and mount point==<br />
<br />
Create a directory:<br />
<br />
mkdir /mnt/usbdrive<br />
<br />
In your <code>/etc/fstab</code>, create an entry like this:<br />
<br />
/dev/usbdrive /mnt/usbdrive vfat rw,noauto,group,flush,quiet,nodev,nosuid,noexec,noatime,dmask=000,fmask=111 0 0<br />
<br />
Additionally, depending on your locale preferences, add something like <code>codepage=866,iocharset=utf-8</code> to be able to see non-Latin filenames correctly.<br />
<br />
Now root or any user who belongs to the <code>storage</code> group can mount the USB stick by simply doing<br />
<br />
mount /mnt/usbdrive<br />
<br />
BTW, all the last 3 additional mount options are meant to increase your system's security, e.g. they will prevent you running an executable file directly from the USB drive.<br />
<br />
To allow non-root users to access to USB stick do<br />
gpasswd -a user1 storage<br />
gpasswd -a user2 storage<br />
<br />
==Restart udev==<br />
<br />
To load your updated rules you can run:<br />
udevadm control --reload-rules<br />
<br />
''Note: As of udev-1.30, the following is deprecated and needs to be updated. It probably won't work anymore.''<br />
<br />
Only if really needed, you may restart udev like this. As root, run those 3 commands:<br />
/etc/./start_udev<br />
mount /dev/pts<br />
mount /dev/shm<br />
<br />
==Examples==<br />
<br />
Here are some examples from my system. My devices sometimes mount on <code>sda</code> or <code>sda1</code> so I have two rules for each - this is a work around for device not found problems. The sda node is also needed for disk-level activities e.g. <code>fdisk /dev/sda</code>.<br />
<br />
This always maps my disgo USB pen to <code>/dev/usbpen</code> which I then map in fstab to mount on <code>/mnt/usbpen</code><br />
<br />
# Symlink USB pen<br />
SUBSYSTEMS=="usb", ATTRS{serial}=="1730C13B18000B84", KERNEL=="sd?", NAME="%k", SYMLINK+="usbpen", GROUP="storage"<br />
SUBSYSTEMS=="usb", ATTRS{serial}=="1730C13B18000B84", KERNEL=="sd?1", NAME="%k", SYMLINK+="usbpen", GROUP="storage"<br />
<br />
If you have a device with with multiple partitions, the following example maps the device to <code>/dev/usbdisk</code>, and partitions 1, 2, 3 etc. to <code>/dev/usbdisk1</code>, <code>/dev/usbdisk2</code>, <code>/dev/usbdisk3</code> etc.<br />
<br />
# Symlink multi-part device<br />
SUSSYSTEMS=="usb", ATTRS{serial}=="1730C13B18000B84", KERNEL=="sd?", NAME="%k", SYMLINK+="usbdisk", GROUP="storage"<br />
SUBSYSTEMS=="usb", ATTRS{serial}=="1730C13B18000B84", KERNEL=="sd?[1-9]", NAME="%k", SYMLINK+="usbdisk%n", GROUP="storage"<br />
<br />
These rules are equivalent to the following one:<br />
<br />
# Symlink multi-part device<br />
SUBSYSTEMS=="usb", ATTRS{serial}=="1730C13B18000B84", KERNEL=="sd*", NAME="%k", SYMLINK+="usbdisk%n", GROUP="storage"<br />
<br />
You can also omit the NAME and GROUP statements, so that the defaults from <code>udev.rules</code> are used. So the shortest and simplest solution would be adding this rule:<br />
<br />
# Symlink multi-part device<br />
SUBSYSTEMS=="usb", ATTRS{serial}=="1730C13B18000B84", KERNEL=="sd*", SYMLINK+="usbdisk%n"<br />
<br />
This always maps our Olympus digicam to <code>/dev/usbcam</code> which I then map in fstab to mount on <code>/mnt/usbcam</code><br />
<br />
# Symlink USB camera<br />
SUBSYSTEMS=="usb", ATTRS{serial}=="000207532049", KERNEL=="sd?", NAME="%k", SYMLINK+="usbcam", GROUP="storage"<br />
SUBSYSTEMS=="usb", ATTRS{serial}=="000207532049", KERNEL=="sd?1", NAME="%k", SYMLINK+="usbcam", GROUP="storage"<br />
<br />
And this maps my Packard Bell MP3 player to <code>/dev/mp3player</code><br />
<br />
# Symlink MP3 player<br />
SUBSYSTEMS=="usb", ATTRS{serial}=="0002F5CF72C9C691", KERNEL=="sd?", NAME="%k", SYMLINK+="mp3player", GROUP="storage"<br />
SUBSYSTEMS=="usb", ATTRS{serial}=="0002F5CF72C9C691", KERNEL=="sd?1", NAME="%k", SYMLINK+="mp3player", GROUP="storage"<br />
<br />
To map your own usb key to <code>/dev/mykey</code> and all of other keys to <code>/dev/otherkey</code><br />
<br />
# Symlink USB keys<br />
SUBSYSTEMS=="usb", ATTRS{serial}=="insert serial key", KERNEL=="sd?1", NAME="%k", SYMLINK+="mykey"<br />
SUBSYSTEMS=="usb", KERNEL=="sd?1", NAME="%k", SYMLINK+="otherkey"<br />
<br />
Note the order of the lines. Since all the usb keys should create the /dev/sd<a||b> node, udev will first check if it is your own usb key, defined with the serial number. But if you plug another key witch you don't know the serial number, it will create a node too, with a generic name "otherkey". That rule should be the last one your rules file.<br />
<br />
<br />
This is an example how to distinguish USB HDD drive and USB sticks:<br />
<br />
BUS=="usb", ATTRS{product}=="USB2.0 Storage Device", KERNEL=="sd?", NAME="%k", SYMLINK+="usbdisk", GROUP="storage"<br />
BUS=="usb", ATTRS{product}=="USB2.0 Storage Device", KERNEL=="sd?[1-9]", NAME="%k", SYMLINK+="usbdisk%n", GROUP="storage"<br />
BUS=="usb", ATTRS{product}=="USB Mass Storage Device", KERNEL=="sd?1", NAME="%k", SYMLINK+="usbflash", GROUP="storage"<br />
<br />
Note that this udev rule doesn't use serials at all.</div>Hit