r/archlinux • u/activedusk • 26d ago
DISCUSSION Old time unfixed Linux bug for copying files
Hello,
For some time I noticed when copying files to other storage devices like USB thumb drives there are some weird and largely unadvertised bugs, for example when copying files including when using dd to create bootable media I always leave the thumb drive connected for 5 to 10 minutes after the filesystem or terminal says "it's done" because I found if I immediately disconnect the drive, it might not actually be finished. Reason being, apparently there is a delay built in when transfering from memory to the storage device and it's not clearly communicated visually when the task is finished. When copying from one part of an internal drive to another, this is not an issue, it generally becomes a big issue when using external storage and even network attached storage.
https://youtu.be/DEf10RWc_F0?si=zTJucYOxOwQgGQwK
Apparently KDE is trying to push a fix for this, I still don't know if it's a kernel problem, a file manager problem, some other component or all the above and how it affects Linux in a case by case basis. Does the wiki warn about this? Are people shouting loud and clear "When you copy something to USB storage, leave it connected and do not unmount or eject for 5 to 10 minutes after it says it's done"? It seems like a minor inconvenience but it is a pain point that can confuse a lot of beginners that expect simple things like this to be sorted and rock solid, after all it's a basic cp or mv operation.
6
u/Elsior 26d ago
Sounds like you are talking about the cache not yet being written to disk. A mounted filesystem when unmounted would cause a sync to occur. You can see this if you transfer a large amount of data to an external disk and then immediately try to unmount. The unmount can take a few seconds.
DD to a drive is writing to the device raw, so you the user need to take care that the cache is flushed. Easiest way is to call "sync" as root.
12
u/ang-p 26d ago
Looks like AI slop....
So it happened once and you couldn't be arsed to discover why, when the signs and answers were infront of your face the whole time?
BULLSHIT.
do a half-assed search and you'll be hard pressed to find a
dd"tutorial" for creating a USB stick without a means for ensuring the whole image is copied....Even the CRAP tut YOU "WROTE" a week ago has (a crap) method of avoiding just what you claim to suffer from....
https://www.reddit.com/r/archlinux/comments/1xk6hi3/how_to_maintain_and_optimize_your_install_arch/
Scroll down to the last command.....
NO - because that is a shit way of "ensuring" anything is written....
In KDE Dolphin - use the "Unmount" option that is in-front of your face should you be arsed to look instead of running AI-round like some headless dummy on one day shouting "is this a bug", and giving people "advice" on how to do things another....
Even Windows had this "issue" for nearly 2 decades - but "safely ejecting" was something that even stupid people managed with little difficulty...
2
u/AppointmentNearby161 26d ago
This is not a bug but a misunderstanding of how Linux/GNU works. The
cpandsynccommands do different things. Not only does this follow the Unix philosophy of do one thing and do it well, it also has performance benefits. By not forcing a sync after copying the files to the page cache, it allows the kernel to group the writes together.Windows does exactly the same thing (buffered I/O) for devices it decides are internal. For devices it decides are "removable", Windows disables buffered I/O to prevent users from losing data when they yank the USB stick. Linux does not do this. It is design decision with that trades user convenience (Windows) for performance/device health (Linux).
17
u/happahopp 26d ago edited 26d ago
you can eject it safely in dolphin. the ejection process will wait.
umount seem to wait too
the only issue is that you should not physically unplug it before eject/umount if you have written something to it recently (and if you copied a 10GB file you might have to wait for quite some time)
14
u/MouseJiggler 26d ago
I will always run sync after writing to non-local devices
I will always run sync after writing to non-local devices
I will always run sync after writing to non-local devices
I will always run sync after writing to non-local devices
I will always run sync after writing to non-local devices
I will always run sync after writing to non-local devices
I will always run sync after writing to non-local devices
(insert Bart Simpson here)
2
u/Excellent-Love-6943 26d ago
When you eject the drive, it doesn't eject until any file transfer is done.
1
u/Needieos 26d ago
isn't there a sysctl trick on cache?
1
u/Gozenka 25d ago
I would say it is not a bug, but a great feature. Think of it like this: Would you rather have to wait an hour for the physical disk write to finish, or would you rather the physical disk write continues in the background while your system can quickly work just like it is completed (by accessing the data from RAM while the process continues)?
Cache works really well to speed things up like this. For instance, files that are accessed may also be cached in memory, and do not need the disk to be read again when you try to access the file again.
In cases where this matters, just proper usage should be enough to handle the "sync". Unmount (or eject or whatever in GUI) before physically removing a disk. And do clean shutdowns of the PC, which would also automatically sync and unmount disks before shutting down. If you do not do these, you are likely to have other issues that are independent of this post's topic anyway, such as filesystem corruption. Removing a USB stick without proper unmounting is a risk in any case.
However you are right that new (or old) Linux users do not really need to know about
syncand that things may continue writing to disk in the background.1
u/archover 25d ago edited 24d ago
Your complaint about copying to flash drives is as old as Linux.
The antidote in my long experience is using >400MB/sec target drives, which solves it completely.
For example,
Note that full installs and doing pacman updates to flash drives, is a worst case test scenario IMO.
While I might use an ordinary flash drive as an ISO host, I NEVER use them to copy many files, and especially large files.
Contrary to what most people say, I've had no flash drive failures due to write fatigue, ever. Many years experience.
Good day.
1
u/CosmicFieldDrift_ 25d ago
In regards to a bug in KDE, I remember seeing something on Phoronix about it:
https://www.phoronix.com/news/KDE-Fixes-15-Year-Old-Bugs
-3
u/Illustrious-Gur8335 26d ago
After safely removing the drive in KDE, type
syncin Konsole and wait for it to complete, then the drive is really safe to remove.You can also shutdown or restart to sync the disk cache to disk.
-6
u/BlueGoliath 26d ago
Linux is mainstream ready. Year of the Linux desktop. Finally.