3

In Xubuntu 14.04 I have tried to disable USB automount by creating the following two files as found here: Prevent a specific USB device from auto-mounting and rebooting:

/lib/udev/unmount.sh

#!/bin/bash
udisks --unmount /dev/sdn1
udisks --detach /dev/sdn

/etc/udev/rules.d/100-unmount-usb.rules

ACTION=="add", ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="yyyy", RUN+="/lib/udev/unmount.sh"

That didn't work, so I created another file as found here https://unix.stackexchange.com/questions/85061/automount-not-disabling-in-ubuntu-12-04-or-13-04

/etc/udev/rules.d/85-no-automount.rules

SUBSYSTEM=="usb", ENV{UDISKS_AUTO}="0"

After rebooting the USB still automounted.

I then installed gnome-disk-utility, which installed but no launch icon was created and typing 'gnome-disk-utility' is not recognized- I can't figure out how to launch it.I note gnome-system-tools is installed - but again I can't work out how to start it.

2 Answers2

4

For udisks2:

If udisks2 is in use, following actions are needed to not automount a device. Fisrt, you need to get informations about the device to write a udev rule. Unmount the device, become root via

sudo su

then run this command:

udevadm monitor --environment --udev

After that, plug the device to the computer. Now, you can see relative informations about the device. What you need is ENV{ID_VENDOR} and ENV{ID_FS_UUID}. Especially ID_FS_UUID is important because it is a unique value for the device. Press ctrl+c to exit udevadm.

Then, run the following command to get other informations you need

udevadm info -a -p $(udevadm info -q path -n /dev/sdX)

Replace /dev/sdX with your drive. Look for ATTRS{idVendor} and ATTRS{idProduct} values. You need SUBSYSTEM AND DRIVER values to specify which device block this rule will be applied and ENV{UDISKS_AUTO}="0" to make the device not auto-mountable. If you get all informations you need, it is time to write udev rule. Open a new rule file:

sudo -H gedit /etc/udev/rules.d/10-noautomount.rules

And write information you got to it:

SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{idVendor}=="3538"
ATTRS{idProduct}=="0070"
ENV{ID_VENDOR}=="PQI"
ENV{ID_FS_UUID}=="1A5AFC1F427754BF"
ENV{UDISKS_AUTO}="0"

Save the file and close it. A rule in /etc/dev/rules.d/ directory has the highest priority. By writing the rule in that directory, we will prevent any problem that may hinder the rule.

Now, you can test your rule to see whether it is working or not. First, you need to learn "devpath" of the device. You will see lines in the output of

udevadm info -a -p $(udevadm info -q path -n /dev/sdX)

command similar to this line:

looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5...'

Some of them is very long and is not usefull for you. You need to cut that line to a degree which is usefull for you. To learn where to cut, run this command:

dmesg | grep usb

You will see lines relative to the device similar to these lines:

usb 2-1.5: new high-speed USB device number 15 using ehci-pci
usb 2-1.5: New USB device found, idVendor=3538, idProduct=0070
usb 2-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-1.5: Product: PQI USB Flash drive
usb 2-1.5: Manufacturer: PQI
usb 2-1.5: SerialNumber: XQVBW9KR
usb-storage 2-1.5:1.0: USB Mass Storage device detected

Pay attantion to value after usb one (2-1.5). It shows that your device's path and where to cut. So "devpath" of this device is

/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5

Now you can test the new udev rule by running this command:

udevadm test /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5

Near the end of the output of above command, if you see the line

UDISKS_AUTO=0

it means that your new rule is working. To apply the new rule, you need to reload udev rules by

udevadm control --reload

If it does not work, run

udevadm trigger

After that, you can see wherher the new rule is working or not by un-plugging the device and re-plugging it. Your device will be shown in Unity launcher like this:

enter image description here

In my case, "nd" is the device to which no-automount udev rule is applied. If I press the icon of the device, it will be mounted.

For udisks

If udisks is in use, you can use ENV{UDISKS_PRESENTATION_NOPOLICY}="0" value to make the device not-automountable. Since my system ( Ubuntu 15.04) isn't using udisks, I can not give specific instructions but the process is similar. Write a new udev rule in /etc/udev/rules.d/ directory for your device with values you get above and add ENV{UDISKS_PRESENTATION_NOPOLICY}="0" value instead of ENV{UDISKS_AUTO}="0" value.

I hope this answer help you.

numand
  • 1,696
  • Just a note, for the test udevadm test /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5 I got an error that the dive couldn't be fount, checked the direcories and found I needed to append a ':1.0' on the end, then it worked. Although the device doesnt mount - it still shows as an icon when I plug it in, and Xubuntu still seems to have control over it as when I try to access from a clonezilla boot, clonezilla can't see it (could also be somethiong related to the VM). – Don Smythe Jul 26 '15 at 21:55
  • wow this is really complex. i just don't want anything automounted ever, regardless of vendor or device, and i need to be able to flip it on and off like a switch – Michael Nov 09 '16 at 20:21
  • 1
    @Michael For XUbuntu try Settings->Removable Drives and Media then uncheck the boxes under removable storage – Don Smythe Nov 10 '16 at 07:56
0

copied from https://unix.stackexchange.com/a/536545/302588:

# /etc/udev/rules.d/99-noautomount.rules
ENV{UDISKS_PRESENTATION_HIDE}="1"
ENV{UDISKS_PRESENTATION_NOPOLICY}="1"
ENV{UDISKS_AUTOMOUNT_HINT}="never"
ENV{UDISKS_SYSTEM_INTERNAL}="1"
ENV{UDISKS_IGNORE}="1"
ENV{UDISKS_AUTO}="0"

https://www.systutorials.com/docs/linux/man/7-udisks/ :

UDISKS_PRESENTATION_HIDE
  If set to 1 this is a hint to presentation level software that the device should not be shown to the user.

UDISKS_PRESENTATION_NOPOLICY
  If set to 1 this is a hint to presentation level software that the device should not be automounted or autoassembled (for e.g. components of a multi-disk device).

UDISKS_AUTOMOUNT_HINT
  A variable to influence whether a device should be automounted. Possible values include "always" (to hint that a device should always be automounted) and "never" (to hint that a device should never be automounted). Note that this is only a hint - the auto-mounter might not honor it.

UDISKS_SYSTEM_INTERNAL
  If set, this will override the usual bus type based detection of whether a device is considered "system internal". "0" means "removable" (i. e. eligible for automounting, and normal users can mount), any other value means "system internal" (i. e. no automounting, and only administrators can mount).

https://www.systutorials.com/docs/linux/man/8-udisks/ :

UDISKS_IGNORE
  If set, this overrides the value of the HintIgnore property.

UDISKS_AUTO
  If set, this overrides the value of the HintAuto property.