2008-06-10

prevent (auto)mounting of usb devices

Dear Lazyweb,

any idea on how i can prevent the (auto)mounting of any usb stick or usb disk on linux (unless you are root) ?

edit: renaming the module seems to work...but it is not a very clean solution.

"mv usb-storage.ko usb-storage.disable"

6 comments:

Matt Casters said...

You can probably configure these things with udev. Read about it in an excellent Linux magazine article (Feb '08).
But even wiki has some content:

http://en.wikipedia.org/wiki/Udev

Philip said...

Yes - you can destroy this dangerous behaviour using udev. I don't know which prat decided that automounting filesystems on removable media would be a bright idea, but he should be slapped. Hard.

Madness.

Paul Cobbaut said...

thanks, i'm busy reading the udev manual!

paul

Jan Veldeman said...

You could also try:

gconftool-2 -s /apps/nautilus/preferences/media_automount --type boolean false

or gconf-editor if you're using gnome.

Matt Casters said...

philip, why would auto-mounting USB drives be a bad idea? On my Kubuntu system I get a nice question if I want to do this or not, just like I want. (including the "don't bug me again" option).

udev is pretty sweet actually. You can do things like fire off a script when you attach a drive: mount, backup, unmount, etc.

Wouter Verhelst said...

It's not the kernel which does this, it's userspace. Udev only shouts to some other software "hey, we have a new device", which that other software then promptly acts upon.

If you don't want that, all you need to do is to kick that other software out. In the case of gnome, that's gnome-volume-manager; I don't know what KDE subsystem does the same on their end.

You could, of course, refrain from using such "desktop environments" entirely. I've been using icewm since like forever, and it works perfectly...