Udisks

udisks is a D-Bus daemon offering some storage related services:
 * enumeration of storage devices, much like udev but with more details.
 * mounting of filesystems.
 * partition of storage devices.
 * monitor of storage devices.
 * configuration of storage devices.

Prerequisites
Udisks uses D-Bus and polkit, so set them up first.

Kernel
You need to activate the following kernel options:

Software
Portage knows the global USE flag udisks for enabling support for udisks in other packages. Enabling this USE flag will pull in automatically (default for desktop profiles):

After setting this you want to update your system so the changes take effect:

Addon software

 * - GNOME program to partition, configure and monitor storage devices.
 * - Automatic mount of drives.
 * - Run actions on udisks events.

Configuration
Udisks uses polkit to handle permissions.

Groups
Make sure your user in the group plugdev. Here the example user foo is used.

If plugdev is not among your user's groups (common users, who use a window manager instead of a desktop environment), add you user to the plugdev group.

Usage
Some useful commands are: In some cases the udisks command is not found. If this is the case, try udisksctl (Will have different command options from udisks)
 * udisks --enumerate - Lists all storage devices.
 * udisks --monitor - Monitor udisks.
 * udisks --monitor-details - Monitor udisks with more details.
 * udisks --inhibit-polling /dev/DEVICEFILE - Disable polling on the given device.

Python Scripting
The following code is an example of listening to udisk on the system dbus for device events. We stick with udisk1 and glib style event loops in order for the code to also be able to run on a RedHat or Centos system. Otherwise, we could use the udisk2 monitor api to just look at mount events.

The relevant udisk documentation url for 1.0.5 (Rhel6 is at 1.0.1) is here

USB Thumb Drive Example
The following example is from a gentoo system when an 8gb thumb drive containing kubuntu 14.04 installer is plugged into a usb port. It was created by dd'ing the iso file directly to the thumb drive. fdisk shows that the 1gb or so of good stuff ended up in /dev/sdf2 while /dev/sdf1 is the free space left over. Note that the first event is the "whole drive" or partition table getting looked at.

This happens when the device notifier pops up and we have kde open the drive in the dolphin file manager.

All this happens when we do a "safely remove" in dolphin. Notice that some of the properties are already unset and we are catching exceptions in device_dump during examination

Then we get one last removal signal when we yank the thumb drive

CD/DVD media example
The use of a dvd or cdrom in an internal drive will cause only changes events to signal. Here's an example for a mount followed by an unmount of a gentoo autobuild iso in a Centos6 VM's virtual cdrom. Notice that there are two change signals per action. The insertion shows the first event with media available and then a second event on the mount where the DeviceMountedByUid value properly matched up with our uid. Presumably the two for the removal are the unmount followed by an eject, but media shows as not being available on both so the two are indistinguishable.

-

Troubleshooting

 * udisks communicates over D-Bus, so also see the D-Bus "Troubleshooting" section.
 * udisks communicates over D-Bus, so also see the D-Bus "Troubleshooting" section.
 * udisks communicates over D-Bus, so also see the D-Bus "Troubleshooting" section.