I had the problem that I don’t want to automount a specific USB device in Linux. I could switch whole automount off, but this was not what I wanted.
To achieve this, you can define a specific udev rule. Udev is the widely used daemon for handling devices of Linux kernels in user space.
First you need to know how to identify your device. So plug your USB stick in and view the device specific parameters. The following example assumes, that your USB stick is added as /dev/sdb
.
sudo udevadm info -a -n /dev/sdb
You will see everything which is related to this USB device, so also USB hub, etc. So be careful to choose the correct attributes for further filtering.
Now you have to add a udev rule for your device. You should create a new rules file, for example in /etc/udev/rules.d/10-myspecialdevice.rules
with the following content:
ATTRS{idProduct}=="449a", ATTRS{idVendor}=="0815", ATTRS{serial}=="foobar", ENV{UDISKS_AUTO}="0"
The first 3 ATTRS
parts are your extracted attributes from the previous command. The last sets an environment variable UDISKS_AUTO
which handles the automount behavior of Gnome. There are more variables, for example UDISKS_IGNORE=1
for hiding the device in Nautilus. The following overview can be found in the man pages via man udisks
:
UDISKS_SYSTEM
If set, this overrides the value of the HintSystem property.UDISKS_IGNORE
If set, this overrides the value of the HintIgnore property.UDISKS_AUTO
If set, this overrides the value of the HintAuto property.UDISKS_CAN_POWER_OFF
If set, this overrides the value of the CanPowerOff property.UDISKS_NAME
The name to use for the device when presenting it in an user interface. This corresponds to the HintName property.UDISKS_ICON_NAME
The icon to use for the device when presenting it in an user interface. If set, the name must adhere to the freedesktop.org icon theme specification[4]. This corresponds to the HintIconName property.UDISKS_SYMBOLIC_ICON_NAME
The icon to use for the device when presenting it in an user interface using a symbolic icon. If set, the name must adhere to the freedesktop.org icon theme specification[4]. This corresponds to the HintSymbolicIconName property.UDISKS_FILESYSTEM_SHARED
If set to 1, the filesystem on the device will be mounted in a shared directory (e.g. /media/VolumeName) instead of a private directory (e.g. /run/media/$USER/VolumeName) when the Filesystem.Mount() method is handled.ID_SEAT
The physical seat the device is attached to. If unset or set to the empty string, “seat0” (the first seat) is assumed.
After you created your file you have to reload your rules:
sudo udevadm control --reload