11

I would like to stop Ubuntu from mounting my other (Windows) partitions automatically since I do not need it very often, I would like not to automount "System reserved" partition for Windows.

There is a similar question here:

How can I stop Ubuntu 12.04 from mounting Fedora 16's Swap Partition?

However, I do not have these partitions added in /etc/fstab.

How can I do it ?

For proof, my /etc/fstab:

proc            /proc           proc    nodev,noexec,nosuid          0   0
# / was on /dev/sda7 during installation
UUID=1384cee0-6a71-4b83-b0d3-1338db925168 / ext4  errors=remount-ro  0   1
# swap was on /dev/sda6 during installation
UUID=e3729117-b936-4c1d-9883-aee73dab6729 none swap    sw            0   0
#------ MY WINDOWS D DRIVE---------- I WANT TO KEEP IT
UUID=98E8B14DE8B12A80   /media/d ntfs   defaults,errors=remount-ro   0   0
Patryk
  • 9,146

3 Answers3

20

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.

Marty Fried
  • 18,466
  • This won't mount automatically. What about the case I have an HD (Volume) with 2 partitions (NTFS). When I double click this volume on File Manager it mounts both partitions. How can I edit in fstab to not mount specific partition out of the 2? Maybe by nouser? – Royi Apr 19 '20 at 18:49
10

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

muru
  • 197,895
  • 55
  • 485
  • 740
Ashwin Joshi
  • 155
  • 2
  • 9
  • This one has the facility of also remove from devices list with ease. Using noauto at fstab will just not mount untill you do, but removing from system list will avoid you to mount by mistake from any kind of file manager, as far as i understand. – m3nda Aug 20 '19 at 15:36
1

1: Use blkid to get your partition name

blkid
/dev/nvme1n1p7: UUID="d9c349bc-cf7f-43fd-a57b-2b12e08fb16b"  TYPE="ext4" PARTUUID="3f4bd9ad-0dad-4c37-8dbd-a30c31ac25fb"
/dev/nvme0n1p1: UUID="16b734d5-6df8-4d47-bd04-8c5d3e29f05a" BLOCK_SIZE="4096" TYPE="ext4"...

The partition name is the part after /dev so nvme0n1p1 or above nvme1n1p7

  • go to the directory /etc/udev/rules.d and

  • create a file named 10-local-rules with the following content: replace nvme1n1p1 with your partition name

    KERNEL=="nvme1n1p1", ENV{UDISKS_IGNORE}="1"

  • You can use the following to see what identifies your device:

    udevadm info --attribute-walk --name=/dev/nvme1n1p1

  • I found this the most useful because it does not require me to specify a mount point. I used udevadm info -q property /dev/XXX to discover that I could match by PARTNAME and used lines like SUBSYSTEM=="block", ENV{PARTNAME}=="YYY", ENV{UDISKS_IGNORE}="1" – rptb1 Mar 19 '23 at 13:00