Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a somewhat old NAS hosting my music collection. It is not capable of running a DAAP media server so I have mounted the music folder on my Sheevaplug (a tiny headless server running Debian) which then runs the DAAP media server.

It works perfectly, but the problem is that the mounting of the samba share prevents the NAS from going into hibernation when there is no activity. If I unmount the share manually, the NAS will hibernate after some time.

Because of that I am looking after a way to automatically mount the network drive when needed (ie. accessed) and unmount it again after a period with inactivy.

I have tried inotifywait to monitor read access in the mount point, but unfortunately that does not catch reading from files not found which is what happens when the DAAP server tries to stream a music file in the empty folder.

Then I have googled more and have found autofs which seems to be able to do exactly what I need. But unfortunately, even after reading a guide like this, I still don't understand how to use it.

EDIT:

I was confused by the small differences between Debian and Gentoo. In Gentoo the config file is /etc/autofs/auto.misc whereas Debian uses /etc/auto.misc and so on.

Adjusting for those subtle differences, autofs works perfectly. It mounts the samba share when needed and unmouns it again after the timeout period given in auto.master

share|improve this question
2  
autofs seems to be what you're looking for, where did you stop in the guide? –  Stéphane Gimenez Jul 31 '11 at 1:18
    
It was very late when I asked my questions and apparently I didn't think clearly enough. Because I just tried again and it works perfectly! I think I was confused by the small differences between Debian and Gentoo, for example in Debian the config file is /etc/auto.misc and not /etc/autofs/auto.misc as in the guide. –  marlar Aug 1 '11 at 12:28
add comment

1 Answer

Using autofs is quite simple.

In the file /etc/auto.master you specify parts of the configuration. Each part has a directory specified into which are the configured mounts mounted.

For example in my configuration, I have:

/nfs /etc/auto.nfs

This means, whatever is configured in /etc/auto.nfs will be mounted into the /nfs directory.

Now in the separate configuration files, you directly specify the mounts.

Again in my configuration, I have:

storage -rw,soft,intr,rsize=8192,noatime,async 192.168.0.50:/storage

Meaning: create a subdirectory storage in /nfs that will be a nfs mount 192.168.0.50:/storage. The options are specified in the middle and they are the same, you would specify in /etc/fstab.

share|improve this answer
    
Don't you miss the -fstype parameter to specify that it is a nfs mount? –  marlar Aug 4 '11 at 9:26
    
@marlar Actually not. You don't need to specify filesystem type if it can be auto detected. –  Let_Me_Be Aug 4 '11 at 10:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.