r/archlinux • • 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.

0 Upvotes

35 comments sorted by

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.

-1

u/activedusk 26d ago

Most users understand Eject, unmount, etc. as a switch rather than a process. If sync takes tens of s if not minutes for idk 50GB to actually finish copying, realistically the user will wait about as much time it takes to unplug the external drive.

7

u/AppointmentNearby161 26d ago

The list of PEBKAC bugs is long.

1

u/activedusk 26d ago

If GUI says copying is finished but it's not, it was filed as a problem and not user error.

1

u/lajawi 26d ago

The user not waiting for confirmation of ejection is user error.

The system saying the files are done copying while absolutely not being finished with it is a system error.

1

u/AppointmentNearby161 26d ago

The user thinking the cp runs sync is the user error.

1

u/activedusk 25d ago

That's true but not an issue for cp from internal drive to internal drive, those are not going anywhere. This becomes an issue with external storage where they observed one behavior for internal drive operation and suddenly it behaves differently for external storage. I can give a pass to cp, mv, dd, read the manual, whatever. The GUI however lying when it's done and then expecting users to follow procedure and wait after they thought the files were already on the external storage is best described as trolling.

12

u/ang-p 26d ago

Looks like AI slop....

For some time I noticed

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?

for example when copying files including when using dd to create bootable media

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.....

 sudo dd ....... oflag=sync

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"?

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...

-5

u/activedusk 26d ago

I wrote the post myself and found a fix that worked, waiting after the GUI said it's "done copying" before removing the drive.

As for dd command including sync, apparently both sudo and synch is required and a beginner would not realize they need both for copying any sort of files and might associate it only with .iso files specifically.

>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

Says you as if the process still doesn't take time and a beginner would not immediately unplug the device without waiting. But you, despite knowing better, did not warn about it in your comment.

>Even Windows had this "issue" for nearly 2 decades - but "safely ejecting" was something that even stupid people managed with little difficulty...

I am sure everyone uses eject...right. /s

5

u/ang-p 26d ago edited 26d ago

As for dd command including sync, apparently both sudo and synch is required and a beginner would not realize they need both for copying any sort of files and might associate it only with .iso files specifically.

Erm...... what a complete word-salad of shite...

they need both for copying any sort of files

Oh, lordy..... How wrong is that statement in several ways

did not warn about it in your comment.

In a post about the very subject? - What part of

use the "Unmount" option

Do you have trouble understanding?

Also, in your OP...

a basic cp or mv operation.

won't return until finished, besides, would have been preceded by a mount command, and the corresponding umount would automagically sync - saving your pretty little head from rubbing it's brain cells together and getting flustered.

I am sure everyone uses eject...right. /s

They sure did - for decades....

They only pulled the drive out and lost stuff once....

Unlike you it seems....

 "insanity is doing the same thing over and over and expecting different results"

-2

u/activedusk 26d ago edited 26d ago

>would have been preceded by a mount command, and the corresponding umount would automagically sync - saving your pretty little head from rubbing it's brain cells together and getting flustered.

Sync takes time, does it not? If user disconnects drive not knowing umount command is finishing the copying, how is the result not a corrupted or missing file? You should also warn for the user to wait for the process to finish and when it's safe to remove the device and not just using umount.

2

u/ang-p 26d ago

If user disconnects drive not knowing umount command is finishing the copying, how is the result not a corrupted or missing file?

The user knows the umount command has finished because they see a

activedusk@troll:~>  

prompt appear....

0

u/activedusk 26d ago

Address the issue or move along.

2

u/ang-p 26d ago edited 26d ago

OK...

You.       Can.       Tell.       A.       sync.       Or.       umount.       Or.       cp.       Or.       mv.       Command.       Has.       Completed.       Because.       It.       Gives.       You.       The.       Prompt.       Back.

Can you work that out?

0

u/activedusk 26d ago edited 26d ago

Useless trivia, mention why waiting for the command line is important not just that the command must be used before unplugging the drive, also you forgot about dd and privilege for the command or how the process works with a GUI file manager maybe give example for the most used ones. If you want to grift instead of helping, go elsewhere.

2

u/AppointmentNearby161 26d ago

This is not a bug but a misunderstanding of how Linux/GNU works. The cp and sync commands 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).

0

u/activedusk 26d ago

From the GUI, when the file manager or some GUI notification/applet says copying is done, it should be done. 

The method and how that is handled under the hood should not concern the user.

From the terminal, if said buffer or cache is disabled, would cp, mv or dd command not also finish when the process finishes executing the command even without sync? If so it is a choice someone made for, assuming, performance reasons. Was historically a buffer always used, maybe cp, mv, dd require a separate package specifically because this improvement was done later.

1

u/AppointmentNearby161 26d ago

Was historically a buffer always used

At least as far back as the PDP 11.

The method and how that is handled under the hood should not concern the user.

You seem to have strong views on this and really want it to work in a way that 50+ years of Unix/Linux/GNU developers have decided against.

From the GUI, when the file manager or some GUI notification/applet says copying is done, it should be done.

The copying is done, the sync is not done. Someone could write a cp command that runs sync_filesystem(), but that requires a lot of design decisions. The two most obvious are when to sync (e.g., after all the files, each file, each block, or every bit) and what to sync (e.g., HDD, SSD, NVME, USB, loop devices).

Labeling a design decision as a bug will not get you very far. Creating an upstream feature request for a different type of copy in a GUI file manager might get you further if it is well thought out and clear.

1

u/activedusk 25d ago

Searched a bit, sync predates Linux which had from the start a copy first to RAM buffer/ cache data before transferring to destination for performance and deals with some less than ideal scenario, power loss, forced system reset, physically removing storage media before copying finishes. That said, found out, there are ways on Linux to bypass the cache, example using dd with oflag=direct, though it's not used universally due to issues, the ones that using a cache fixed, 0 cache direct copy operations are mainly used for benchmarking storage performance, databases and a few other niche applications.

Regardless, KDE have a solution for the GUI feedback to report when the copy is done, after it is done to destination. The problem with having the GUI use a form of sync only on Eject is that users do not think it's used to also finish the copy operation because the GUI told them "it's done", any form of safety they assume is for other things like electrical contacts or stopping any communication between device and storage so at that point it's just a formality and they will yank out the drive, any delay Eject produces will be considered a bug or system hanging (aka irrelevant and unrelated, low power mode who cares). Moving it to right click, context menu, copy and then paste (implied sync as well and reporting when it's done) makes the most sense and it is what KDE did eventually in 2026, finally.

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 sync and 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,

  • Full Arch install (involves large and small files) to an ordinary Sandisk flash drive takes >40min, then updates take a long time.
  • Same to a fast flash drive takes <5min consistently, and pacman updates fly.
  • Doing dd copies is also night and day faster, compared to ordinary flash drives.

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 sync in 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. 

11

u/d_ed 26d ago

The safely remove in KDE is fine. You don't need to type anything after (and it wouldn't make sense)

The "bug" is people not doing a safe remove.

-1

u/activedusk 26d ago

Would it work as intended with Dolphin installed as a flatpak or from repo and used with a tiling window manager for example and not Plasma? Flatpaks can and do have permissions limitations by design as default and installing it on a basic twm might lack the "infrastructure" or components.

Ideally it should work the same way everywhere, when it says it's done copying, it's done copying. People can and do often unplug afterwards without waiting and that is if they even make a habit out of clicking Eject, not getting the notification will often times be considered as "bug" instead of ongoing copying operation, until they get the corrupted or missing files that is and then they find out.

2

u/d_ed 26d ago

Ultimately it's a call to udisks, so it's fine everywhere (*1 *2)

*1 technically BSD doesn't have udisks, there's an abstraction layer

*2 you could filter it in a flatpak setup, dolphin doesn't, if it was filtered you wouldn't see the drive in the sidebar

4

u/ang-p 26d ago

OP is just fishing for scenarios..

Don't feed the help vampire / slop merchant...

Check their history.

-1

u/activedusk 26d ago

I did not make up the scenario, the youtube link lists it as a bug.

3

u/ang-p 26d ago

Your second problem is referencing Brodie Robertson vids...

-6

u/BlueGoliath 26d ago

Linux is mainstream ready. Year of the Linux desktop. Finally.