I have a small home server running Ubuntu 12.04 with an external hard drive attached to it. The external hard drive is mounted with autofs. Autofs basically unmounts a hard drive if it isn't used for a specified amount of time and automatically mount them back if some one tries to read / write from the mount folder.

Autofs and Samba working correctly my only problem now is:

  • The samba shares are located within the external hard drive, I only want to share sub-folders. E.g.: the music folder on the hard drive.
  • Autofs mount the harddrive to /automnt/external. If you access the folder the drive will be mounted and you can access the music folder (/automnt/external/music)
  • If the drive is unmounted and some one tries to access it samba apparently just tries to access the music sub-folder which is not yet accessible.

My question: Is it possible to tell samba before allowing access one of the shares to run a little script (ls /automnt/extern would do) to make sure the drive is mounted?

  • Doesn't make sense to me. It is impossible (for samba and anything else) to access /automnt/external/music without accessing /automnt/external first. I would look for the solution in the autofs area. What happens if you export /automnt/external and the external drive is not connected when Samba starts but connected later and then an access is tried? – Hauke Laging Feb 22 '13 at 14:08
  • @HaukeLaging it works if I share the whole drive, so yes, autofs does not seem like the perfect solution anymore and could be replaced with something handling the job better. This question was out of curiosity and because it would be very simple to add a line in the smb.conf and write a bash one-liner. – TheHippo Feb 22 '13 at 14:12
  • I also have this problem, however my setup is much more complex. I also would like to able tu run a script when someone connects to a share and make samba wait until the script finished. – TCB13 Feb 1 '16 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.