HOWTO D-BUS, HAL, KDE media:/
From Gentoo Linux Wiki
Contents |
[edit] D-BUS, HAL, KDE media:/
I wanted to make use of the new hal support in KDE. I found this howto. Here's how to use it in Gentoo. You should also check out HOWTO KDE Desktop for the end-user.
[edit] Introduction
The media:/ kioslave in KDE (>=3.4) can use the HAL (hardware abstraction layer) and hotplug to detect hardware changes. This makes living with removable media like compact discs and USB keys much nicer. Here's how I got it working.
[edit] Kernel
The 2.6.11 kernel has some built in support for hot-pluggable devices. So the first step is to get at least a 2.6.11 kernel.
2.6.12 introduces irrevocable changes to reiser4 support and a serious bug that affected mounting usb devices with sync (as is done by default by HAL) which sends your flash drive to high heavens. (I believe this was only an issue before HAL 0.5, and since 0.5.5.1-r3 is now stable on almost every platform it should no longer be an issue.) [1] [2]
You may want to modify hal if you adopt kernel >2.6.11 [3]
emerge --sync emerge -u gentoo-sources
Copy over your old .config file and,
make oldconfig
Make sure to enable KOBJECT_UEVENT (not for hal-0.5.9) and CONFIG_HOTPLUG. Make it and install it as per usual. If you prefer 'make menuconfig' or 'genkernel --menuconfig', check if this minimum configuration is met:
Device Drivers --->
SCSI device support --->
<M> SCSI device support
<M> SCSI disk support
<M> SCSI generic support (you need this for USB CD/DVD writers, scanners etc.)
USB support --->
<M> Support for Host-side USB
<M> EHCI HCD (USB 2.0) support (for USB 2.0)
<M> OHCI HCD support (for USB 1.1)
<M> UHCI HCD (most Intel and VIA) support
<M> USB Mass Storage support
File systems --->
[*] Inotify file change notification support
[*] Inotify support for userspace
DOS/FAT/NT Filesystems --->
<M> MSDOS fs support
<M> VFAT (Windows-95) fs support
<M> NTFS file system support (if you want to use NTFS formatted USB drives)
Don't forget to add the modules to /etc/modules.autoload.d/kernel-2.6, or just compile them statically into the kernel.
Now is as good a time as any to boot to your fresh new kernel.
[edit] Software
Now we'll install the new software we need. Edit /etc/make.conf and make sure you have the hal use flag. If we reinstall kdebase-kioslaves, it will pull in hal and hotplug as dependencies.
emerge -avt kdebase-kioslaves
If you installed KDE by emerging kde-base/kdebase you'll have to reemerge this instead because kdebase contains kioslaves. This is why kdebase is blocking kdebase-kioslaves. Instead, reemerge kde-base/kdebase with the hal use flag.
NOTE: After remerging kdebase with the hal you DO NOT need to emerge kde-base/kdebase-kioslaves. For more information see Split vs Monolithic KDE ebuilds.
Make sure that this also installs hal and dbus, or that you already have them installed.
Now add the hal boot script to rc and start it. As it depends on dbus it will start dbus automatically.
rc-update add hald default rc-config start hald
NOTE: If you didn't have hald running before emerging kde-base/kdebase-kioslaves or kde-base/kdebase you might experience exactly the problems discribed under Troubleshooting KDE media:/.
You also need to make sure that all the users that need to mount removable media are in the 'plugdev' group.
usermod -a -G plugdev <username>
At this point, you have everything that you need. Just make sure that you have a /media folder.
[edit] Trying it out
Open Konqueror and type media:/ into the address bar. Try inserting a usbstick or whatever you like. You can click the icons and the media should be automatically mounted. KDE >= 3.5 has even nice windows popping up and asking you what to do (you can configure it to automatically mount the device without asking).
TIP for 'Permission denied' error: if you have an entry in fstab for floppy, cd-rom, or dvd-rom check what device you are trying to mount. /dev/fd0 is not /dev/floppy/0.
If you don't know what device is used in KDE to mount floppy, cd-rom, or dvd-rom just show device icons on desktop for unmounted floppy, cd-rom or dvd-rom.
Right click on device icon: 'Properties' -> 'Additional information' -> 'Mount point' and You know ;-)
I spent half day searching for a solution to this error :-)
Comment: What I understood here was not very intuitive to me. What I actually ended up doing was I had a device, /dev/hdc, symlinked to /dev/dvd and my fstab was using the symbolic link. The entry in fstab was what was actually causing the problem. Changing the entry in fstab to /dev/hdc fixed the problem and actually allows me to mount in points other than /media. I hope this clarifies things and answers some questions.
In my case: I kept getting a "Permissions denied" error when my fstab had a /dev/hdc entry in it, and I added user and received no error message when launching Konqueror, but nothing would show. If I clicked the icon on the desktop multiple times, multiple mounts would occur requiring me to umount as many times necessary before I can eject by right-clicking and doing "Eject" or using eject. I commented out /dev/hdc and now KDE mounts the drive correctly whether it be DVD or CD.
another comment : I've read here https://fug-fr.org/cgi-bin/yabb2/YaBB.pl?num=1183022264 that you have to be in the "operator" group in order to avoid the "persmission denied" error. to be confirmed.
'Note:' For me neither solutions worked. Once hal is enabled kde is capable of mounting removable media on-demand inside /media. Thus you do not need mount points for usb, cdroms etc..in fstab. Simply delete these entries from /etc/fstab and you should be ok.
My experience: You do not need to delete the cdrom mount point from /etc/fstab to avoid this error, simply add user or users option. This allows non-root users mount /dev/cdrom and unmount it. From man mount:
user Allow an ordinary user to mount the file system. ...
he can unmount the file system again.
users Allow every user to mount and unmount the file system.
The line in my /etc/fstab looks like
# <fs> <mountpoint> <type> <opts> <dump/pass> /dev/cdrom /mnt/cdrom auto noauto,ro,users 0 0
Option ro does not prevent writing on cd-rw, it seems to work flawlessly with KDE media:/ and manual mounts as mentioned below
Another error : Wrong fs, bad superblock or bad option etc... I have had an error mounting fat filesystem because hal was trying to mount it with option "flush". You can remove this option by right-clicking on the device in media:/ and then properties > mounting and checking out "flushed" ("E/S videes" in French). If you want to disable it on system-level you can remove the appropriate line in /usr/share/hal/fdi/policy/10osvendor/20-storage-methods.fdi (the one telling hal to mount with option "flush") but 1) there may be side-effects 2) there ought to be a user-friendly solution 3) it will create a conflict when this file is modified during an upgrade.
[edit] Automounting and running scripts/programs on media insertion
If you want to be able to do the aforementioned, it might be worth your while to check out ivman. It allows you to automatically mount and play audio CDs and DVDs and much, much more. Ivman's available as an ebuild.
emerge -a ivman
[edit] Tips and Tricks
[edit] KDE/GNOME hal stops working with usb devices
Description: lshal -m show a device if plugged in, but doesn't create a proper mountpoint and nothing show up in KDE
Solution1: unmerge hal, delete /usr/share/hal and remerge hal (You can as well unmerge hal-info instead of deleting /usr/share/hal.)
Credits are going to dodo1122 from the Gentoo forum for automount not working for usb devices
This one applies to GNOME, too. Same problem, same solution.
Solution2: An error in gparted (gnome partitioning tool) could leave the file /usr/share/hal/fdi/policy/gparted-disable-automount.fdi. In this case, delete that file or simply open gparted and close it properly with the same user that opened it before.
May be another program do the same thing, check /usr/share/hal/fdi/policy/ for a file blocking automount and delete only that file. No install/reinstall needed. Other files may be included in other packages, so, if they were deleted, they are not restored even if hal is reinstalled.
Solution3: Some bug (feature?) in /etc/dbus-1/system.d/hal.conf. added by Jay [JID:jay@xmpp.ru]
Here is tail of original file:
<!-- Gentoo specific rules to allow 'plugdev' group to access Volumes and Power Management -->
<!-- We possibly will use 'powerdev' for Power Management or work on encapsulating everything in ConsoleKit -->
<policy group="plugdev">
<allow send_interface="org.freedesktop.Hal.Device.SystemPowerManagement"/>
<allow send_interface="org.freedesktop.Hal.Device.LaptopPanel"/>
</policy>
<policy group="plugdev">
<allow send_interface="org.freedesktop.Hal.Device.Volume"/>
<allow send_interface="org.freedesktop.Hal.Device.Volume.Crypto"/>
</policy>
I have merged splitted policy-tag into one section like following:
<!-- Gentoo specific rules to allow 'plugdev' group to access Volumes and Power Management -->
<!-- We possibly will use 'powerdev' for Power Management or work on encapsulating everything in ConsoleKit -->
<policy group="plugdev">
<allow send_interface="org.freedesktop.Hal.Device.SystemPowerManagement"/>
<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>
And after restarting dbus automounting start working as before.
[edit] Troubleshooting KDE media:/
If you can mount media using the pmount command but KDE media:/ doesn't work, try re-emerging kdebase-kioslaves. The ebuild checks for HAL-support on your system and disables it, even if the HAL-Use-Flag is set. Re-emerging it after HAL is up and running enables the HAL-support in kdebase-kioslaves.
Furthermore, if you find that it *still* doesn't work, you may also need to emerge dbus-qt3-old before you re-emerge kdebase-kioslaves. The reasoning behind this is a little obscure, but kdebase-kioslaves will refuse to build the HAL media:/ driver if it can't find HAL, DBUS, and DBUS-Qt, the latter being provided by this dbus-qt3-old package.
[edit] UDEV Symlinks and HAL
For more information on how to create UDEV symlinks, I would recommend: Writing UDEV Rules. If you want to retain your udev symlink names, and have HAL use them you can change the file: nano -w /etc/udev/rules.d/90-hal.rules
This is where you would put your UDEV rules, appending GROUP="hal" to them. As an example, my hal.rules:
| File: hal.rules |
BUS=="usb", SYSFS{serial}=="123456789011121314", SYSFS{product}=="JUMPDRIVE", KERNEL=="sd?1", NAME="%k", SYMLINK="usbdrive", GROUP="hal"
BUS=="usb", SYSFS{manufacturer}=="Sony", SYSFS{product}=="PSP Type A", KERNEL=="sd?1", NAME="%k", SYMLINK="psp", GROUP="hal"
BUS=="usb", SYSFS{manufacturer}=="Apple", SYSFS{product}=="iPod", KERNEL=="sd?2", NAME="%k", SYMLINK="ipod", GROUP="hal"
|
Notice that {{{1}}} is at the end of every rule.
Almost done. All we need to do is change our fstab to reflect the UDEV rules.
{{Box File|/etc/fstab|/dev/sda1 /mnt/windows ntfs user,umask=0133,dmask=000 0 0 /dev/sda2 /boot ext2 noauto,noatime 1 2 /dev/sda3 none swap sw 0 0 /dev/sda4 / jfs noatime 0 1 /dev/hdc1 /mnt/backup reiserfs noatime,user 0 3 none /proc proc defaults 0 0 none /dev/shm tmpfs nodev,nosuid,noexec 0 0 /dev/hda /mnt/cdrw auto noauto,rw,user 0 0 /dev/usbdrive /mnt/usbdrive auto noauto,rw,user 0 0 /dev/ipod /mnt/ipod auto noauto,rw,user 0 0 /dev/psp /mnt/psp auto noauto,rw,user 0 0
The SYMLINK setting in your UDEV rules file is used as the device node. all you have to do after you do this is make sure that you built kde with HAL support, (Lets assume that you followed the guide and did) and reboot.
One last note: This information came from a variety of web sites, so I don't know if everything is 100% as it should be or even if it will work for anyone else, that being said, I hope someone else find this usefull, I use it in conjunction with pmount so that I can mount new devices, but still know exactly where my normal device nodes/mountpoints are. Have fun.
Just a comment: I don't see how /etc/udev/rules.d/hal.rules would ever be run since the rules are processed in lexical order and the default rules in /etc/udev/rules.d/50-udev.rules would name the device and all subsequent rules (higher than 50 or starting with a letter) would not apply.
Answer: It's because current versions of udev apply all matching rules, not just the first one.
Comment by Maniac: Maybe someone does't already know it: If KDE detects your device, but always tells you that its not in /etc/fstab, then you may change the rights of the pmount and pmount-hal files in /usr/bin to 4755. Works fine for me :-) added by otty 27.11.06: this solves the most problems with user restrictions on accessing usb devices.
[edit] Mount NTFS-formatted media as user
If you want to be able to mount and use NTFS-formatted media with user privileges (i.e. not as root), you might need to add a hal-policy:
su - cd /usr/share/hal/fdi/policy/ mkdir 95userpolicy cd 95userpolicy nano removablentfs.fdi
Add the following content to this file:
| File: /etc/hal/fdi/policy/95userpolicy/removablentfs.fdi |
<deviceinfo version="0.2"> <device> <match key="volume.fstype" string="ntfs"> <append key="volume.mount.valid_options" type="strlist">uid=</append> </match> </device> </deviceinfo> |
Restart hald:
| Code: Restart hald |
rc-config restart hald |
This tip is basically from: http://fedorawiki.de/index.php/NTFS_Partitionen_von_Wechseldatenträgern_mit_HAL_als_User_mounten
[edit] A way without automounting
Actually you do not need to do all this to use removable media in KDE (or other desktop environments). Just write user option to your device line in /etc/fstab to allow users to mount/umount this media. NOTE: This will work only in linux not in BSD. Then you can use Kwikdisk in kde. Just press on its icon in trey an then on device to mount and do the same to umount. You can also use scripts attached to desktop icons to mount devices.
