7

We have BBB based custom board with kernel 3.12 running on it.

I have doubt regarding umount and & sync.

Lets say a script is umounting a partition, Does it require to run sync command before umount to complete pending writes. ?

10

No, you don't need to run sync before umount. umount will complete all pending writes before it actually unmounts the filesystem. It will also refuse to unmount if some process is still using the filesystem, e.g. as current working directory.

Edit: Unmounting is mostly handled in fs/namespace.c. You won't find any explicit call to sync there, but you'll see comments along the line of "mark this mountpoint for unmount, refuse any further operations on it, and if all operations are done, unmount". You can also see explicit in-use checks.

You can easily test yourself that umount really does finish all pending operations: Mount some slow USB stick, copy a large file to it, and directly call umount after cp. It will take several seconds before you see a new prompt, and if you run dstat etc. in another window, you'll see the write operations that are still going on. That's exactly the same behaviour as if you've typed sync.

  • Thank you for answer dirkt, Do u know code path in kernel which does that ? – AnkurTank Feb 18 '17 at 11:47
  • 5
    It could not be any other way. If you had to sync then you would have to block processes from writing first, or else it may not be synced by the time you got to the unmount (a race condition). – ctrl-alt-delor Feb 18 '17 at 11:57
  • umount -l will let the command complete if something is still using the filesystem and wait in the background for the process to finish, then quietly unmount it. – Mioriin Feb 18 '17 at 13:30
  • Correct. Even the emergency unmount (Alt+SysRq+U) goes through this path which syncs first. – Gilles Feb 18 '17 at 23:45
  • Thank you for reply @richard In my case there are no process writing, I was just worried about writes which were done before, they must be synced to a disk. – AnkurTank Feb 20 '17 at 6:30

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.