Unmounting partitions needs to be done by device
Background - A partition can have multiple mount points. If a mount is busy then you cannot umount it. This can leave some mounts on the partition mounted and some unmounted. I have the following set up:
[root@server ~]# cat /proc/mounts | grep sdb
/dev/sdb1 /BackupDisc ext4 rw,noatime,data=ordered 0 0
/dev/sdb1 /shares/private ext4 rw,noatime,data=ordered 0 0
The disk is mounted into /BackupDisc. There is also a bind mount from /dev/sdb1/shares/private to /shares/private and this is a Samba share. If I browse the share in Windows Explorer, it comes into use. In the current program, the app shows /dev/sdb1 mounted into /BackupDisc. If I unmount it through the webconfig, it then shows /dev/sdb1 mounted into /shares/private. This is unmountable as it is in use.
Note, at this point, if I remount /dev/sdb1 into /BackupDisc, it then shows up incorrectly in the app as the first mount from cat /proc/mounts
is the bind mount! It would be ok if lsblk
with some switches was used instead cat /proc/mounts
/cat /etc/mtab
. See fth following sequence:
[root@server ~]# cat /etc/mtab | grep sdb
/dev/sdb1 /BackupDisc ext4 rw,noatime,data=ordered 0 0
/dev/sdb1 /shares/private ext4 rw,noatime,data=ordered 0 0
[root@server ~]# umount /BackupDisc
[root@server ~]# cat /etc/mtab | grep sdb
/dev/sdb1 /shares/private ext4 rw,noatime,data=ordered 0 0
[root@server ~]# mount -a
[root@server ~]# cat /etc/mtab | grep sdb
/dev/sdb1 /shares/private ext4 rw,noatime,data=ordered 0 0
/dev/sdb1 /BackupDisc ext4 rw,noatime,data=ordered 0 0
/dev/sdb1 /shares/private ext4 rw,noatime,data=ordered 0 0
What I suggest you do is do the unmount by device. If you do a umount /dev/sdb1
, it this case it will show the disk is in use:
[root@server ~]# umount /dev/sdb1
umount: /shares/private: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
This error can be trapped and a message displayed on screen. If no error message is displayed, the first unmount has worked. At this point you should repeat umount /dev/sdb1
until mtab shows no more mounts for the device or until you get:
[root@server ~]# umount /dev/sdb1
umount: /dev/sdb1: not mounted