50

I know how to use /etc/fstab to automatically mount devices on boot or when doing sudo mount -a, which works perfectly fine. For example, here is my current line for my device

UUID=B864-497A /media/usbstick vfat defaults,users,noatime,nodiratime,umask=000 0 0

How do I achieve automatic mounting when this USB device with known UUID is plugged in while the system is already running, so that I don't have to run sudo mount -a after it is plugged in?

Additional info: I'm working on an up-to-date console-only Debian wheezy linux.

2
  • By How do I achieve automatic mounting when this USB device with known UUID is plugged in do you mean you only want to automount this specific USB drive? Or does it matter? I've gone ahead an posted a more generic answer that will automatically mount most USB storage devices, but I am not entirely sure this is what you want.
    – Seth
    Commented Jun 6, 2014 at 18:58
  • @Seth I have a specific USB stick which I use for quickly transferring files between the Debian device and other devices (sometimes granting network access for these devices is to much work if you only want to transfer a tiny file quickly).
    – Foo Bar
    Commented Jun 7, 2014 at 9:36

3 Answers 3

45

I use the usbmount package to automount USB drives on my Ubuntu server install. I have confirmed that the package exists for Wheezy too. Recently also added for Jessie.

sudo apt-get install usbmount  

usbmount will automount hfsplus, vfat, and ext (2, 3, and 4) file systems. You can configure it to mount more/different file systems in /etc/usbmount/usbmount.conf. By default it mounts these file systems with the sync,noexec,nodev,noatime,nodiratime options, however this can also be changed in the aforementioned configuration file.

usbmount also supports custom mount options for different file system types and custom mountpoints.

10
  • 1
    after installing this it did start auto-mounting drives again but I don't seem to have access rights as my user, making it needlessly painful to copy files. Would you expect I'd have to edit the config mentioned to achieve this or is it likely to be something else? My machine has just been crippled by some updates - i had to shutdown on the command line previously but now it wont work with my usb... also just lost my graphics drivers so my desktop looks like windows 3.1 or something! :( not been a good week for my computer
    – JonnyRaa
    Commented Oct 27, 2014 at 19:23
  • 1
    @IvanBorisenko On Debian based systems it will usually mount to /media/user/.
    – Seth
    Commented Mar 27, 2016 at 14:48
  • 1
    Is there a way to force usbmount to use volume lables as mount points rather than usb1, usb2, usb3...?
    – ccpizza
    Commented Nov 6, 2017 at 10:23
  • 1
    @Rolf Still seems to work fine :)
    – Seth
    Commented Jan 29, 2018 at 18:04
  • 5
    This package does not appear to exist for Stretch. Is their a newer alternative? Commented May 21, 2018 at 22:52
8

You could use gnome-volume-manager to automount. You can reconfigure it a bit using gnome-volume-properties.

screenshot

            ss of gnome-volume-properties

If you're in runlevel 3 I don't believe this is an option. You could however coax udev into doing the mounting for you in a similar fashion.

1. add a file automount.rules in /etc/udev/rules.d

2. add the following lines to automount.rules

automount.rules

# automounting usb flash drives
# umask is used to allow every user to write on the stick
# we use --sync in order to enable physical removing of mounted memory sticks -- this is OK for fat-based sticks
# I don't automount sda since in my system this is the internal hard drive
# depending on your hardware config, usb sticks might be other devices than sdb*
ACTION=="add",KERNEL=="sdb*", RUN+="/usr/bin/pmount --sync --umask 000 %k"
ACTION=="remove", KERNEL=="sdb*", RUN+="/usr/bin/pumount %k"
ACTION=="add",KERNEL=="sdc*", RUN+="/usr/bin/pmount --sync --umask 000 %k"
ACTION=="remove", KERNEL=="sdc*", RUN+="/usr/bin/pumount %k"

3. reload the udev rules:

udevadm control --reload-rules

gnome-disk-utility

I found the new name of gnome-volume-manager BTW. It's called gnome-disk-utility in CentOS6, I just confirmed that that RPM is in the default yum repos.

This U&L Q lead me to it: USB storage devices aren't automatically mounted when inserted on a fresh install of Debian 6.0.

Do the following command to find it:

$ yum search gnome-disk-utility*
gnome-disk-utility-devel.i686 : Development files for gnome-disk-utility-libs
gnome-disk-utility-devel.x86_64 : Development files for gnome-disk-utility-libs
gnome-disk-utility-ui-devel.i686 : Development files for gnome-disk-utility-ui-libs
gnome-disk-utility-ui-devel.x86_64 : Development files for gnome-disk-utility-ui-libs
gnome-disk-utility.x86_64 : Disk management application
gnome-disk-utility-libs.i686 : Shared libraries used by Palimpsest
gnome-disk-utility-libs.x86_64 : Shared libraries used by Palimpsest
gnome-disk-utility-ui-libs.i686 : Shared libraries used by Palimpsest
gnome-disk-utility-ui-libs.x86_64 : Shared libraries used by Palimpsest

References

3

Because I couldn't find the above GUI tool from my repository, I instead found this,

enter image description here

which at least shows when something is plugged in and provides an easy and fairly smart way to mount it by selecting it and clicking the play button.

enter image description here

1
  • But unfortunately nothing whatsoever to do with the Q - which is to mount when you plug in an external drive. It's surprising just how hard this is to find a solution which doesn't involve root editing udev rules - quite crazy in fact.
    – RichieHH
    Commented Jan 29, 2023 at 9:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .