Desktop

Auto-Mount USB Drives on Linux with udiskie

udiskie is a lightweight automount daemon that uses udisks2 to automatically mount USB drives, external hard disks, SD cards, and other removable media when you plug them in. It runs in userspace, needs no root privileges for day-to-day use, and works with any Linux desktop or window manager. This guide covers installing udiskie, configuring automount rules, setting up a systemd user service for auto-start, and using the tray icon for quick device management.

Original content from computingforgeeks.com - post 2567

udiskie provides four command-line tools – udiskie (the daemon), udiskie-mount, udiskie-umount, and udiskie-info – along with optional desktop notifications and a system tray icon. It supports LUKS encrypted volumes, loop devices for ISO files, and per-device mount options through a YAML config file. The current release is udiskie 2.6.2, which requires Python 3 and udisks2.

Prerequisites

  • A Linux system running Ubuntu 24.04/22.04, Debian 13/12, Fedora 42, Arch Linux, or RHEL 10/Rocky Linux 10/AlmaLinux 10
  • A regular user account (udiskie runs in userspace – no root needed after install)
  • udisks2 installed (most desktop installs include it by default)
  • Python 3.5 or newer
  • A desktop environment or window manager with a running D-Bus session

Step 1: Install udiskie on Linux

udiskie is packaged in most major distribution repositories. Install it with your distro’s package manager.

Ubuntu / Debian

On Ubuntu and Debian, udiskie and its dependencies are in the default repositories:

sudo apt update
sudo apt install udiskie

This pulls in udisks2, python3-gi, python3-yaml, and the GObject introspection bindings automatically.

Fedora / RHEL / Rocky Linux / AlmaLinux

On Fedora, RHEL 10, Rocky Linux 10, and AlmaLinux 10, install udiskie with dnf:

sudo dnf install udiskie

On RHEL-based systems, make sure the EPEL repository is enabled if the package is not found in the base repos.

Arch Linux

Arch Linux ships udiskie in the community repository. If you are running Arch Linux, install it with pacman:

sudo pacman -S udiskie

Install with pip (any distro)

You can also install the latest release from PyPI if your distro packages an older version:

pip install --user udiskie

Make sure ~/.local/bin is in your PATH if you install with pip.

Step 2: Basic Usage – Auto-Mount USB Drives

Start udiskie in the foreground first to check that everything works:

udiskie -v

The -v flag enables verbose output so you can see mount events as they happen. Plug in a USB drive and you should see log messages showing the device being detected and mounted automatically. Press Ctrl+C to stop the daemon.

To run udiskie as a background process in your current session:

udiskie &

The & sends it to the background. Devices will now automount under /run/media/$USER/ (the udisks2 default mount point). To stop the background process:

pkill udiskie

For window managers like i3, Sway, or Openbox, add udiskie & to your startup config (for example, ~/.config/i3/config or ~/.xinitrc) so it launches automatically with your session.

Step 3: Configure udiskie with config.yml

udiskie reads its configuration from ~/.config/udiskie/config.yml. Create the directory and config file:

mkdir -p ~/.config/udiskie

Open the configuration file in your editor:

vi ~/.config/udiskie/config.yml

Add the following configuration to control automount behavior, notifications, tray icon, and per-device rules:

program_options:
  automount: true         # Mount devices automatically when plugged in
  notify: true            # Show desktop notifications on mount/unmount
  tray: true              # Show system tray icon
  file_manager: xdg-open  # Open file manager when clicking mounted device

notifications:
  timeout: 3              # Notification display time in seconds
  device_mounted: 5       # How long to show mount notification
  device_unmounted: 3     # How long to show unmount notification

device_config:
  # Ignore a specific device by UUID
  - id_uuid: "1234-ABCD"
    ignore: true

  # Set custom mount options for a device
  - id_uuid: "5678-EFGH"
    options:
      - noexec
      - nosuid
      - nodev
    automount: true

  # Disable automount for optical drives
  - is_optical: true
    automount: false

Find the UUID of your devices by running lsblk -o NAME,UUID,FSTYPE,SIZE,MOUNTPOINT and use those values in the id_uuid field. The device_config section lets you set different rules per device – useful when you want to ignore certain drives or apply specific mount options like noexec for security.

Step 4: Auto-Start udiskie with a Systemd User Service

Instead of adding udiskie to your shell startup, create a systemd user service for reliable auto-start and process management. This works regardless of your desktop environment or window manager.

Create the service file:

mkdir -p ~/.config/systemd/user

Open the unit file in your editor:

vi ~/.config/systemd/user/udiskie.service

Add the following systemd unit configuration:

