Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Hotplug an external usb hard drive

Posted on 2008-11-04
8
Medium Priority
?
1,172 Views
Last Modified: 2013-12-06
hi all,

i'm wanting to hotplug an external usb device on my debian box.
I can mount the drive using: mount /dev/sdb1 /mnt/usb
the question is how do i hotplug this device?

thanx in advance

mk

0
Comment
Question by:onlinede
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
bishillo earned 2000 total points
ID: 22874332
If you are using as desktop machine usually is enough to add the user to the plugdev group. That will enable the user to mount all usb disks connected. Gnome and KDE automatize this, and enable umount them as well very easily.

If it's for a server, you should use autofs instead:

apt-get install autofs

In the config file: /etc/auto.master add:
/mnt       /etc/auto.removable      --timeout=60


In the config file /etc/auto.removable add:
usb         -fstype=vfat,rw,gid=100,umask=002,[other options you want]       :/dev/sdb1

The you just do:
/etc/init.d/autofs restart

And whenever the sdb1 is connected, /mnt/usb will work. After 60 seconds of inactivity, it will umount automatically, so it's safe to remove it. (if you try to list it again, it will be mounted again). Tune the timeout to match your needs.

For memory cards the timeout can be adjusted to a much lower timeout, so they can be extracted anytime safely. Add a line:
/mnt/cards       /etc/auto_cards.removable      --timeout=2

and in /etc/auto_cards.removable configure the devices that should be considered cards.
0
 

Author Comment

by:onlinede
ID: 22874398
hi,

there is no /etc/auto.removable

?
0
 
LVL 3

Expert Comment

by:bishillo
ID: 22874702
Yeah, you could name it as you want, so you should create the file.

In /etc/auto.master you set which file will be loaded, in this example I used /etc/auto.removable, but if you prefer you could use other name (like the /etc/auto_cards.removable of the second example)
0
 

Author Comment

by:onlinede
ID: 22874889
hi,

shouldn't this: /mnt     /etc/auto.removable      --timeout=60 be /mnt/usb     /etc/auto.removable     --timeout=60

also [other options you want]?

usb         -fstype=vfat,rw,gid=100,umask=002,[other options you want]       :/dev/sdb1

I'm lost with this section? what if I remove it so it reads:

usb         -fstype=vfat,rw,gid=100,umask=002,       :/dev/sdb1

will this work?

Mk
0
 
LVL 3

Expert Comment

by:bishillo
ID: 22875041
no, /mnt is the base directory. Later on auto.removable yo set usb, disk, and other labels, that will be mounted on /mnt/<label>

The other options of course you should remove it if your don't need other options. :) Perhaps it's interesting to add sync, that avoids write cache, that can cause data loss on removable media (if you remove the media before the cache gets flushed to disk).

To resume:

/etc/auto.master:
/mnt     /etc/auto.removable      --timeout=60

/etc/auto.removable:
usb         -fstype=vfat,rw,gid=100,umask=002,sync       :/dev/sdb1

(without the semicolon if you are not adding more options)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question