This guide explains how to monitor the progress of the sync command when flushing data to disk, particularly useful when copying large files to USB drives.

Why Monitor Sync?

The sync command writes cached data from RAM to disk, but provides no feedback. When copying large files to slow USB drives, you need to know when it’s actually safe to unmount.


The Problem

cp large_files/ /mnt/usb/   # Appears to finish instantly, but data is still writing!
sync                        # Seems to have hung

The sync command “hangs” as writes continue in the background. Unplugging too early causes data loss.


Solution: Monitor Dirty Memory

watch -n 1 grep -e Dirty: -e Writeback: /proc/meminfo

How It Works:

  1. Dirty: Data modified in RAM but not yet written to disk (queued).
  2. Writeback: Data currently being written to disk (in progress).
  3. When both values drop to near 0 KB, sync is complete.

What You’ll See:

Dirty:          524288 kB  ← Data waiting to be written
Writeback:       65536 kB  ← Data currently writing

Wait until both show only a few KB or MB, then it’s safe to unmount.


Alternative: Monitor I/O Activity

watch -n 1 iostat -x 1 1 /dev/sda

Look for write activity (wkB/s). When it drops to 0, writes are complete.

Or use iotop to see live disk writes:

doas iotop -o