Lately I've been using USB2 flash drives to transfer a lot of data to my company.
When copying the Data to the flash drive, I noticed that the data is not written directly to the drive. It wrote with 200MB/sec to cache(?). I then umount
or sync
the drive and it takes hours to actually write the data to the
drive.
I also tried using cp
instead of Nautilus, but it had the same behavior. dd
is not an option for copying normal files.
Is there any way to make Linux write the data directly without caching when writing on USB storage? Or maybe reduce caching so that I don't have to wait for hours when unmounting the drive?
What's annoying me most is that the progress bar finishes copying and I then have to wait a unspecified time for sync
to write the data.
I'm on a Fedora 25 machine.
[Update] Tried to clarify my question.
[Update 2] Found a similar question without answer:Reduce cache size of flash storage devices
Best Answer
You could dry the direct
dd
method. Sounds like it's time to reformat your drive with:mk2fs.
-fs-of-your-choice.man mkf2s
The dd route is simple.
Run once before you pulug in your drive.
lsblk
And once after.
Notice the output of your device.
Then to copy the files you can create a new device like so:
dd if=/dev/zero of=~/my-files.dd.img bs=1G mkfs.ext4 ~/my-files.dd.img losetup /dev/loop0 ~/my-files.dd.img
Note If you’d like this to be remounted after a machine reboot then add the above line to the rc.local file.
vi /etc/rc.local
Mount the device with:
mkdir /mnt/amazing mount -o loop=/dev/loop0 ~/my-files.dd.img /mnt/mymountpoint
To check the file has been mounted you can use the df command:
df -h | grep mymountpoint /dev/loop0 976M 1.3M 924M 1% /mnt/mymountpoint where `bs=` a value greater than the output of: `ls -lh ./your-file-here`
When you're done unmount the devices:
umount /mnt/mymountpoint losetup -d /dev/loop0
Haven't tested this but I suppose this is how it should work.
Cheers rivanov