3

On Linux (Gnome desktop) how do you prevent one of the partitions on an external USB drive auto-mounting when it attached to the machine?

I don't just want to prevent the Nautilus window from popping up -- I want that partition not to mount.

Fiddling with /etc/fstab is not acceptable, as this is a removable drive that is attached to different machines.

I seem to remember that you create a hidden file in the root of the file system, but I can't remember what it's called. Something like:

touch /media/usbdisk/.no-mount

How do you actually make this work?

1
  • 2
    If I understand you correctly, you want the drive to not be auto-mounted on any linux machine, but without any configuration on the machine itself?
    – user4358
    Aug 20, 2009 at 16:43

3 Answers 3

3

To read that file, the partition would have to be mounted. The auto-mounting is a feature of the operating system (actually hotplug, or some other service monitoring USB) and has to be turned off per-machine.

2

If you're specifically worried about auto-mounting in gnome, and would rather not touch /etc/fstab, try the following command to turn it off for a specific partition:

gnome-mount --write-settings --mount-options noauto --device /dev/sda1

If you no longer want this to happen, erase the settings:

gnome-mount --erase-settings --device /dev/sda1

I also think you can turn off auto-mount altogether through the gconf-editor utililty: desktop > gnome > volume_manager > automount_media

I'm not aware of any way to have the auto-mount daemon look for a file on the drive and unmount the drive on finding it, though I can see the utility in having something like this.

3
  • I tried this, but it results in an error: Cannot mount volume - invalid mount option when attempting to mount the volume 'volume label'. Any ideas?
    – chris
    Sep 13, 2009 at 18:27
  • Can you provide the command you ran, and did you get the error when running the command or when attaching the device?
    – user4358
    Sep 13, 2009 at 20:12
  • gnome-mount is not in recent distributions like Ubuntu 10.04 Lucid. I've looked but haven't run across a way to do this now. Any tips? The closest I've gotten is stopping all USB auto-opening Disabling auto-open - Ask Ubuntu - Stack Exchange
    – nealmcb
    Feb 7, 2011 at 5:25
0

At first, run udisksctl status to get the device path, followed by eg. udevadm info --attribute-walk --name=/dev/sr0, to get the characteristics of the USB device to ignore.

Then add a rule with UDISKS_IGNORE into /etc/udev/rules.d/12-prevent-automount.rules. For example, this blocks the "HiSuite" "Linux File-CD Gadget" of a Huawei Matepad Pro 12.6", as the Windows software is rather irrelevant - and it's mount notifications are just as irrelevant:

ACTION=="add|change", SUBSYSTEM=="block", KERNEL=="sr[0-9]*", ATTRS{model}=="File-CD Gadget  ", ENV{UDISKS_IGNORE}="1"

Then reload the rules with: udevadm control --reload-rules && udevadm trigger.

For testing the rule: udevadm monitor --environment --udev

You must log in to answer this question.