-   Linux - Newbie (
-   -   How can I automount my drives in Debian? (

alarazr 11-08-2012 03:18 PM

How can I automount my drives in Debian?
Hey all.

If I try to access my USB drives, Windows partition or external HDD, I get a 'Not Authorized' message in pcmanfm. I can sudo mount /dev/sda2 /media/Windows and it works fine, but how can I make it do this automatically?


markush 11-08-2012 04:51 PM


there are at least two ways to achieve this. The first would be to include the drives into your /etc/fstab file. Read the manpage for fstab, you will find the necessary information there (I've never used this feature and cannot help here).

The second way would be to use udev-rules. I have an udev-rule for my USB-memory-sticks

# file /etc/udev/rules.d/52-usb-memory.rules
SUBSYSTEMS=="usb", KERNEL=="sd?1", ACTION=="add", RUN+="/usr/local/bin/"

And I have a little script /usr/local/bin/ which mounts the devices


# USB-Stick mounten
sleep 5
device=`dmesg | grep -e sd.: | tail -n 1 | sed -n 's/.*sd.:\s\+\?\(.*\)/\1/i p'`
name=`dmesg | grep -i product: | tail -n 1 | sed -n 's/.*product:\s\+\(.*\)/\1/i p' | sed -n 's/\ /_/g p'`

if [ ! -d /media/$name ]; then
    mkdir /media/$name
mount /dev/$device /media/$name

This solution doesn't set any permissions, root is the owner of the devices and the normal user has only read-permission. But one can easily change this with the udev-rule.


frankbell 11-08-2012 08:33 PM

I normally put them in fstab.

This is the best explanation I've found on fstab:

It's easier if you use the UUID, which I think post-dates that article. That ensures that they always mount to the same mountpoint.

Here's a good explanation of how to use the UUID to mount a device in fstab:

All times are GMT -5. The time now is 05:28 AM.