How do you force a CIFS connection to unmount
Asked Answered
K

13

169

I have a CIFS share mounted on a Linux machine. The CIFS server is down, or the internet connection is down, and anything that touches the CIFS mount now takes several minutes to timeout, and is unkillable while you wait. I can't even run ls in my home directory because there is a symlink pointing inside the CIFS mount and ls tries to follow it to decide what color it should be. If I try to umount it (even with -fl), the umount process hangs just like ls does. Not even sudo kill -9 can kill it. How can I force the kernel to unmount?

Kobe answered 16/9, 2008 at 17:8 Comment(1)
Similar: Force unmount of NFS-mounted directoryIdeation
I
204

I use lazy unmount: umount -l (that's a lowercase L)

Lazy unmount. Detach the filesystem from the filesystem hierarchy now, and cleanup all references to the filesystem as soon as it is not busy anymore. (Requires kernel 2.4.11 or later.)

Ideation answered 18/9, 2008 at 19:59 Comment(9)
This didn't work for me at first. After experimenting a while (in a new virtual terminal each time) I came up with this: sudo umount -a -t cifs -l. Either this did the trick, or the first umount took a while (120s? 300s?) to complete. I got lots of warnings about umount being blocked for more than 120 seconds.Unmitigated
And then I had to kill all the hanging umounts before I could mount again.Unmitigated
I needed also sudo umount -a -t cifs -l to get it to work.Zedoary
This didn't work for me really. I tried everything else above and the cifs mount disappeared from my /etc/mtab listing but it cannot be remounted, so it's effectively useless. The cifs mount freezes when my computer suspends itself while the cifs share is mounted.Locksmith
I concur, umount -a -t cifs -l was what I needed too to get past the dreaded "Host is Down" thx.Calve
This is not working for me. I am able to unmount the share but when I try to remount it I get the following error: mount error(12): Cannot allocate memory Refer to the mount.cifs(8) manual page (e.g. man mount.cifs). Does anyone know what does this mean?Michaeu
Worked for me on RHEL6. Thank you!Sybarite
Don't forget to specify the type -t cifs or you'll unmount EVERYTHING (trust me). Ha.Unstring
Yay, I did sudo umount /mnt/cifsshare -fl then sudo mount /mnt/cifsshare, and a mv file /mnt/cifsshare/file that got stuck yesterday simply continued where it got stuck ! :-)Tribute
B
87

umount -a -t cifs -l

worked like a charm for me on CentOS 6.3. It saved me a server reboot.

