[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: sleep(1) vs. sync(1) twice before umount(8)



David wrote:
>On 7/10/22 05:55, fxkl47BF@protonmail.com wrote:
> > I'm just flapping my gums
> > As a systems administrator for UNIX systems I wrote more than a few 
>scripts
> > Many time I found it necessary to put a sleep between operations
>
>+1
>
>
>The hard part is deciding what the NUMBER argument should be.  :-/
>
>
> > Several decades ago I was taught to type sync and then type sync 
>again before unmounting a drive
> > The only reason I ever got was that the second sync was a time delay
>
>
>That is an interesting technique.  I sometimes type sync(1) twice when I 
>am distracted with several irons in the fire and/or when the system is 
>making me worried, but it is not my standard practice.
>
>Any potential gotchas?

Sigh, this old canard.

Back in the day (*many* days ago!), the sync was recommended on some
Unix systems as they might *not* necessarily unmount and flush data
cleanly. This has not been necessary since *forever* on any sensible
system, like Linux - the system will already flush all existing
filesystem buffers as part of the umount process.

There *is* one reaonable exception - if you're using dd (or similar)
to write directly to a raw device then that will *not* wait for things
to be flushed *by default*, and may exit cleanly when the kernel still
has buffers outstanding. *Then* you might want to call sync and waif
for that to finish. Or: simply add "oflag=sync" onto your dd call, or
similar.

*Or* you might want to call "sync" in a loop if you're worried you're
about to lose power suddenly. This is what UPSes are for...

-- 
Steve McIntyre, Cambridge, UK.                                steve@einval.com
"We're the technical experts.  We were hired so that management could
 ignore our recommendations and tell us how to do our jobs."  -- Mike Andrews


Reply to: