LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices



Reply
 
Search this Thread
Old 01-29-2009, 06:15 AM   #1
tl3462
LQ Newbie
 
Registered: Jan 2009
Posts: 8

Rep: Reputation: 0
How to poll for USB devices available to mount (with auto-mounting disabled)?


I don't want any old USB thumb drive mounting to my system therefore I'm trying to create a script that controls the mounting of USB devices and the permissions given to them. These permissions depend on other variables (eg. am I connected to a network?) therefore I don't think I can just add a device to a list of approved devices for mounting and block everything else. I need some dynamic way of doing it.

I've disabled the auto-mounting of removable/hot-pluggable drives, I now need some way of polling for the insertion of a USB device. Any ideas what I need to poll?

Tom
 
Old 01-29-2009, 06:26 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Whether a local user or remote user can mount a usb drive is usually handled by PolicyKit.

Since you disabled automounting, you might consider manually mounting usb drives instead with entries in /etc/fstab determining the permissions and ownership. The first field in /etc/fstab can use UUID=<filesystem_uid> instead of the device node. This is recommended anyway for removable drives because you can't depend on which device node it will be assigned to.

Also, for removable drives, be sure to use the "noauto" option.

For fat32 filesystems, which is the most common for pendrives, you determine the permissions and ownership in the mount command. So you can have an /etc/fstab entry for each pendrive you own and use different permissions or ownership. Using the "user" or "users" option, you can even mount the pendrive as a normal user. The permissions you use could mean that only you have permission to enter the mounted directory.
 
Old 01-29-2009, 06:41 AM   #3
tl3462
LQ Newbie
 
Registered: Jan 2009
Posts: 8

Original Poster
Rep: Reputation: 0
I'd really like to be able to run the polling and mounting automatically using a daemon. I think that fdisk -l will give me a list of all devices connected (but not necessarily mounted) so I could run that every few seconds from a script to check if anything has been inserted into a USB socket, but this seems a bit clumsy.

I suppose I could dig through the source for fdisk and find out what it uses but I thought there might perhaps be an easier way?

Last edited by tl3462; 01-29-2009 at 07:19 AM.
 
Old 01-29-2009, 07:33 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
If you don't want to use HAL, look at "ivman".
 
Old 01-29-2009, 08:19 AM   #5
Didier Spaier
Senior Member
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware{,64}-{14.1,current} on a Lenovo Thinkpad W520
Posts: 4,681

Rep: Reputation: 1240Reputation: 1240Reputation: 1240Reputation: 1240Reputation: 1240Reputation: 1240Reputation: 1240Reputation: 1240Reputation: 1240
Poll for output of 'lsusb' or the file /proc/bus/usb/devices

Last edited by Didier Spaier; 01-29-2009 at 08:22 AM.
 
Old 01-29-2009, 09:49 AM   #6
tl3462
LQ Newbie
 
Registered: Jan 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Brilliant, ivman looks to be exactly what I was after.

I tried working with HAL - I found a python script that supposedly interacts with HAL 0.4 at http://people.redhat.com/davidz/hal-...c.html#AEN2152 but I have 0.5 I think so this wasn't giving me any joy.

ivman seems to be controlled by a configuration file so this might possibly be the answer but I haven't dug around for any documentation yet

... if not lsusb will do as my clumsy backup option!

Thank you both!
 
  


Reply

Tags
drive, mount, poll, usb


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to disable auto-mounting of USB Devices on Slackware 12.2? sertmusluman Slackware 31 12-20-2008 04:57 AM
(auto)mounting devices in slackware w/ (or w/o) KDE crisostomo_enrico Slackware 1 08-05-2006 12:59 AM
how can i configure FreeBSD to auto mount USB devices? asilentmurmur *BSD 2 04-24-2006 02:24 PM
Disable Auto-mounting of devices in .... WINDOWS? opioid General 4 04-20-2006 02:35 PM
Auto mounting of USB devices leecming Linux - Newbie 6 08-05-2004 02:42 PM


All times are GMT -5. The time now is 10:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration