# [Solved] Automount usb external drive

## dpetka2001

hello there...i would like to know if there is a script or a tool that can automount any usb external drive i plug into my computer thus saving me the trouble to do it manually...is there a way?? thanks in advance...i use KDE...Last edited by dpetka2001 on Wed May 14, 2008 9:27 pm; edited 1 time in total

----------

## vaxbrat

Put HAL in your USE flags and emerge hald along with whatever else an "emerge -uD --newuse world" pulls in.  I believe dbus will get pulled in if it already doesn't.  Then put dbus and hald in your default runlevel with rc-update.  In your /etc/fstab modify your removable entries such as /mnt/cdrom and whatever mountpoint(s) you use for external usb drives to use a filesystem of "auto" and "users" added to the option columns to allow unprivileged mounts.

I use KDE, so you mileage may vary.  However a hal aware KDE will sense media change, drive or thumbdrive getting attached and will popup an "open in new window" prompt.  If you let it, media will mount and then you can play.  Close the konqueror tab, get out of attached drive directories and then do a right button click on the desktop icon for the mounted usb device to select "safely remove" when you are done.

----------

## dpetka2001

thank you for your response...i will try what you suggested and report back if i have any problems...

----------

## dpetka2001

one more question...how would i modify /etc/fstab in order to make the changes you suggested?? i don't know which device my external usb drive will use in order to mount...i have 2 usb devices...the printer and the usb external drive...when they are on they usually are /dev/sda1 and /dev/sda2 but not in a specific order...it is done randomly...how am i supposed to do what you suggest??

----------

## vaxbrat

Actually if you assume that your printer is kept hooked in constantly, udev and hotplug will get it at boot and the device node for it should stay put.  I don't have any problems calling out the thumb drive as /dev/sdc1 as that's pretty much the only usb device I plug in and out after boot.

You might also look into using the /dev/disk directories as an alternative for the device name in the fstab.  When I plug my thumb drive, the hotplug package (you do run that right?) sets up the following entries for it:

```
ls /dev/disk/by-id

      (other devices not shown)

usb-090c_1000_AA04012700014916-0:0

usb-090c_1000_AA04012700014916-0:0-part1
```

and

```
ls /dev/disk/by-path

      (other devices not shown)

pci-0000:00:10.4-usb-0:5:1.0-scsi-0:0:0:0

pci-0000:00:10.4-usb-0:5:1.0-scsi-0:0:0:0-part1

```

