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?


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.
  • 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 6:21

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
  • 1
    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 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.