May 19

Linux: Disable usb automounting

Udisks and udev are related. Normally, as you can see from the above examples, when a new USB stick or DVD inserted, it is automatically mounted and the file manager is displayed. Suppose, instead, that you want that USB stick or DVD to be ignored and not mounted. How would you configure your system to do this?

While researching how to disable the automatic mounting of devices for a Linux kiosk project I was working on, I spent a number of hours on the Internet reading purported solutions to the problem. The majority of the solutions (probably 99%) simply did not work because the solution referred to obsolete versions of udev, HAL (Hardware Abstraction Layer), DBus or solutions based on PolicyKit or gsettings.

The simplest method that I have found is to create a low numbered file (I call mine 10-local.rules in /etc/udev/rules.d containing the following rule:

ACTION=="add|change", SUBSYSTEM=="block", KERNEL=="sd*|sr", ENV{UDISKS_PRESENTATION_HIDE}="1"

A twist on the above rule would apply to a kiosk-like LiveCD containing a persistent data partition to restrict mounting to /dev/sda*:

ACTION=="add|change", SUBSYSTEM=="block", KERNEL=="sd[b-e]*|sr", ENV{UDISKS_PRESENTATION_HIDE}="1"

By: Zurlinux

Copyright 2021. All rights reserved.

Posted May 19, 2014 by Timothy Conrad in category "Linux

About the Author

If I were to describe myself with one word it would be, creative. I am interested in almost everything which keeps me rather busy. Here you will find some of my technical musings. Securely email me using - PGP: 4CB8 91EB 0C0A A530 3BE9 6D76 B076 96F1 6135 0A1B