Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

udisksctl

Mount, unmount, unlock and power off removable disks as a normal user — the command-line side of the desktop's automount.

Level
Extra
Group
Disks and file systems
Needs root
No
Package
udisks2

What it does

udisksctl talks to the udisks2 service. A user at the local desktop may mount USB sticks, SD cards and ISO files without root; polkit decides what is allowed. Mounts go to /run/media/USER/LABEL. power-off stops the whole device so it is safe to unplug.

It also sets up loop devices for image files and unlocks LUKS-encrypted disks.

How to write it

udisksctl COMMAND [OPTION]...

Main parts

Commands

status
List the drives and their block devices.
info -b DEV
All details of a device (from udisks).
mount -b DEV
Mount a file system as the user.
unmount -b DEV
Unmount it.
unlock -b DEV / lock -b DEV
Open / close a LUKS encrypted device.
loop-setup -f FILE
Make a loop device for an image file.
loop-delete -b DEV
Remove a loop device.
power-off -b DEV
Stop the drive so it can be removed.
smart-simulate -f FILE -b DEV
Load SMART data from a file (testing).
monitor
Show udisks events live.
dump
Show everything udisks knows.
help
Show help.

Options 11

Most used

Options

-b, --block-device=DEV
The device, for example /dev/sdb1.
-p, --object-path=PATH
The udisks object path instead of a device.
-d, --drive=DRIVE
A drive object (with info).
-t, --filesystem-type=TYPE
File system type for mount.
-o, --options=OPTS
Mount options, for example ro or noexec.
-f, --force
Force the unmount.
--key-file=FILE
Read the LUKS passphrase from a file (unlock).
-f, --file=FILE
The image file (loop-setup, smart-simulate).
-r, --read-only
Read-only loop device.
-o, --offset=BYTES / -s, --size=BYTES
Part of the file for the loop device.
--no-user-interaction
Do not ask for a password (fail instead).

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Show all drives

    udisksctl status
    MODEL                     REVISION  SERIAL               DEVICE
    --------------------------------------------------------------------------
    SanDisk Ultra             1.00      4C530001231022115423 sda
  2. 2Mount a USB stick as a normal user

    udisksctl mount -b /dev/sda1
    Mounted /dev/sda1 at /run/media/student/BACKUP
  3. 3Mount read-only

    udisksctl mount -b /dev/sda1 -o ro
  4. 4Unmount and power off before you unplug it

    udisksctl unmount -b /dev/sda1
    Unmounted /dev/sda1.
    udisksctl power-off -b /dev/sda
  5. 5Open an ISO file without root

    udisksctl loop-setup -r -f ~/Downloads/rhel-10.0-x86_64-dvd.iso
    Mapped file /home/student/Downloads/rhel-10.0-x86_64-dvd.iso as /dev/loop0.
    udisksctl mount -b /dev/loop0
    udisksctl unmount -b /dev/loop0
    udisksctl loop-delete -b /dev/loop0
  6. 6Unlock an encrypted USB disk

    udisksctl unlock -b /dev/sdb1
    Passphrase:
    Unlocked /dev/sdb1 as /dev/dm-3.
    udisksctl mount -b /dev/dm-3
  7. 7Lock it again after use

    udisksctl unmount -b /dev/dm-3
    udisksctl lock -b /dev/sdb1
  8. 8Details of a device

    udisksctl info -b /dev/sda1 | grep -E 'IdLabel|IdType|Size'
  9. 9Watch what happens when you plug a device in

    udisksctl monitor
  10. 10Use it in a script without password prompts

    udisksctl mount -b /dev/sda1 --no-user-interaction || echo "not allowed"

Watch out

  • Over SSH, polkit normally does not allow normal users to mount; use sudo mount there.
  • power-off works on the whole disk (/dev/sda), not on a partition.

Files

/run/media/USER/
Where udisks mounts devices for a user.
/etc/udisks2/
Settings of udisks2.

Tips to remember

  • lsblk -f first: it shows the label and file system of every partition.

Exit codes

0Success.
1Error (not allowed, busy, not found).

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man udisksctl