[Unit]
Description=udiskie automount daemon
After=graphical-session.target

[Service]
ExecStart=/usr/bin/udiskie --smart-tray --notify
Restart=on-failure
RestartSec=5

[Install]
WantedBy=default.target

The --smart-tray flag shows the tray icon only when a removable device is present, keeping your system tray clean. Enable and start the service:

systemctl --user daemon-reload
systemctl --user enable --now udiskie.service

Verify the service is running:

systemctl --user status udiskie.service

The output should show active (running). The service will start automatically on every login from now on. If you need to check logs:

journalctl --user -u udiskie.service -f

This shows live log output. You can plug in a USB drive to confirm mount events appear in the journal.

Step 5: Use the udiskie Tray Icon

The tray icon gives you quick access to mount, unmount, and open mounted devices without touching the terminal. Start udiskie with the tray enabled:

udiskie --tray &

This puts a disk icon in your system tray. Left-click it to see a list of all removable devices with their mount status. From the menu you can mount, unmount, eject, or open the file manager for any device.

There are two tray modes available:

  • --tray – Always show the tray icon, even when no devices are connected
  • --smart-tray – Only show the icon when at least one removable device is present

For minimal desktop setups, --smart-tray is the better choice since it only appears when you actually need it. The tray requires a system tray implementation – most desktop environments provide one, and for standalone window managers you can use tools like trayer or stalonetray.

Step 6: Mount and Unmount Specific Devices

Beyond automatic mounting, udiskie provides dedicated commands for manual device management. This is useful when you need to format or manage USB drives and then remount them.

Mount a device

Mount a specific partition by its device path:

udiskie-mount /dev/sdb1

Mount all currently unmounted removable devices at once:

udiskie-mount --all

Unmount a device

Unmount a device by its device path or mount point:

udiskie-umount /dev/sdb1

Or unmount by mount point:

udiskie-umount /run/media/$USER/MyUSB

Safely detach a USB drive

To unmount and power off the device so it is safe to physically remove:

udiskie-umount --detach /dev/sdb

The --detach flag tells the kernel to power off the USB port after unmounting, which is the equivalent of “Safely Remove” on other operating systems.

Get device information

Check details about connected devices with udiskie-info:

udiskie-info -a

This lists all removable devices with their UUIDs, filesystem types, mount points, and sizes – handy for finding the UUID values needed in your config file.

Step 7: udiskie vs udisksctl vs autofs – Comparison

Linux offers several approaches to automounting. Here is how udiskie compares to the other common options. If you want a simpler auto-mount setup for USB devices on Arch Linux, udisksctl may be enough on its own.

Featureudiskieudisksctlautofs
TypeAutomount daemon with tray UIManual CLI tool (part of udisks2)Kernel-based automounter
Automount on plugYes – automaticNo – manual command per deviceYes – on access (lazy mount)
Root privilegesNo (runs in userspace)No (uses PolicyKit)Yes (system service)
Tray iconYesNoNo
LUKS supportYes – auto-prompts for passwordYes – manual unlock commandNo built-in support
Config fileYAML per-device rulesNone/etc/auto.master maps
Best forDesktop users who want hands-free USB mountingOne-off mounts, scriptingNetwork shares (NFS, SMB), server environments

udisksctl is the low-level command-line interface to udisks2. It mounts devices on demand but has no daemon mode – you must run udisksctl mount -b /dev/sdb1 manually each time. Good for scripting, but not practical for daily desktop use.

autofs is a kernel automounter designed primarily for network filesystems like NFS and SMB shares. It mounts on first access (when a process reads the mount point) and unmounts after idle timeout. It works for USB drives too, but requires root configuration in /etc/auto.master and is overkill for simple removable media.

For desktop Linux users who plug in USB drives and external disks regularly, udiskie is the best fit – it handles everything automatically, runs without root, and gives you a tray icon to manage devices visually.

Conclusion

You now have udiskie set up as an automount daemon on Linux – USB drives, external disks, and SD cards mount automatically when connected and can be managed from the tray icon or command line. The systemd user service ensures udiskie starts on every login without manual intervention. For creating bootable USB drives, you will want to temporarily stop udiskie so it does not interfere with the write process. Consider adding noexec and nosuid to your default mount options in the config file for better security on untrusted removable media.

Related Articles

Debian Best Gnome GTK Themes for Kali Linux / Debian / Ubuntu Desktop Install Anydesk | TeamViewer on Garuda Linux Desktop How To Install Wireshark on Debian 11/10/9 Desktop Desktop How to Install Omarchy OS – Arch-Based Hyprland Desktop

Leave a Comment

Press ESC to close