# Udisks

Related articles

- udev
- Mount
- Polkit
- File manager functionality

udisks provides a daemon udisksd, that implements D-Bus interfaces used to query and manipulate storage devices, and a command-line tool udisksctl, used to query and use the daemon.

## Installation

There are two versions of udisks called udisksAUR and udisks2. Development of udisks has ceased in favor of udisks2. [1]

udisksd (udisks2) and udisks-daemon (udisksAUR) are started on-demand by D-Bus, and should not be enabled explicitly (see `man udisksd` and `man udisks-daemon`). They can be controlled through the command-line with udisksctl and udisks, respectively. See `man udisksctl` and `man udisks` for more information.

## Configuration

Actions a user can perform using udisks are restricted with Polkit. If your session is not activated or present, for example, when controlling udisks from systemd/User, configure policykit manually.

See [2] for common udisks permissions for the `storage` group, and [3] for a more restrictive example.

## Mount helpers

The automatic mounting of devices is easily achieved with udisks wrappers. See also List of applications#Mount tools and File manager functionality#Mounting.

### devmon

udevil includes devmon, which is compatible with udisks and udisks2. It uses programs with the following priority:

1. udevil (SUID)
2. pmount (SUID)
3. udisks
4. udisks2

Note:

- udevil or pmount are only considered if set SUID. To remove this permission, run `chmod -s /usr/bin/udevil` as root).
- If udevil is further not executable (removed with `chmod -x /usr/bin/udevil` as root), udisks is used to monitor for new devices.

Tip: To run devmon in the background and automatically mount devices, enable it with `devmon@.service`, taking the user name as argument: `devmon@user.service`. The service reads command line arguments for devmon from the `/etc/conf.d/devmon` file. Keep in mind that services run outside the session: adjust Polkit rules where appropriate, or run devmon from the user session (see Autostart).

### udevadm monitor

You may use `udevadm monitor` to monitor block events and mount drives when a new block device is created. Stale mount points are automatically removed by udisksd, such that no special action is required on deletion.

    #!/bin/sh

    pathtoname() {
        udevadm info -p /sys/"$1" | awk -v FS== '/DEVNAME/ {print $2}'
    }

    stdbuf -oL -- udevadm monitor --udev -s block | while read -r -- _ _ event devpath _; do
            if [ "$event" = add ]; then
                devname=$(pathtoname "$devpath")
                udisksctl mount --block-device "$devname" --no-user-interaction
            fi
    done

### udiskie

udiskie is a mount helper using either udisksAUR or udisks2. It includes support for password protected LUKS devices. See the udiskie wiki for usage details. Github is also here: udiskie

#### udiskie freezing and configuration

udiskie may freeze/crash or not work in some situations/setups if you do not have some of the notification support installed. For instance xfce and udiskie may not work correctly. You may see udiskie freeze in xfce if you do not install xfce4-notifyd and notify-osd also.

If you do not source /etc/X11/xinit/xinitrc.d/50-systemd-user.sh in your .xinitrc you may have issues also.

### udisksvm

udisksvmAUR is a graphical udisks2 wrapper application written in Python3 and using the Qt5 framework. It uses only mouse clicks to mount, unmount removable devices or eject a CD/DVD. It is well adapted to light weight graphical environments, like Openbox with Tint2. It is a stand-alone mounting/automounting application running in background (see the README file in the package for details).

## Tips and tricks

### Mount to /media (udisks2)

By default, udisks2 mounts removable drives under the ACL controlled directory `/run/media/$USER/`. If you wish to mount to `/media` instead, use this rule:

    /etc/udev/rules.d/99-udisks2.rules

    # UDISKS_FILESYSTEM_SHARED
    # ==1: mount filesystem to a shared directory (/media/VolumeName)
    # ==0: mount filesystem to a private directory (/run/media/$USER/VolumeName)
    # See udisks(8)
    ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{UDISKS_FILESYSTEM_SHARED}="1"

After, you need to create /media directory:

    # mkdir /media

### Mount loop devices

To easily mount ISO images, use the following command:

    $ udisksctl loop-setup -r -f image.iso

This will create a loop device and show the ISO image ready to mount. Once unmounted, the loop device will be terminated by udev.

Note: This mounts a read only image. To mount raw disk images, such as for QEMU, remove the `-r` flag, and release the image after use with `udisksctl loop-delete -b /dev/loop0`. Substitute `/dev/loop0` with the name of the loop device.

### Hide selected partitions

If you wish to prevent certain partitions or drives appearing on the desktop, you can create a udev rule, for example `/etc/udev/rules.d/10-local.rules`:

    KERNEL=="sda1", ENV{UDISKS_PRESENTATION_HIDE}="1"
    KERNEL=="sda2", ENV{UDISKS_PRESENTATION_HIDE}="1"

shows all partitions with the exception of `sda1` and `sda2` on your desktop. Note that if you are using udisks2, the above will not work as `UDISKS_PRESENTATION_HIDE` is no longer supported. Instead, use `UDISKS_IGNORE` as follows:

    KERNEL=="sda1", ENV{UDISKS_IGNORE}="1"
    KERNEL=="sda2", ENV{UDISKS_IGNORE}="1"

Because block device names can change between reboots, it is also possible to use UUIDs (as gathered from executing the `blkid /dev/sdX` command) to hide partitions or whole devices:

For example:

    # blkid /dev/sdX
    /dev/sdX: LABEL="Filesystem Label" UUID="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX" UUID_SUB="YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY" TYPE="btrfs"

Then the following line can be used:

    ENV{ID_FS_UUID}=="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX", ENV{UDISKS_IGNORE}="1"

The above line is also useful to hide multi device btrfs filesystems, as all the devices from a single btrtfs filesystem will share the same UUID across the devices but will have different SUB_UUID for each individual device.

## Troubleshooting

### Hidden devices (udisks2)

Udisks2 hides certain devices from the user by default. If this is undesired or otherwise problematic, copy `/usr/lib/udev/rules.d/80-udisks2.rules` to `/etc/udev/rules.d/80-udisks2.rules` and remove the following section in the copy:

    # ------------------------------------------------------------------------
    # ------------------------------------------------------------------------
    # ------------------------------------------------------------------------
    # Devices which should not be display in the user interface
    [...]

### Devices do not remain unmounted (udisks)

udisks remounts devices after a given period, or polls those devices. This can cause unexpected behaviour, for example when formatting drives, sharing them in a virtual machine, power saving, or removing a drive that was not detached with `--detach` before.

To disable polling for a given device, for example a CD/DVD device:

    # udisks --inhibit-polling /dev/sr0

or for all devices:

    # udisks --inhibit-all-polling

See `man udisks` for more information.

## See also

- gentoo wiki: udisks
- Introduction to udisks

Category:

- Hardware detection and troubleshooting