Slow shutdown related to network share drives

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
JasonStonier

Slow shutdown related to network share drives

Post by JasonStonier »

I'm occasionally having crazy slow shutdown times on my desktop Mint 18.1, in the order of two minutes to shut down. I think I have the problem isolated to involving my network share drives.

At startup I mount two network share drives in fstab:

Code: Select all

//192.168.0.120/JCSShare /media/BuffaloJCS cifs  guest,uid=1000  0  0
//192.168.0.121/share /media/BuffaloMFA cifs  guest,uid=1000  0  0
The problem I'm having is that if those drives were available at boot time, but NOT available at shutdown time, shutdown takes ages. That wouldn't usually be a massive problem I guess, but we get a lot of power outages, and I get about 2 minutes out of my UPS before the battery goes, which means there are a lot of occasions where the machine won't shut down in time if I turn the network drives off first.

is there anything I can do to get around this? Thanks in advance.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
ugly
Level 5
Level 5
Posts: 592
Joined: Thu Nov 24, 2016 9:17 pm

Re: Slow shutdown related to network share drives

Post by ugly »

I have trouble with this as well. Same symptoms. Slow shutdown if network drives are mounted, but unavailable. In my case, it's a Samba share, and sometimes I turn off the computer hosting the Samba shares first.

I had a script that I set up with init.d to run when I shutdown the PC that provides the mounted network shares. It worked in 18.1, but for some reason it stopped in 18.2. I don't know enough to fix it.

I'll post the script and maybe someone smarter than me can fix it, or provide a better answer on how to accomplish the same task.

I put this in /etc/init.d with a filename UnmountSambaFromZBOXShutdown and made it executable.

Code: Select all

#!/bin/bash
### BEGIN INIT INFO
# Provides:          UnmountSambaFromZBOXShutdown
# Required-Start:    network
# Required-Stop:
# Should-Start:      
# Default-Start:     5
# Default-Stop:
# Short-Description: Unmounts ZBOX samba share on shutdown
# Description:       Checks if PC is accessible and unmounts the shared and laptop folder if it is
### END INIT INFO

#address of local IP - zbox
localaddressmain=192.168.1.73
sharedFolder=/media/zbox/Shared
laptopFolder=/media/zbox/laptop

ping -c 1 $localaddressmain 2>/dev/null 1>/dev/null
if [ "$?" = 0 ]
then
	ssh -i /home/rick/.ssh/id_rsa rick@$localaddressmain sudo /bin/umount -f $sharedFolder
	ssh -i /home/rick/.ssh/id_rsa rick@$localaddressmain sudo /bin/umount -f $laptopFolder
#else
#	echo "host not found"
fi
Basically, what it does is when the computer hosting the network share shuts down, it pings my main PC, if it is found, it uses ssh to unmount the two shared folders.

To provide the permission to run umount without a password, in sudoers, I added: rick ALL = NOPASSWD: /sbin/mount.cifs, /bin/umount

Then I symlinked the script to the reboot and shutdown rc folders:
ln -s /etc/init.d/UnmountSambaFromZBOXShutdown /etc/rc0.d/K01UnmountSambaFromZBOXShutdown
ln -s /etc/init.d/UnmountSambaFromZBOXShutdown /etc/rc6.d/K01UnmountSambaFromZBOXShutdown

There's probably a much smarter way of doing this.
JasonStonier

Re: Slow shutdown related to network share drives

Post by JasonStonier »

Why do you ssh there, inside your conditional?

I love the approach, it's elegant. Is it possible to just umount the local shares if ping fails?
User avatar
ugly
Level 5
Level 5
Posts: 592
Joined: Thu Nov 24, 2016 9:17 pm

Re: Slow shutdown related to network share drives

Post by ugly »

Oh, I forgot to mention a key point. The shutdown script is intended to be on the 'server' PC that hosts the shared folder.

So the idea is that before the server shuts down, it tells my main 'client' PC (the one that has mounted the shared folders) to unmount the shared folders. The ssh command enables the server to send the unmount command to the client.

Maybe you can just send the commands without doing the ping.
JasonStonier

Re: Slow shutdown related to network share drives

Post by JasonStonier »

I got Ugly's neat shell script working for my case, i.e. if the server isn't ping-able then run umount

HOWEVER there does not appear to be an easy way to force unmount a share that is not currently present due to a network failure.

I've tried umount with -f -l and the process still hangs until timeout (300 seconds I think).

Any ideas on this one?
JasonStonier

Re: Slow shutdown related to network share drives

Post by JasonStonier »

I still haven't got anywhere with this.

Anyone able to offer insights on how to force unmount a network share that has dropped off the network?
Locked

Return to “Beginner Questions”