LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can I automount my drives in Debian? (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-automount-my-drives-in-debian-4175436306/)

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?

Cheers,

markush 11-08-2012 04:51 PM

Hi,

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
Code:

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

And I have a little script /usr/local/bin/mount-usb.sh which mounts the devices
Code:

#!/bin/bash

# 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
fi
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.

Markus

frankbell 11-08-2012 08:33 PM

I normally put them in fstab.

This is the best explanation I've found on fstab: http://www.tuxfiles.org/linuxhelp/fstab.html

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: http://www.cyberciti.biz/faq/linux-f...-update-fstab/


All times are GMT -5. The time now is 12:04 AM.