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


Hotplug an external usb hard drive

Posted on 2008-11-04
Medium Priority
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


Question by:onlinede
  • 3
  • 2

Accepted Solution

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.

Author Comment

ID: 22874398

there is no /etc/auto.removable


Expert Comment

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)

Author Comment

ID: 22874889

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?


Expert Comment

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:

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

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

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

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