# Automount (autofs) External Hard Drive (USB)

## DancesWithWords

Hi,

I set up my system to do backups including auto-mounting of my external USB 

hard drive. I followed these instructions https://workaround.org/rsnapshot-and-usb-drives/

everything worked fine until I unplugged my external hard drive.  Now it will 

no longer auto-mount.

My auto.usbdrive file has:

usbdrive -fstype=auto    UUID=234390d3-1b4c-4b03-8476-XXXXXXXXXXXX

My auto.master file has:

/var/autofs/removable /etc/auto.usbdrive –timeout=2,sync,nodev,nosuid

When I look at /var/log/messages I get:

Apr 20 19:24:38 bbox automount[8038]: �

Apr 20 19:24:38 bbox automount[8038]: �

Apr 20 19:24:38 bbox automount[8038]: �

Now remember  this did work.  I can mount this drive manually but that does 

not suit my purposes.

Can you add some insight or suggestions.

=======

DWWLast edited by DancesWithWords on Sun Apr 30, 2017 9:40 pm; edited 1 time in total

----------

## cboldt

I ended up using uam for automatically mounting usb devices.  Sometimes it gets stuck if I have failed to umount a device before turning it off or unplugging it.  autofs might similarly get stuck.

I run autofs too, but don't use that for mounting usb drives.

----------

## DancesWithWords

 *cboldt wrote:*   

> I ended up using uam for automatically mounting usb devices.  Sometimes it gets stuck if I have failed to umount a device before turning it off or unplugging it.  autofs might similarly get stuck.
> 
> I run autofs too, but don't use that for mounting usb drives.

 

Thanks for the reply.  Hopefully someone out there has a solution.

=====

DWW

----------

## Ant P.

There's a similar bug with sshfs mounts not working (and spewing binary to the log) when ld.gold is in use. Does your `ld -v` mention gold by any chance?

----------

## DancesWithWords

 *Ant P. wrote:*   

> There's a similar bug with sshfs mounts not working (and spewing binary to the log) when ld.gold is in use. Does your `ld -v` mention gold by any chance?

 

No. Nothing like that.

======

DWW

----------

## Logicien

Because the Linux kernel can change the device file name of a Usb hard drive on unplug and plugin again, I would ask Udev to do a symbolic link to the drive according to the ID Vendor and ID Product of the Usb drive. Than you can use the symbolic link with Autofs and not it's Linux device file name.

----------

## DancesWithWords

 *Logicien wrote:*   

> Because the Linux kernel can change the device file name of a Usb hard drive on unplug and plugin again, I would ask Udev to do a symbolic link to the drive according to the ID Vendor and ID Product of the Usb drive. Than you can use the symbolic link with Autofs and not it's Linux device file name.

 

I've seen how to do that some where...  Can you give me an example or point me to one?

Thanks for this.

====

DWW

----------

## apiaio

```
cat /etc/udev/rules.d/40-usbkey.rules

ACTION=="add", KERNEL=="sdc*", SUBSYSTEM=="block", RUN+="/bin/mount /dev/%k"

ACTION=="remove", KERNEL=="sdc*", SUBSYSTEM=="block", RUN+="/bin/umount /dev/%k"

```

works for me. I dont use  autofs

In the part  *Quote:*   

>  KERNEL=="sdc*"

  you will have to use device which is populated in /dev directory during hotplug.

----------

## cboldt

Another "plug" for uam - it is nothing more than some scripts that interact with udev actions in a similar fashion to the simple example shared above.  A few differences.  uam.conf allows mounting to be done by kernel device name (and there is no need to know, in advance, that e.g., 'sdc' will be the device basename), or filesystem label, or UUID, or device serial number.  It also allows ignoring certain devices, ostensibly in case they are handled by a different mechanism.

Granted, uam is not as "simple" as the example, but like the example, is "hooked" to only udev.

----------

## apiaio

You are right that is "hooked" to only udev, but I have been using it for some seven years on two gentoo PC's and never had got stuck as

mentioned above with autofs or uam. I admit that exists better solution.

Even thought it is only hint for DancesWithWords.

----------

## Logicien

This is an example to create a symbolic link of a Usb drive to it's Linux device file name with the Udev file /etc/udev/rules.d/00-persistent-usb-names.rules

```
KERNEL=="sd*", ATTRS{serial}=="xxxxxxxxxxxxxxxxxxxxxxxx",                 ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="xxxx" SYMLINK+="xxx%n"
```

You can get the serial number, the 4 last hexadecimal digits of the idVendor and the idProduct of your Usb drive using

```
lsusb -vvv | less
```

The name of the symbolic link is at your taste. The drive and the partitions if some will appear in /dev after

```
udevadm trigger
```

or after reboot.

----------

## DancesWithWords

UPDATE

So interesting fact. Even though I can not manually get my external USB hard drive to mount via autofs.  I've learnt that rsnapshot can mount this drive all on its own using autofs.

How this is working I don't know, but it is a win for me.    :Laughing: 

If anyone wants to explain this behaviour please be my guest.

====

DWW

----------

