I'm using Ubuntu 17.10.
I formatted an USB pen-drive to NTFS to prepare a Windows7 USB Installer.
I set the bootable flag on this pen-drive and copied the files into it.
EDIT 1: The USB pen-drive is automatically mounted by udev.
umount /dev/sdb1
takes from 10 upto 12 minutes to complete.
Here are the mount options :
$ mount | grep sdb
/dev/sdb1 on /media/mansfeld/Win7_USB_Installer type fuseblk (rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096,uhelper=udisks2)
EDIT 2: The cp
operation is not INSTANTANEOUS at all, it took 3 minutes to copy the files to the USB pen-drive.
EDIT 3: The sync
operation (done right after the cp
) took 12 minutes to complete ! But then the umount
will be instantaneous.
For FAT32, (with sync also disabled during mount), I notice the same behaviour.
Any ideas why it takes so long to unmount NTFS USB pendrive ?
You are probably suffering from
bufferingcaching. 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, thenumount
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 thesync
to complete (instead of waiting forumount
). But theumount
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 completesync
, wait 10 minutes to complete, followed byumount
(will return almost immediately)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
beforeumount
, theumount
is instant.