The Automated Disk Mounter
Ubuntu Desktop relies on a background service called udisks2 to handle removable media. Whenever you plug in a USB flash drive or an external hard drive, the udisks2 daemon detects the new hardware, automatically mounts the filesystem to a directory under /media/, and usually triggers a notification or opens a file manager window on your desktop.
While this is convenient for casual desktop use, it can be problematic if you are using Ubuntu as a makeshift server, a digital forensics workstation, or a kiosk. In these scenarios, you may want to plug in a drive specifically to format it, repair it with fsck, or image it with dd. If udisks2 automatically mounts the drive the moment you plug it in, those low-level disk tools will fail because the filesystem is actively in use. You can disable this automounting behavior.
How to Stop Udisks2 from Automounting
The safest way to stop the automounting behavior for a specific user session without uninstalling system components is via the gsettings configuration tool.
- Open your Ubuntu Terminal.
- Run the following command to disable the automounting of recognized media:
gsettings set org.gnome.desktop.media-handling automount false
- Run the following command to disable the automatic opening of a file manager window when media is mounted:
gsettings set org.gnome.desktop.media-handling automount-open false
(Note: If you are running a headless server environment without GNOME, the udisks2 daemon is usually not installed by default, or it can simply be masked via sudo systemctl mask udisks2).
Now, when you plug in a USB drive, Ubuntu will recognize the hardware block device (e.g., /dev/sdb1), but it will not mount the filesystem. You can safely run your disk repair tools or manually mount the drive exactly where you want it using the mount command.