phpsmbunmount

Unmounting SMB share folder


I mounted a SMB share folder under /mnt/smb/ and I can access the files. When I unmount this shared folder using command:

umount /mnt/smb/

naturally I cannot list shared folder contents using command:

ls /mnt/smb/

But the problem is when I run the ls command from a PHP file on the same machine, the contents of shared SMB folder can be listed! The contents of PHP file is:

<?php
  $command = 'ls /mnt/smb/';
  $result = shell_exec($command);
  echo $result;
?>

What is my mistake. Is there any other commanf needed for completely unmount the SMB share? I also used command below but there was no luck:

fusermount -u /mnt/smb/

Solution

  • 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