user1654132
user1654132

Reputation: 31

How can I prevent all USB mass storages from mounting?

I want to prevent every kind of USB mass storage from mounting using udev rules.

Already I can detect all of 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 prevent them from mounting?

I know I have to set the authorized file of its relevant USB device to zero! But how can I find the USB device path? The $DEVPATH gives me the path of storage device block for example sdb1!

I have an application which should give permission to some of USB mass storage devices. So the used method for blocking the USB mass storage devices should not be very static!

Upvotes: 3

Views: 6285

Answers (2)

KevinM
KevinM

Reputation: 577

The following rule prevents all except the first partition from being auto-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 USB disks with multiple partitions, I only want to automount the first one. I manually mount the others, if I want them.

You should be able to substitute 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 auto-mounting, which you can then manually manage.

I have only tested this on Ubuntu 10.10

Upvotes: 3

jam
jam

Reputation: 3688

The easiest way to do this is to blacklist the usb-storage kernel module. This will only work if it has been compiled as a module however, rather than directly into the kernel. You can check with modprobe -n usb-storage.ko, or by looking for it in /lib/modules/$(uname -r)/kernel/drivers/usb/storage/

If it's compiled as a module, you can black list it by adding an entry to /etc/modprobe.d/blacklist(.conf) For Debian, see this guide

Upvotes: 1

Related Questions