The Auto-Mount Behavior
When you plug a USB flash drive or an external hard drive into a computer running the Ubuntu Linux desktop, the operating system instantly detects the hardware, automatically mounts the filesystem, and slaps a shortcut icon onto your launcher. For general use, this is highly convenient. However, if you are a system administrator attempting to run data recovery tools, format a corrupted drive, or clone a disk using dd, this automatic mounting is incredibly dangerous. Modifying a disk while the operating system has it actively mounted can lead to catastrophic data corruption.
How to Disable Auto-Mount in the GNOME Desktop
If you are using the default Ubuntu graphical interface (GNOME), the auto-mounting is handled by the GSettings configuration system. You can disable it using the terminal without needing to uninstall any system packages.
1. Open your terminal application (Ctrl+Alt+T).
2. To stop Ubuntu from automatically mounting the disk to the filesystem, run the following command:
gsettings set org.gnome.desktop.media-handling automount false
3. To stop Ubuntu from automatically opening the file manager window when a disk is inserted, run this command:
gsettings set org.gnome.desktop.media-handling automount-open false
From this point forward, when you insert a USB drive, the hardware will be recognized by the kernel (you can see it using lsblk), but it will not be mounted. You must manually mount it using the mount command when you are ready.
How to Prevent Auto-Mounting of Internal Drives (fstab)
The previous method only applies to removable media like USB drives. If you have internal hard drives (like a secondary storage drive) that automatically mount during the boot process, and you want them to remain unmounted until you specifically request them, you must edit the filesystem table.
1. Open your terminal.
2. Edit the fstab file with root privileges:
sudo nano /etc/fstab
3. Locate the line that corresponds to the drive you want to stop mounting (e.g., /dev/sdb1 or a specific UUID).
4. Look at the fourth column of that line, which contains the mount options (usually something like defaults or rw,relatime).
5. Add the word noauto to that list of options, separated by a comma. For example:
UUID=1234-5678 /mnt/data ext4 defaults,noauto 0 2
6. Save the file (Ctrl+O, Enter) and exit (Ctrl+X).
The noauto flag explicitly tells the Linux kernel to ignore this drive during the automatic boot sequence. It will only mount when you manually run sudo mount /mnt/data.