Valid HTML 4.01 Transitional
Prev: Fails to Mount Media with VFAT Next: Black Screen on Logout
(Index)
Jim Carter's Bugfixes

Automatic Volume Mounting Without KDE or Gnome

James F. Carter
2007-01-22
Symptom:

On Windows if you stick a disc in the CD drive, or plug in an external disc drive or flash memory stick to USB or Firewire, something useful will happen such as mounting the media or playing a music disc or video. Modern installations of Gnome or KDE do the same thing, if you're lucky. But suppose you're an old troglodyte who uses a non-bloatware desktop manager such as fvwm? Nothing happens.

What's going on:

There has been a lot of work in the past few years on co-opting what Windows does right. In particular, there's a new form of inter-process communication called the dbus. Each user session needs one of these (as well as a system-wide dbus). Gnome and KDE have a default configuration that starts it up, but a troglodyte needs to take care of this by hand, as well as starting gnome-volume-manager.

The system-wide haldaemon taps into the kernel feed of hotplug messages and rebroadcasts them on the dbus. gnome-volume-manager listens on the session dbus for these messages. If suitably configured (and the default configuration does this), it sends messages back to haldaemon asking it to mount newly appeared removeable media, or it may launch a media player for music or video discs, or various other actions.

When you press the eject button on the CD drive, an inverse set of messages is sent for unmounting the media, after which the tray physically pops out (if unmounting succeeded).

How to fix:

By now there are quite a number of pages various places on the web describing how to start up gnome-volume-manager. Here's my contribution.

If not already done, you need to install the packages hal, dbus-1 and gnome-volume-manager. These are the names on my distro, SuSE 10.1; it's possible that the names differ slightly on other distros, e.g. dbus1 versus dbus-1.

I'm assuming that your boot scripts invoke haldaemon successfully. I've been successful invoking the other two daemons like this. I've put this code in /etc/X11/xdm/Xsession conditional on the window manager not being Gnome or KDE, but most people will probably put this invocation in ~/.xsession.

dbus=(`dbus-daemon --session --fork --print-pid=1 --print-address=1`)
export DBUS_SESSION_BUS_ADDRESS=${dbus[0]}
export DBUS_SESSION_BUS_PID=${dbus[1]}
gnome-volume-manager --daemon=yes --sm-disable

You can configure your instance of gnome-volume-manager by running gnome-volume-properties.

To eject a CD, press the tray open button on the drive. But if some process has the drive open or (for a data CD) has its current directory within the media, it will be busy and the unmount will fail. Stop a music player or cd off the disc, and then it can be unmounted.

However, I haven't yet figured out how to correctly unmount a USB storage device, except by doing it as root. The ordinary user does not have permission to do it. I'll bet that Gnome or KDE generate a fancy dbus message that Hal will honor. If I figure it out, I'll post the method.


Prev: Fails to Mount Media with VFAT Next: Black Screen on Logout
(Index)