Linux – How do I prevent all USB mass storage devices from being installed?

How do I prevent all USB mass storage devices from being installed?… here is a solution to the problem.

How do I prevent all USB mass storage devices from being installed?

I want to use udev to block mount rules for various USB mass storage devices.

I can already detect all USB mass storage devices connected to my system using the following rule:

SUBSYSTEMS=="scsi", SUBSYSTEM=="block" KERNEL=="sd[b-h]1"

But how can I stop them from mounting?

I

know I have to set the authorization file for my associated USB device to zero! But how to find the USB device path? $DEVPATH gives me the path to the storage device block, e.g. sdb1!

I have an app that should allow certain USB mass storage devices. Therefore, the method used to block USB mass storage devices should not be very static!

Solution

The following rule prevents all but the first partition from being automatically mounted:

# Rule: Only mount first partition found on /dev/sd* (USB) devices.
ACTION=="add|change", SUBSYSTEM=="block", KERNEL=="sd*[2-9]", ENV{UDISKS_PRESENTATION_NOPOLICY}="1"

Reason: In a USB stick with multiple partitions, I only want to mount the first one automatically. I’ll install the others manually if needed.

You should be able to replace the partition matcher with KERNEL==”sd*” to get:

# Rule: Do not automount any partitions found on /dev/sd* (USB) devices.
ACTION=="add|change", SUBSYSTEM=="block", KERNEL=="sd*", ENV{UDISKS_PRESENTATION_NOPOLICY}="1"

This prevents automatic installation, which you can then manage manually.

I only tested it on Ubuntu 10.10

Related Problems and Solutions