15

I have an Ubuntu 16.04 LTS desktop system that I use to rescue disk drives (using dd or ddrescue). Whenever I plug in a disk drive it is automatically mounted and shown in the file manager.

I don't want this because I am afraid of the disk to be rescued is modified by the mounting process. It is me who decides if and when that disk is mounted, and not some OS function.

Surprisingly I could not find a setting to deactivate the auto-mount function. Some solutions suggest to enter the affected partitions in /etc/fstab and disable mounting there, however as each disk drives to be rescued may have different partitions this is not going to work in my case.

How to fully disable the auto mount feature of Ubuntu?

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
  • 3
    Good question, but I don't think it belongs on [sf]. Would be a better fit for [ubuntu.se] or [unix.se]. I have voted to migrate the question. – kasperd Dec 11 '16 at 19:24
  • 1
    I'd suggest you gogle for `linux forensic distribution` there are better choices for your task. For ubuntu a search for [dsiable automount](http://askubuntu.com/questions/89244/how-to-disable-automount-in-nautiluss-preferences) gets you some hits. –  Dec 11 '16 at 22:44
  • You rather don't want Ubuntu for that at all, see http://forensicswiki.org/wiki/Forensic_Live_CD_issues -- a proper forensic rescue disk doesn't try mounting filesystems without taking extra care when looking for its squashfs, for example... the two proper implementations in this regard I know are http://grml.org and http://en.altlinux.org/rescue – Michael Shigorin Dec 18 '19 at 16:34

4 Answers4

10

The core of the automount system is probably the udisks system. The daemon process should be udisksd and the systemd service might be udisks2.service (at least on my Debian 9; the name might vary on Ubuntu).

Once you stop that service (e.g. with systemctl stop udisks2.service) the GUI session should be unable to auto-mount anything.

To make sure any other service does not reactivate it, you could mask it: systemctl mask udisks2.service.

telcoM
  • 87,318
  • 3
  • 112
  • 232
  • 1
    `sudo systemctl stop udisks2.service` correctly disabled automount for my session in a 64-bit XUbuntu Linux version 16.04 (a.k.a. "Xenial Xerus"). – Yuri Sucupira Nov 03 '19 at 03:16
  • Stopping `udisk2.service` not only disables automount, but also has possibly unwanted side effects. I.E. `gnome-disks` stops working, too. – Tino Mar 16 '23 at 02:20
7

To stop auto-mounting of specific devices, add an entry to /etc/fstab with the noauto optiion.

Example entry (after getting the UID using the blkid command):

...
UUID=2017-09-15-16-48-31-00 none mac noauto 0 0
...

nyxee
  • 474
  • 3
  • 6
3

In Ubuntu 22.04 I was able to stop automatic mounting of devices using the dconf Editor. First install it:

sudo apt install dconf-editor

Next, run it and navigate up to this setting:

enter image description here

and simply disable it. That's it.

Source: here.

user171780
  • 157
  • 1
  • 7
  • 2
    To automate: `gsettings set org.gnome.desktop.media-handling automount false` [[source](https://www.suse.com/support/kb/doc/?id=000019002)] – Tino Mar 16 '23 at 02:28
  • Yeah, the GUI option is nice, but if you're willing to run a command-line program anyway (sudo apt install ...), you might as well run a `gsettings` command instead. – mwfearnley Jul 18 '23 at 07:58
0

So you want to recover disks without messing with their contents. Yes, mounting their filesystems will increment counters, and possibly damage an already damaged filesystem.

In this case you can't just run dd on a disk to prevent this from happening, because by the time you plug it in that system has already automatically mounted it. You will be using the new udisks system to auto-mount new volumes based on udev events. You can turn this functionality off entirely in your GUI.

Within "Settings" > "Removable Drives and Media": uncheck all of the "removable storage" boxes. This should disable the feature entirely.

Spooler
  • 230
  • 1
  • 7
  • I can't find the "Settings" > "Removable Drives and Media" dialog you are mentioning. My Ubuntu system has a "System Settings" dialog but that page does not have a "Removable Drives and Media" dialog. I found a "Details" program having a "Removable Media" dialog but the "removable storage" check boxes do not exist. –  Dec 11 '16 at 19:05
  • 1
    Running `sudo systemctl stop udisks2.service` in the shell prior to connecting the defective device solves it in a Ubuntu system (I'm using the 64-bit XUbuntu 16.04 distro). The command `dd` should not be used for copying the contents of a defective drive: `ddrescue` should be used instead. Example: `ddrescue -Adf -r 3 -v /dev/sdb1 sdb1.iso` will attempt to copy partition 1 of disk `sdb` to a file `sdb1.iso` placed in the directory where such command is run. Running `photorec sdb1.iso` will cause `photorec` to read and copy the contents of `sdb1.iso` to the directory where such command is run. – Yuri Sucupira Nov 03 '19 at 03:22