How to Force a Cifs Connection to Unmount

How do you force a CIFS connection to unmount

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

How to unmount a busy device

YES!! There is a way to detach a busy device immediately - even if it is busy and cannot be unmounted forcefully. You may cleanup all later:

umount -l /PATH/OF/BUSY-DEVICE
umount -f /PATH/OF/BUSY-NFS (NETWORK-FILE-SYSTEM)

NOTE/CAUTION

  1. These commands can disrupt a running process, cause data loss OR corrupt open files. Programs accessing target DEVICE/NFS files may throw errors OR could not work properly after force unmount.
  2. Do not execute above umount commands when inside mounted path (Folder/Drive/Device) itself. First, you may use pwd command to validate your current directory path (which should not be the mounted path), then use cd command to get out of the mounted path - to unmount it later using above commands.

Unmounting SMB share folder

When the mount command runs for more than one time, multiple sessions open in the background. Running u(n)mount command, only terminates one of the sessions while the other sessions are active in the background. The active sessions can be seen by running this command:

mount | grep /mnt/smb

Running u(n)mount command again terminates active sessions one by one and resolves the issue. I used this script to run u(n)mount command as many times as needed:

if [ "$(sudo mount | grep /mnt/smb)" != "" ]; then
sudo umount -l /mnt/smb/;
smbContents=$(sudo mount | grep /mnt/smb);
fi

while [ "$smbContents" != "" ]; do
sudo umount -l /mnt/smb/;
smbContents=$(sudo mount | grep /mnt/smb);
done

Force unmount of NFS-mounted directory

You might try a lazy unmount:

umount -l

Kali on windows CIFS support

using:

sudo mount -t drvfs \\server\directory \mountpoint

WSL now supports drvfs which can connect to remote drives etc.
So no need for cifs/samba



Related Topics



Leave a reply



Submit