Belligerent answered 15/6, 2013 at 23:18 Comment(5)
Would you mind to elaborate on what -a and -l switches are and how they are helping?Jenette
-a and -t cifs unmounts all cifs filesystems. it's better to specify the one you want to unmountPuttier
This is perfect if you mounted via a file browser and you cannot locate the offending mount point - provided you don't mind it unmounting everything!Eurythmic
-l stands for "--lazy detach the filesystem now, clean up things later", worked like a charmAllodial
WARNING. This may not actually "save you a server reboot" in the case that you actually want to use that mount point. `Lazy umount. Detach the filesystem from the file heirarchy now, and clean up all references to this filesystem as son as it is not busy anymore. REMOUNTS OF THE SHARE WILL NOT BE POSSIBLE".Explicit
S
17

On RHEL 6 this worked:

umount -f -a -t cifs -l 
Surefooted answered 9/10, 2014 at 19:29 Comment(1)
This worked, has to wait a full 30 minutes (timeout) before I could remount. Probably best to do a soft mount as jnice indicates.Meemeece
A
15

This works for me (Ubuntu 13.10 Desktop to an Ubuntu 14.04 Server) :-

 sudo umount -f /mnt/my_share

Mounted with

 sudo mount -t cifs -o username=me,password=mine //192.168.0.111/serv_share /mnt/my_share

where serv_share is that set up and pointed to in the smb.conf file.

Aquarist answered 31/1, 2014 at 21:0 Comment(0)
P
6

I had this issue for a day until I found the real resolution. Instead of trying to force unmount an smb share that is hung, mount the share with the "soft" option. If a process attempts to connect to the share that is not available it will stop trying after a certain amount of time.

soft Make the mount soft. Fail file system calls after a number of seconds.

mount -t smbfs -o soft //username@server/share /users/username/smb/share

stat /users/username/smb/share/file
stat: /users/username/smb/share/file: stat: Operation timed out

May not be a real answer to your question but it is a solution to the problem

Pegram answered 18/10, 2012 at 1:53 Comment(2)
If you look at man mount.cifs you'll notice that soft is actually the default.Amphi
Indeed, it is the default, and (at least on my system) it doesn't look like it behaves as expected. After a broken connection (e.g. when the server isn't responding) my cifs system calls hang forever.Chordate
H
2

There's a -f option to umount that you can try:

umount -f /mnt/fileshare

Are you specifying the '-t cifs' option to mount? Also make sure you're not specifying the 'hard' option to mount.

You may also want to consider fusesmb, since the filesystem will be running in userspace you can kill it just like any other process.

Hinterland answered 16/9, 2008 at 17:15 Comment(2)
-f and -t don't help, the umount still hangs.Hindbrain
have you rebooted since adding the '-t cifs' option to mount? I don't think there's anything you can do to fix your stuck mount point right now, your only hope is to try and mount it in a way that's more resistant to failure in the future.Hinterland
M
2

Try umount -f /mnt/share. Works OK with NFS, never tried with cifs.

Also, take a look at autofs, it will mount the share only when accessed, and will unmount it afterworlds.

There is a good tutorial at www.howtoforge.net

Moneywort answered 16/9, 2008 at 17:31 Comment(1)
unfortunately -f doesn't work with CIFS. the umount still just hangs.Hindbrain
P
2

I had a very similar problem with davfs. In the man page of umount.davfs, I found that the -f -l -n -r -v options are ignored by umount.davfs. To force-unmount my davfs mount, I had to use umount -i -f -l /media/davmount.

Phil answered 19/4, 2014 at 10:17 Comment(0)
S
1
umount -f -t cifs -l /mnt &

Be careful of &, let umount run in background. umount will detach filesystem first, so you will find nothing abount /mnt. If you run df command, then it will umount /mnt forcibly.

Stigma answered 2/2, 2015 at 6:12 Comment(0)
R
1

I experienced very different results regarding unmounting a dead cifs mount and found several tricks to bypass the problem temporarily.

Let's start with the mountpoint command. It can be useful to analyze the status of a mount:

mountpoint /mnt/smb_share

Usually it returns is a mountpoint or / is not a mountpoint.

But it can even return:

  • No such device
  • Transport endpoint is not connected
  • <nothing / stale>

For every result expect of is not a mountpoint there is a chance of unmounting.

You could try the usual way:

umount /mnt/smb_share

or force mode:

umount /mnt/smb_share -f

But often the force does not help. It simply returns the same nasty device is busy message.

Then the only option is to use the lazy mode:

umount /mnt/smb_share -l

BUT: This does not unmount anything. It only "moves" the mount to the root of the system, which can be seen as follows:

# lsof | grep mount | grep cwd
mount.cif  3125             root  cwd   unknown                                          / (stat: No such device)
mount.cif  3150             root  cwd   unknown                                          / (stat: No such device)

It is even noted in the documentation:

Lazy unmount. Detach the filesystem from the file hierarchy now, and clean up all references to this filesystem as soon as it is not busy anymore.

Now if you are unlucky, it will stay there forever. Even killing the process probably does not help:

kill -9 $pid

But why is this a problem? Because mount /mnt/smb_share does not work until the lazy unmounted path is really cleaned up by the Linux Kernel. And this is even mentioned in the documentation of umount. "lazy" should only be used to avoid a long shutdown / reboot times:

A system reboot would be expected in near future if you’re going to use this option for network filesystem or local filesystem with submounts. The recommended use-case for umount -l is to prevent hangs on shutdown due to an unreachable network share where a normal umount will hang due to a downed server or a network partition. Remounts of the share will not be possible.

Workarounds

Use a different SMB version

If you still have hopes that the lazy unmounted path will ever be not busy anymore and cleaned up by the Linux Kernel or you can't reboot at the moment, then you are maybe lucky and your SMB server supports different protocol versions. By that we can use the following trick:

Lets say you mounted your share as follows:

mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw

By that Linux automatically tries the maximum support SMB protocol version. Maybe 3.1. Now, you can force this version and it won't mount as expected:

mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=3.1

But then simply try a different version:

mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=3.0

or maybe 2.1:

mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=2.1

Change the IP of the SMB server

If you are able to change the IP address or add a second IP to your SMB server, you can use this to mount the same server.

Dirty: Forward the traffic

Lets say the SMB server has the IP address 10.0.0.1 and the mount is really dead. Then create this iptables rule:

iptables -t nat -A OUTPUT -d 10.0.0.250 -j DNAT --to-destination 10.0.0.1

Now change your mount rule accordingly, so it mounts the samba server through IP 10.0.0.250 instead of 10.0.0.1 and voila, its mounted without server reboot. Dirty, but it works. PS This rule does not survive a reboot, so you should mount the SMB server manually and leave the /etc/fstab as usual.

More debugging

If you want to check if samba connection itself is theoretically working, you could try to list all SMB shares of the server through SMB3 as follows:

smbclient //smb.server -U "smb_user" -m SMB3 -L

or to view the content of a share with SMB1:

smbclient //smb.server -U "smb_user" -m NT1 -c ls
Recipience answered 8/8, 2022 at 13:34 Comment(0)
S
1

Approaching this problem sideways:

If you can't unmount because the filesystem is busy, is your ssh/terminal session cd'd into the mount directory, therefore making the filesystem busy?

For me, the solution was to cd into my home, then sudo umount worked flawlessly.

cd ~
umount /path/to/my/share

I would post this as a comment, but I have insufficient reputation. Hoping to spare someone else the forehead slap.

Salado answered 6/10, 2022 at 18:51 Comment(0)
R
-2

On RHEL 6 this worked for me also:

umount -f -a -t cifs -l FOLDER_NAME

Raucous answered 9/12, 2014 at 10:42 Comment(0)
O
-9

A lazy unmount will do the job for you.

umount -l <mount path>
Ogden answered 16/4, 2015 at 15:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.