When I do the safe remove operation, these by-id and by-path entries are removed.  (note, you would want to use the -part1 entries to mount your filesystem.

People doing RAID volumes on redundant paths will quickly find it useful to stick a volume label on their filesystems and use the by-label settings to mount their stuff without worrying about failovers or reconfiguring moving device nodes around.

----------

## dpetka2001

i can also see a /dev/disk/by-label...how could i use this in fstab to mount the external usb disk drive...for example in my situation there is a /dev/disk/by-label/Removable_HDD which refers to the external usb disk drive...should the entry in fstab look something like this "/dev/disk/by-label/Removable_HDD               /mnt/usb        auto            noatime,auto,users      0 0" ??

----------

## Sachankara

If you have compiled your system with HAL and you use Nautilus, you just have to emerge gnome-volume-manager and add your user to the plugdev group. That's it. No need to edit /etc/fstab.

If you use Thunar, emerge thunar-volman instead (works similar to gnome-volume-manager). If you want something that works without being dependant on a particular file browser, take a look at ivman.

http://gentoo-wiki.com/HOWTO_gnome-volume-manager

http://gentoo-wiki.com/HOWTO_ivman

----------

## vaxbrat

That looks to be a good entry for the by-label alternative.  I didn't steer you that way since I assumed that your filesystem was unlabeled.  A usb thumbdrive is usually unlabeled vfat for example.

As for the other guy's comment about Nautilus,  konqueror can handle fstab-less entries via media management and HAL.  However it's harder to work with these guys elsewhere (ie a command shell) without one getting automounted via fstab.

----------

## dpetka2001

i added my account to plugdev group,logged out/in again and when i plugged my external usb drive into my computer it recognized and mounted it but when trying to open it with konqueror it pops up the following error

```
"Could not enter folder /media/disk"
```

also from what i can see as far as permissions are concerned take a look at the following

```
root@ ~ > ls -al /media/

total 9

drwxr-xr-x 3 root root 112 2007-06-14 20:22 .

drwxrwxrwx 21 root root 616 2007-06-11 18:40 ..

dr-x------ 1 root root 8192 2007-06-09 17:05 disk

-rw-r--r-- 1 root root 0 2007-06-14 06:07 .keep_sys-apps_hal-0

root@ ~ > mount | grep dev/sda

/dev/sda1 on /media/disk type ntfs (rw,noexec,nosuid,nodev,sync)
```

how could i overcome the problem i mention above so that my user should be able to have access to the mounted media?? thanks...

----------

## dpetka2001

well i tried to solve it by making my own entry in fstab...i tried to do as you suggested using /dev/disk/by-id but nothing happened...when i try /dev/sda1 instead of /dev/disk/by-id it works all right using the same parameters...so how should i implement your suggestion using /dev/disk/by-id in fstab?? could you show me your fstab entry to make comparison?? thanks in advance...

Edit: to be more precise the error it gives me is "Permission denied" and it doesn't even mount the disk drive...but when using the /dev/sda1 it mounts it just well...what kind of permissions does my user need in order to be able to mount devices using /dev/disk/by-uuid (or something else) ??

----------

## vaxbrat

As I mentioned, I get by using the sd name as well:

```
/dev/sdc1       /mnt/thumb      auto    users           0 0

```

However I just changed it to look like:

```

/dev/disk/by-id/usb-090c_1000_AA04012700014916-0:0-part1   /mnt/thumb   auto   users      0 0
```

And it mounted without any problems.  Now when I df this mount, I still see the /dev/sdc1 since the df command follows that softlink to the eventual physical device name:

```
 $ df

Filesystem           1K-blocks      Used Available Use% Mounted on

/dev/sdc1              4055276   3892460    162816  96% /mnt/thumb

```

Maybe you forgot to put "users" in your options field?  If you don't allow user mounts, you would get a permission error.  Remember I mentioned to use the "part1" entry and not the first one since you want the partition and not the entire disk for the filesystem.  Also look at the group setting of your physical device node.  Mine looks like:

```

ls -l /dev/sdc1

brw-rw---- 1 root disk 8, 33 Jun 16 14:19 /dev/sdc1

```

That should be a default setup from udev rules, but maybe you have something else.  The third possibility is the kio setup in kde ie:

```
system:/media/sdc1
```

However I don't remember having to do anything in the kde control center to open up permissions for mortal users.

----------

## dpetka2001

my entry looks like this

```
/dev/disk/by-uuid/C00CD0FD0CD0F000              /mnt/usb        ntfs            ro,users,gid=users,umask=0002,nls=utf8  0 0
```

and it doesn't get mounted...it says "permission denied"...i don't know why...do you see some kind of error in my entry?? do you think it has to do with the permissions my user has on the mountpoint where i try to mount it?? but the following indicates that everything should be fine(in my humble opinion)

```
root@ ~ > ls -l /mnt/

total 20

drwxrwxrwx 2 jrn23 users    72 2005-07-26 20:11 cdrom

drwxr-xr-x 5 jrn23 users  4096 2007-06-09 17:14 data

drwxr-xr-x 2 root  root     48 2006-03-28 17:50 external

drwx------ 2 root  root     72 2005-07-26 20:11 floppy

drwxrwxrwx 6 root  root  16384 1970-01-01 02:00 share

drwxr-xr-x 2 jrn23 users    80 2006-02-07 21:50 store

drwxrwxrwx 2 jrn23 users    48 2005-12-15 02:45 usb

drwxr-xr-x 3 root  root     72 2005-12-13 02:14 Windows
```

here is also an image of my /etc/fstab...as you can see /dev/sda1 and /dev/disk/by-uuid have the same options but still i get "permissions denied" when trying to mount it using /dev/disk/by-uuid...can you see the red square where the "-"is in by-uuid?? does it mean something is wrong?? 

```
http://img516.imageshack.us/my.php?image=top10ro7.png
```

----------

## vaxbrat

If you are mounting that ntfs as readonly, not sure why you are using a umask in your options.  That only comes into play for creating new files.

When you attempt the mount as normal user, open another console window and do a "tail -f /var/log/messages".  You should see messages from hotplug as you plug the drive in and may see whatever error you are getting.

You didn't show the permissions of the /dev/sd<whatever> that your by-uuid entry was pointing to.  It may still be a permissions thing on the physical device from udev.

----------

## dpetka2001

i don't have a /var/log/messages...this is what i have in /var/log

```
root@ ~ > ls /var/log/

amuled.log      dmesg       kernel                pwdfail           xdm.log

apcupsd.events  emerge.log  lastlog               samba             Xorg.0.log

btmp            everything  mail                  sandbox           Xorg.0.log.old

clamav          faillog     mysql                 scrollkeeper.log  Xorg.8.log

critical        freepopsd   mythtv                sshd

crond           iptraf      news                  telnet

cups            kdm.log     nvidia-installer.log  wtmp
```

as for the umask thing i did it because my user couldn't access the mount point...well my usb drive is /dev/sda1 and its permissions are 

```
root@ ~ > ls -l /dev/sda1

brw-rw---- 1 root disk 8, 1 2007-06-17 11:56 /dev/sda1
```

----------

## vaxbrat

If you want one you can emerge syslog-ng.  Otherwise you might want to tail -f the /var/log/dmesg to see if there's anything happening in there when you plug in.

----------

