From 6f811cfaca4d8b0e8cad1dfd1bd81c336fc8528b Mon Sep 17 00:00:00 2001 From: Movie Ma Date: Fri, 20 Aug 2021 12:33:12 +0000 Subject: [PATCH] Fix unmount error when unmounting below a bind mount point (!89) Bind mounts duplicate part of the file system hierarchy to an additional mount point [1]. When mounting and unmounting a second file system below a duplicating bind mount Linux automatically presents this lower file system as being mounted multiple times. GParted displays these multiple mount points. However using GParted to unmount this lower file system reports an error that the second mount point is no longer mounted, because all were unmounted by the first unmount command. Setup: 1. Mount an upper file system # mkdir /mnt/1 # mount /dev/sdb1 /mnt/1 # fgrep sdb /proc/mounts /dev/sdb1 /mnt/1 ext4 rw,seclabel,relatime,data=ordered 0 0 2. Bind mount it to a second directory # mkdir /mnt/b1 # mount --bind /mnt/1 /mnt/b1 # fgrep sdb /proc/mounts /dev/sdb1 /mnt/1 ext4 rw,seclabel,relatime,data=ordered 0 0 /dev/sdb1 /mnt/b1 ext4 rw,seclabel,relatime,data=ordered 0 0 3. Mount a file system below the first # mkdir /mnt/1/lower # mount /dev/sdb2 /mnt/1/lower # fgrep sdb /proc/mounts /dev/sdb1 /mnt/1 ext4 rw,seclabel,relatime,data=ordered 0 0 /dev/sdb1 /mnt/b1 ext4 rw,seclabel,relatime,data=ordered 0 0 /dev/sdb2 /mnt/1/lower xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0 /dev/sdb2 /mnt/b1/lower xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0 Two mount records for sdb2 were added to /proc/mounts from one mount command. Then use GParted to unmount sdb2. It reports this error dialog: +-------------------------------------+ | | | Could not unmount /dev/sdb2 | | | | # umount -v '/mnt/b1/lower' | | umount: /mnt/b1/lower: not mounted. | +-------------------------------------+ | [ OK ] | +-------------------------------------+ Fix by checking that the file system is still mounted before each unmount attempt. [1] mount (8), Description, Bind mount operation https://man7.org/linux/man-pages/man8/mount.8.html#DESCRIPTION Closes !89 - Fix unmount error when unmounting below a bind mount point --- src/Win_GParted.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index 75ea445e..fcb086eb 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -2847,11 +2847,17 @@ bool Win_GParted::unmount_partition( const Partition & partition, Glib::ustring } else { + Glib::ustring checkmount = "grep -w " + Glib::shell_quote(fs_mountpoints[i]) + " /proc/mounts"; Glib::ustring cmd = "umount -v " + Glib::shell_quote( fs_mountpoints[i] ); Glib::ustring dummy; Glib::ustring umount_error; - if ( Utils::execute_command( cmd, dummy, umount_error ) ) - umount_errors.push_back( "# " + cmd + "\n" + umount_error ); + + // Check mount point is still mounted + if (! Utils::execute_command(checkmount, dummy, umount_error)) + { + if (Utils::execute_command(cmd, dummy, umount_error)) + umount_errors.push_back("# " + cmd + "\n" + umount_error); + } } }