How can I prevent Ubuntu from mounting particular partitions/devices?

Solution 1:

The solution is to add them to /etc/fstab, but with options to prevent them from being automatically mounted. The option you want is noauto rather than auto. For example, to prevent a windows partition from being mounted, you could add an entry like the following:

UUID=C2A281E4A281DCF3 /media ntfs-3g defaults,noauto 0 0

You can run blkid to retrieve the partition UUID:

sudo blkid

See "Using UUID" in the Ubuntu Docs.

Or, to make it more self-documenting and simpler, although not quite as fail-proof, I have switched to using disk labels rather than UUIDs. You just need to make sure the label is descriptive and unique; unlike using UUIDs, labels are not guaranteed to be unique, but I've never run into a problem, and it's more convenient, as you can swap a different partition by using the same label, and no need to modify /etc/fstab, or to run blkid.

Contrast the above entry with this one:

LABEL=Win_sys   /media     ntfs-3g   defaults,noauto   0  0

A good explanation of fstab options can be found on the ArchWiki and on the Ubuntu Docs.

Solution 2:

Just use gnome-disks facility in Ubuntu. Type this in your terminal:-

user@user-X550LD:~$ gnome-disks

Easy to use. Click on any partition and select the "settings" cog wheel down at the bottom near the "play" and "minus" signs. Select mount options and voila.

enter image description here