4

I am running Linux and want to safely unmount my external HDD.

I want to use umount --lazy:

Lazy unmount. Detach the filesystem from the file hierarchy now, and clean up all references to this filesystem as soon as it is not busy anymore. (Requires kernel 2.4.11 or later.)

After the last reference to the filesystem is closed, I'm assuming that a sync will be performed.

How do I know when that sync is complete?

Tom Hale
  • 30,455

2 Answers2

2

You have two options:

  1. don't use umount's --lazy option if you care about when the external drive can be safely unplugged (and you should care).
  2. run sync from your shell and wait for it to return. This is, of course, just doing manually what a non- --lazy umount does automatically...so it doesn't save any time, it just creates more work.
cas
  • 78,579
  • 1
    I should have mentioned that option 2 above does not guarantee a fully synced filsystem - a process with a file open for W may have written to that file between the time sync completes and you see it on your shell (or your script gets to the next executable statement). i.e. race condition. – cas Aug 14 '17 at 06:21
  • If using ext3/4 filesystem, you can also check for needs_recovery flag in tune2fs -l /dev/sdXY | grep Filesystem.features command output, which will be there until device is fully unmounted. – korc Dec 28 '20 at 04:01
-1

One option that has worked for me in the past, is simply trying to lazy umount it again. If it's still mounted, it won't say anything, but if the previous lazy umount succeeded, it'll say:

umount: /path/to/mountpoint/: not mounted
  • 5
    That won't work. Lazy unmounting removes the mount point from the file name space. It doesn't mean that open files on the filesystem have been closed, which is what the question is about. Welcome to unix.SE :) – Tom Hale Apr 15 '18 at 07:18