158

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?

smoofra
  • 2,715
  • 2
  • 19
  • 23
  • Similar: [Force unmount of NFS-mounted directory](http://stackoverflow.com/questions/40317/force-unmount-of-nfs-mounted-directory) – Kemal Sep 18 '08 at 20:04

11 Answers11

193

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.)

Kemal
  • 2,482
  • 1
  • 20
  • 13
  • 45
    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. – Peter Jaric Mar 12 '12 at 12:06
  • 2
    And then I had to kill all the hanging umounts before I could mount again. – Peter Jaric Mar 12 '12 at 12:29
  • 15
    I needed also `sudo umount -a -t cifs -l` to get it to work. – Joma Jul 11 '12 at 16:17
  • 4
    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. – DH4 Sep 23 '12 at 18:43
  • I concur, umount -a -t cifs -l was what I needed too to get past the dreaded "Host is Down" thx. – Pooch Oct 06 '14 at 20:44
  • 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? – Natesh Raina Aug 25 '16 at 05:17
  • Worked for me on RHEL6. Thank you! – Soruk Aug 26 '16 at 21:16
  • Don't forget to specify the type `-t cifs` or you'll unmount EVERYTHING (trust me). Ha. – moodboom Jan 20 '20 at 14:45
73

umount -a -t cifs -l

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

assylias
  • 297,541
  • 71
  • 621
  • 741
ivanlan
  • 858
  • 6
  • 6
  • 8
    Would you mind to elaborate on what `-a` and `-l` switches are and how they are helping? – Isaac Dec 20 '14 at 09:28
  • 10
    -a and -t cifs unmounts all cifs filesystems. it's better to specify the one you want to unmount – dwery Nov 20 '15 at 08:26
  • 2
    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! – sage Dec 03 '15 at 17:49
  • 1
    Thanks, this saved a lot of time today! – agam Apr 05 '18 at 18:26
15

On RHEL 6 this worked:

umount -f -a -t cifs -l 
Andy Fraley
  • 755
  • 6
  • 14
  • This worked, has to wait a full 30 minutes (timeout) before I could remount. Probably best to do a soft mount as jnice indicates. – XMAN Sep 12 '18 at 22:53
12

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.

Phil Johnson
  • 129
  • 1
  • 2
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

pb2q
  • 54,061
  • 17
  • 135
  • 139
jnice
  • 101
  • 1
  • 1
  • 20
    If you look at `man mount.cifs` you'll notice that `soft` is actually the default. – Benj May 01 '13 at 10:13
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.

Benedikt Köppel
  • 4,344
  • 4
  • 26
  • 40
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

Sunny Milenov
  • 20,782
  • 5
  • 75
  • 102
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.

Miheretab Alemu
  • 918
  • 1
  • 19
  • 41
zhjb7
  • 11
  • 2
1

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.

Chris AtLee
  • 7,078
  • 3
  • 26
  • 27
  • 4
    -f and -t don't help, the umount still hangs. – smoofra Sep 16 '08 at 17:35
  • 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. – Chris AtLee Sep 16 '08 at 19:33
-2

On RHEL 6 this worked for me also:

umount -f -a -t cifs -l FOLDER_NAME

chataros
  • 1
  • 2
-9

A lazy unmount will do the job for you.

umount -l <mount path>
anonymoose
  • 750
  • 2
  • 10
  • 23