|
发表于 2005-6-14 19:23:17
|
显示全部楼层
一般情况下,
有 udev , dbus , hal 后
Konqueror 里地址 media:/ 里会有 U 盘 , 光盘 , 硬盘这些
插入 设备后在 media:/ 里会出现相关设备图标
要确保 fstab 里没有 U 盘的行
我另外设置桌面属性 显示设备图标
这样,插入 U 盘后桌面就会出现 U 盘图标
HOWTO 在这儿 http://wiki.kde.org/tiki-index.php?page=DBUS
DBUS
HOWTO: setting up D-BUS and HAL with KDE's media ioslave
(cached) edit refresh print
D-BUS, HAL, KDE media:/ HOWTO
HOWTO Version 0.07 - Mark Veinot
The KDE media:/ ioslave is a new addition to the KDE system that monitors removable media on the system and provides an updated list of such hardware. By default it will simply monitor the /etc/fstab file to know what hardware is available. Various scripts are available for udev/hotplug that effect changes to the fstab file. Currently these forms of detection are required for systems such as FreeBSD, but on Linux we can use the new HAL daemon.
The media:/ ioslave includes the ability to use the HAL (Hardware Abstraction Layer) library and daemon to get hotplug notifications as hardware is added and removed. This provides a more uniform and full fledged approach to hardware discovery.
HAL also polls certain hardware like universal media card readers, enabling hotplug notifications for those devices that don't generate media insert/removal events on their own.
When I decided to try to get HAL working with the KDE media:/ ioslave I found very minimal documentation on the net. Most of what I discovered was in the form of various errors users had encountered and some replies from helpful individuals trying to help. A HOWTO would have been very helpful, but since I couldn't find one, I decided to take it upon myself to write one.
First, equip yourself with a recent Linux 2.6 kernel. 2.6.11 is the latest at this time, which I recommend due to added support for this release in HAL.
Make sure you enable Support for hot-pluggable devices (CONFIG_HOTPLUG), and Kernel Userspace Events (CONFIG_KOBJECT_UEVENT) in your kernel.
After your new kernel is running, you'll need to get D-Bus and HAL. I prefer compiling from source on my Slackware 10 system, so the document reflects that procedure.
D-BUS is currently located at http://freedesktop.org/wiki/Software_2fdbusexternal link. You can download releases from that page. Currently KDE does not support version 0.31 or later. Use 0.23.x.
HAL is located at http://freedesktop.org/wiki/Software_2fhalexternal link and can be downloaded there as well. Currently KDE does not support version 0.5.0 or later. Use 0.4.8.
It's also important that you have a recent version of udev and hotplug, but installation and setup of those systems are currently outside the scope of this document. I may come back and add some instructions later, but installation of udev and hotplug are already relatively well documented on the web.
In order to set this all up to work with media:/, D-BUS qt bindings are required.
On my system, all of qt resides in /usr/local/qt, so you will need to set QTDIR and QT_MOC to point to your qt moc binary. On systems where the qt binaries are in the path, these steps are not likely to be necessary.
Configure, build and install D-BUS with the commands:
./configure --enable-qt
make
make install
useradd messagebus
The messagebus user is required for correct D-BUS operation.
You will need to start the D-BUS daemon when the system starts. The command to start it correctly for our purposes is:
dbus-daemon-1 --system
This will create two files in /usr/local/var/run/dbus named pid and system_bus_socket, the latter being a named pipe and not an actual file. D-BUS daemon will fail to start if either of these files is present before it runs. Make sure they are deleted from the system on shutdown.
After installing and running D-BUS, at this point you can start to build HAL. You will need libcap before you can build HAL. libcap can be found at ftp://ftp.kernel.org/pub/linux/l ... kernel-2.4/external link. As of this writing, libcap-1.10 is the most recent.
To build and install libcap, simply run:
make
make install
ldconfig
Now we can build HAL using the commands:
./configure --enable-fstab-sync --enable-sysfs-carrier
make
make install
groupadd haldaemon
useradd -g haldaemon haldaemon
--enable-fstab-sync is only required if you will not be using the pmount utility described below
--enable-sysfs-carrier requires kernel 2.6.10 or later
hald requires the haldaemon user and group to operate correctly.
During the configure or make processes you may encounter some errors, almost all of which are caused by problematic kernel headers. Specifically, you may encounter a message referring to BLKGETSIZE64: on systems installed with kernel headers from Linux 2.4, the fs.h include file contains a reference to a u64 size that confuses the HAL configuration.
It's a kludge, but I've found it sufficient to edit (at least temporarily) /usr/include/linux/fs.h and change:
#define BLKGETSIZE64 _IOR(0x12,114,sizeof(u64)) /* return device size in bytes (u64 *arg) */
on line 192 to
#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
You may also have issues surrounding the sg.h header. If this is the case, returning to an older version of that header helps.
It can be tricky to work through the errors, but be patient, search the internet using the error messages that are generated and you should be able to find a solution.
After installing HAL, you will need to start the HAL daemon (hald) which monitors the /sys filesystem and sends messages over the D-BUS system.
In order for hald to run with --daemon=yes, the directory /usr/local/var/run/hald must be created and owned by root.
At this point you can reconfigure, rebuild and reinstall kdebase to have it detect and use the HAL backend for the media:/ ioslave (it is sufficient to reconfigure kdebase and then run make and make install only in the kioslave/media directory). Then restart KDE and you should have automatic removable media detection in the media:/ ioslave.
If you want to be able to have the seamless ability to mount and access your removable media (and why wouldn't you, that's why we're doing this, right?) you will need to make a few more changes.
There are two options available to you to accomplish this. The preferred one is to use a utility called pmount which allows non-priveleged user accounts to mount devices that don't appear in /etc/fstab. The second approach is to use the HAL fstab-sync utility and is the one enabled by default in HAL. NOTE: you only need to use one of these methods. In fact, if both are in place, it will probably be very confusing.
The pmount approach
As I mentionned, pmount is the preferred method to accomplish seamless device mounting. Continuously altering a system configuration file such as /etc/fstab should be avoided when possible.
pmount was created by one of the Debian team members, so that is where you will find the source. It is available from http://packages.debian.org/unstable/source/pmountexternal link and will be labeled as pmount_x.y.z.orig.tar.gz
To compile pmount you will also need libsysfs which is included as part of sysfsutils, available from the Linux Diagnostic Tools project at http://linux-diag.sourceforge.net/Sysfsutils.htmlexternal link.
Compile and install sysfsutils with a simple:
./configure
make
make install
After that, you can build pmount. It doesn't have a GNU autoconf build system at this time, so it expects to find libsysfs in one of the default locations in the system. Provided that's the case, then a simple:
make
make install
Will install pmount and the included pmount helper script pmount-hal in /usr/local/bin. The pmount binary will be setuid root by the install script, so as with any setuid binary, there is a small security risk involved. Fortunately pmount has a fairly narrow scope of operation so it should be easy to keep secure. At any rate, it's probably not advisable to install it on a production server system.
Now we need to remove the symbolic link to the fstab-sync utility created by HAL and create one pointing to pmount-hal. These symlinks are in /usr/local/etc/hal/device.d by default. You should find a symlink there named 50-fstab-sync.hal. Either delete it, or move it harmlessly out of the way to some other directory in case you need it again.
After (re)moving the fstab-sync link, we need to create a new one for pmount-hal. I called mine 60-pmount.hal, but you can name it whatever you want (though I think the number prefix and .hal suffix are required). To create this symbolic link use a command like:
ln -s /usr/local/bin/pmount-hal /usr/local/etc/hal/device.d/60-pmount.hal
Restart hald now so it knows about it's new file. At this point you should be able to mount and unmount removable media without having your fstab file altered.
If you used the pmount method, you may skip to the conclusion.
The fstab-sync approach
This method involves having HAL call a program named fstab-sync to alter your /etc/fstab file. This is the way that HAL comes configured by default, but requires the following modification to the mount program on some systems. To test if your system needs this patch or not, add the 'managed' option to one of your current removable media devices in /etc/fstab like a CD-ROM or floppy drive. If you can still mount the device without errors after this modification then this patch has already been applied and you can skip downexternal link to the part about editing the storage-policy.fdi file.
All entries in /etc/fstab need a correct syntax, otherwise fstab-sync doesn't create entries in /etc/mtab. In my case the missing "0 0" (dump/pass) of some nfs-shares was the problem.
Obtain the latest util-linux source and apply the following patch to enable the mount command to ignore the 'managed' option that HAL uses to track it's changes to the /etc/fstab file.
--- util-linux-2.12a/mount/mount.c.sopwith 2004-03-04 20:28:22.000000000 -0500
+++ util-linux-2.12a/mount/mount.c 2004-07-16 16:50:18.792814782 -0400
@@ -191,6 +191,8 @@
{ "diratime", 0, 1, MS_NODIRATIME }, /* Update dir access times */
{ "nodiratime", 0, 0, MS_NODIRATIME }, /* Do not update dir access times */
#endif
+ { "kudzu", 0, 0, MS_COMMENT }, /* Silently remove this option (backwards compat use only - deprecated) */
+ { "managed", 0, 0, MS_COMMENT }, /* Silently remove this option */
{ NULL, 0, 0, 0 }
};
Then build and install util-linux (or just the mount command, if you're so inclined)
You will probably also want to edit /usr/local/share/hal/fdi/90defaultpolicy/storage-policy.fdi and change:
<merge key="storage.policy.default.mount_option.exec" type="bool">true</merge>
near the top of the file to
<merge key="storage.policy.default.mount_option.noexec" type="bool">true</merge>
This will disable the executing of programs on removable media which could be a security risk... enable at your own discretion.
I also opted to add the line:
<merge key="storage.policy.default.mount_option.user" type="bool">true</merge>
To the same set of commands. This enables non-root users to mount the media. You will pretty much need this line unless you login to X/KDE as root... you don't run X/KDE as root, do you?external link
I also found it necessary to remove the line:
<merge key="storage.policy.default.mount_option.iocharset=utf8" type="bool">true</merge>
Which is around line 169, since that doesn't seem to be a valid mount option for the vfat filesystem (which most removable media uses by default).
At this point you should restart hald to have the changes take effect. This should enable you to simply double click on newly inserted media and have it transparently mounted before KDE opens a filemanager window on the new device.
Conclusion
Finally, you'll probably want to right click on the devices:/ tab in the Konqueror file manager to rename it to Media and change the URL to media:/
I think that covers all the issues I encountered while setting this up. If you encounter any other issues, or find any errors in my instructions please send email to vmark () nbnet ! nb ! caexternal link.
This software is in a very early development stage and therefore may be unstable and have unpredictable errors present. No warranty is expressed or implied that this software is safe or even suitable for a given purpose. Use at your own risk. |
|