USB pendrive : the copy takes about 3 minutes but the unmount takes a very long time : 10 to 12 minutes
You are probably suffering from buffering caching. To speed up writing to USB sticks (and hard disks in general), Linux uses a filesystem cache:
When you (think you) write something to the stick then it is first written to the cache (in RAM) and the cp
command (for instance) returns immediately pretending a really fast write operation. While you do other things, the contents of the cache is then written to the stick in background. You may notice that an LED on the stick still flashes showing write operations (depends on your stick) although nothing apparent happens.
When you issue umount
soon after a write operation, then umount
waits until all the filesystem's cache content is written to the stick in order to make sure no data gets lost.
With sync
you can manually force emptying the cache and writing the data to the stick. However, this won't speed up the total elapsed time because then you will have to wait for the sync
to complete (instead of waiting for umount
). But the umount
will then return instantaneously because the cache is already flushed.
In summary you have three choices after copying large or many files to the stick:
-
umount
and wait 10 minutes for it to complete -
sync
, wait 10 minutes to complete, followed byumount
(will return almost immediately) - simply wait for 10 minutes (perhaps a bit more) and do nothing (or something unrelated to the stick) and then issue
umount
. Because the cache gets written in background automatically,umount
will then return almost immediately as well.
When you copy files to your pendrive, they are not written on it directly. Filesystem synchronization is happening on unmount command, the actual data is written while you wait your unmount. If you execute sync
before umount
, the umount
is instant.