# [solved] How? unmount NFS when connection lost

## hoacker

When a connection to a server is lost while a NFS share of this server is still mounted my box stops during shutdown when it tries to unmount the NFS mount. I know that loosing the connection is not a good thing at all, but IF the connection is lost, what to do to shutdown properly?Last edited by hoacker on Sat Oct 04, 2008 6:53 pm; edited 1 time in total

----------

## peaceful

umount -f

From "man umount":

-f     Force unmount (in case of an unreachable NFS system).  (Requires kernel 2.1.116 or later.)

----------

## hoacker

Yes, I know the "force" option, but how "force" unmount during the shutdown process?

----------

## peaceful

Add "umount -f /your/mounted/directory" to /etc/conf.d/local.stop

----------

## hoacker

 *peaceful wrote:*   

> Add "umount -f /your/mounted/directory" to /etc/conf.d/local.stop

 

Thanks, I'll try that. Didn't know local.stop, might be useful to keep it that in mind...

----------

## peaceful

local.start is executed after normal startup.  local.stop is executed before normal shutdown.  They're pretty useful in cases like this.   :Smile: 

----------

## arth1

 *hoacker wrote:*   

> When a connection to a server is lost while a NFS share of this server is still mounted my box stops during shutdown when it tries to unmount the NFS mount. I know that loosing the connection is not a good thing at all, but IF the connection is lost, what to do to shutdown properly?

 

Mount the NFS share with the "soft" or "intr" options.  The soft option will allow NFS to fail when timing out, and not retrying eternally.  The "intr" option allows the NFS process to be stopped if it has timed out.

Caveat:  If an NFS write was in progress when the timeout occurred, it will not complete after it comes back online again if using "soft".

----------

## hoacker

 *arth1 wrote:*   

> Mount the NFS share with the "soft" or "intr" options.

 

I'll mount nfs with every option but "soft" as this may cause data curruption. The option "intr" may be an option for me. Thanks, arth1.

----------

## hoacker

 *hoacker wrote:*   

> The option "intr" may be an option for me.

 

Just putting "intr" in FSTAB is not the solution, shutdown still hangs during unmount. I'll keep it in FSTAB anyway as it seems to be a nice option. Umount in local.stop works quite well, so I consider my problem solved.

Thanks again, you two.

----------

## chris...

```
umount -f /directory/
```

doesnt work for me

----------

## musv

I had a lot of problems with umount -f. In most cases umount -l did a better job for me.

----------

## chris...

most cases?

----------

## musv

My knowledges about the technical aspects of nfs are quite limited. I was using it to share some directories in my local web. Now I'm beginning to migrate all the read-only stuff to nbd or AoE because of performance reasons. My fstab looks like that (I use it to compile the stuff for the slow box on my big computer): 

```
fehlermelder:/  /mnt/fehlermelder       nfs     noauto,wsize=8192,rsize=8192,hard,intr  0 0
```

intr - should allow the interrupt nfs transactions in case of a time-out

hard - in case of a major timeout tries to continue instead of showing the message "server not responding"

My limited experience: 

You have a server, sharing some directories. On the client some of those directories are mounted. Now the server crashes or there's some other trouble with the network connection. If you try to unmount the shared directories on the client, the umount commando hangs. I've never realized so solve that problem with "umount -f". Rather with "-f" I remember to crash the whole system in rare cases. I'm using Linux now for more than 6 years. In all that time the behaviour of nfs didn't change. And to make matters worse, if you try to reboot the client, it will hang while unmounting the network filesystems. Only solution is a hard-reset of the machine or using the Magical SysRQ key.

The funny thing: If you have on the client mounted nfs-shares and reboot the server, the client is able to unmount the shares after the server finished restarting and sharing the directories again. 

umount -l: 

I don't remember where I got this hint. "-l" is a lazy unmount. The filesystem will be unmounted as soon as possible (man-page). With that option I had more success than with "-f". I wrote "in most cases", because sometimes it didn't help too. In that case: Magical SysRQ.

----------

## Xarthisius

It's baselayout bug. Problem's been already mentioned at bugzilla

Temporary solution can be also found there.

Cheers,

Xarthisius

----------

