LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 07-23-2008, 11:55 PM   #1
srikanthnv
LQ Newbie
 
Registered: Jul 2008
Posts: 12

Rep: Reputation: 0
Automount a directory when accessed via NFS


Hey all,

I have a bunch of directories on a central server that are accessible via NFS (they're exported from /etc/exports). Some of them are files that are currently permanently mounted with a "mount -o loop file /mnt/mountpoint".

Is there any way to configure the system such that it automatically mounts the file when it is accessed via NFS? i.e. when a user on PC-A tries to access <server>:/mnt/mountpoint, the file should get mounted. When he's done using it (or if he doesn't use it for a long time) it should get unmounted.

Any advice/pointers on how this can be done, or if it can be done in some other way will be great!

(I know automount can be configured to do this on a direct access, but I'm not sure if it can be used when the directory is accessed through NFS. Can it?)
 
Old 07-25-2008, 04:00 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
Of course you don't mount files, you mount block devices, so I assume you mean you want to mount disk images stored on an nfs-shared filesystem? Do you want the nfs share to be always mounted and only mount the loopback images when accessed? Or do you want to have nfs+image mounted when accessed?

In any case, autofs can probably do the job. With it, you simply associate a mount command with a certain directory, and whenever someone tries to access it autofs will automatically run the mount, then time out and unmount after a user-defined number of seconds of inactivity.

Here's a page detailing how to configure autofs, including how to mount network shares and scripting more complicated actions. I can assume it's possible to configure it to do what you want, but you might have to experiment if it's really complicated.

I should note that I had one problem back when I was using autofs to mount my smb shares with my old Windows computer. Sometimes when I tried to move very large files autofs would want to unmount in the middle of the data transfer, often ruining the copy and locking things up. It's been a few years since I've used it though, so don't know if that's still a problem with newer versions. I may just have been setting my timeout setting too low.
 
Old 07-26-2008, 03:28 AM   #3
srikanthnv
LQ Newbie
 
Registered: Jul 2008
Posts: 12

Original Poster
Rep: Reputation: 0
Yes, they're disk images that I want to mount. Sorry I couldn't be clearer :-)

What I need is to mount the disk image onto a particular directory (say /mnt/mountpoint) when it is accesed by a remote NFS client. So I'm guessing it'll have to be exported all the time. Just the disk image will have to use autofs to mount/unmount.

I'll experiment with autofs and find out. Thanks a bunch for the help!
 
Old 07-31-2008, 06:57 AM   #4
srikanthnv
LQ Newbie
 
Registered: Jul 2008
Posts: 12

Original Poster
Rep: Reputation: 0
OK, I tried it out but it didn't seem to work :-( the disk image stays mounted even though there is no one accessing that directory via NFS.

This is what I did:

/mnt/mountpoint is exported via /etc/exports with this line
Code:
/mnt/mountpoint *(rw,no_root_squash,no_all_squash,sync)
/mnt is configured in autofs /etc/auto.master to do this
Code:
/mnt     /etc/auto.rd     --timeout=60
/etc/auto.rd has this
Code:
mountpoint      -fstype=ext2,rw,loop    :/home/user/disk_image
The disk image gets mounted as soon as someone accesses it remotely, but it stays mounted forever, even if there is no activity from the remote user for hours together :-(

Any clue how I can get it to unmount the disk image automatically? (e.g. if the remote PC has crashed without unmounting the NFS share cleanly, autofs should unmount the disk image after a few minutes of inactivity.)

Last edited by srikanthnv; 07-31-2008 at 06:59 AM. Reason: Clarified a confusing line...
 
Old 08-02-2008, 08:11 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
I haven't used autofs for several years now. I do remember though when I did that for some time there was a bug in it that kept it from auto-unmounting. It was rather frustrating. But I also remember that it was eventually fixed and everything worked perfectly up until the time I decided I didn't need it anymore (when I finally dumped my last Windows machine and no longer had a samba share to automount). Perhaps there's been a regression or something?
 
Old 08-03-2008, 12:49 AM   #6
srikanthnv
LQ Newbie
 
Registered: Jul 2008
Posts: 12

Original Poster
Rep: Reputation: 0
Other directories are getting mounted/unmounted fine, so I don't think it's an autofs problem. It seems to be an issue with autofs unmounting directories that are also accessible via NFS. Any idea if this is the case?
 
  


Reply

Tags
automount, mount, nfs


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with NFS automount deathsfriend99 Linux - Server 2 07-01-2008 08:37 AM
NFS and Automount athreyavc Linux - Server 4 12-10-2007 06:11 AM
automount nfs HA myutopia Linux - Networking 0 11-28-2006 11:06 AM
About NFS automount mahabooba Solaris / OpenSolaris 9 06-30-2006 12:31 AM
NFS server on Windows 2000 to be accessed from Linux manchines hueofwind Linux - Networking 1 06-20-2006 09:20 PM


All times are GMT -5. The time now is 11:10 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration