4

Goal

  • I have a USB drive -- let's say the drive's ID is /dev/disk/by-id/thediskid
  • I would like to mount the drive -- by ID -- to a folder (let's call it /MOUNT_FOLDER)

Question

  • What is the best way to do this using autofs?

Current Attempt

/etc/auto.master:

+auto.master
/localam auto.linux
/[another mount]  [auto.othermount] --timeout=5 -- ghost
/MOUNT_FOLDER auto.ext-usb --timeout=5
/ -

/etc/auto.ext-usb:

/MOUNT_FOLDER /dev/disk/by-id/thediskid

I know I'm missing something but I can't seem to get a good lead on what the proper syntax is.

New to Linux; appreciate a pass if I'm overlooking something simple. Thanks!

1
  • Is this the only usb-drive you ever want to mount, or do you want to do something more generic?
    – Nils
    Jul 3, 2012 at 19:35

2 Answers 2

4
  1. add to /etc/auto.master

    /var/autofs/removable   /etc/auto.removable     --timeout=2
    
  2. add to /etc/auto.removable

    theDiskLabel         -fstype=ext4,rw,gid=1000,umask=002       :/dev/disk/by-uuid/thediskid
    
  3. restart autofs service

    sudo service autofs restart
    
  4. Access your directory, thats it!

    cd /var/autofs/removable/theDiskLabel
    
1

In your constellation /MOUNT_FOLDER is the base directory where subdirectories will be mounted by the indirect mount-map auto.ext-usb.

See man 5 autofs for further details.

Example:

usbdisk -fstype=vfat,uid=yourworkingusername :/dev/disk/by-id/thediskid

If you cd /MOUNT_FOLDER/usbdisk your usbdisk will be mounted there (I assume it is vfat formatted).

You can use /etc/fstab instead - but then you will to have to mount "by hand".

The entry in /etc/fstab looks like this:

/dev/disk/by-id/thediskid /MOUNT_FOLDER vfat defaults,user,noauto 0 0

After that you can mount the USB-Disk as ordinary user with mount /MOUNT_FOLDER.

5
  • Nils, not sure I follow you completely, though what you're saying sounds possible. In this case, how would you recommend accomplishing mounting the contents of the USB disk into the /MOUNT_FOLDER location? Also, am I using the wrong tool in autofs (is it recommended that I just use /etc/fstab instead, for example?) Jul 3, 2012 at 20:23
  • @goober if you want to use the automounter-mechanism using indirect maps is the "recommended" way. If you really want to use the main directory as mountpoint you can define your entry directly in the direct map auto.master - but changes in auto.master will only be activated by restarting autofs (as opposed to indirect maps). I'll update my answer about /etc/fstab
    – Nils
    Jul 4, 2012 at 11:11
  • I'm not attempting to argue your solution that it's the recommended way. My issue is that I'm getting the syntax wrong. In order to mount a usb drive by id using autofs, could you show me the proper way to configure the files given the information I've provided initially? I understand the concept generally when it's explained but implementing your suggestions seems to be going wrong somewhere. Jul 4, 2012 at 19:44
  • @goober I tried this myselv and updated my answer.
    – Nils
    Jul 4, 2012 at 20:47
  • @SeanKilleen The problem with indirect maps is that you will have to use a subdirectory. There are two ways around this: a) use a direct map b) use a soft-link /MOUNT_FOLDER that points to /MOUNT_FOLDER/usbdisk.
    – Nils
    Apr 1, 2014 at 12:18

You must log in to answer this question.

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