Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The copy dialogue is stuck at 0 seconds left...

Whenever I try to copy big files to my USB pendrive (in any format), it always stops at the last moment. It finishes after a long time.

I searched Ask Ubuntu for similar Posts and got many, but none of them have good solutions.

So... Is there any alternative copying tool like Teracopy on Windows?

Or are there any fixes I can do?

Enter image description here

share|improve this question
    
Also please let me know what files I should Upload for reference – Severus Tux Feb 6 at 15:37
2  
Not really sure, but I strongly assume your problem is related to the USB write caching. Search for posts on how to disable that. The entire copying process will appear slower then, but it should be really finished when it looks finished then. – Byte Commander Feb 6 at 15:40
    
@ByteCommander By slower, Do you mean actual speed?? – Severus Tux Feb 6 at 15:44
2  
I am not too familiar with that topic, but the caching just keeps the data you want to write to your USB device in memory and actually writes it later, when it thinks the bus or devices are less busy, or when it can optimize the way to save data blocks together... This should not improve the actual physical write speed (much), it will just appear faster to you, because the copying process reports to be finished as soon as all data to write is in the cache. But it still takes more time to write the cache to the device. You could not immediately unplug it anyway before the cache has been written – Byte Commander Feb 6 at 15:48
    
Yes, the actual copy speed would be the same (perhaps slightly slower because the buffer makes it less likely that there will be a moment when nothing is being written to disk, but not much on a lightly-loaded system), but the progress dialog would be more accurate. – hobbs Feb 6 at 23:40
up vote 14 down vote accepted

You should not worry about this too much.
Maybe your USB pendrive is of "lower quality".
The dialog output regarding the time is misleading.

Other copy tools may have a different output behavior,
but they do not improve the writing speed of the USB drive.
Most important of all is that finally the copy action succeeds.

What you can do is optimizing the input/output schedulers of disks.

Install gksu (when you haven't already) to edit files with gedit as root :

sudo apt-get install gksu  

Now optimize the priority of all running processes for various disks types :

gksudo gedit /etc/udev/rules.d/60-schedulers.rules

Paste the following lines into this empty file and save the file afterwards :

# set cfq scheduler for rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="cfq"

# set deadline scheduler for non-rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="deadline"  

The changes you made take effect after a restart of the operating system.

Also ... an alternative copy solution is available in the Ubuntu repositories :

sudo apt-get install dirdiff  

Now launch the tool from a terminal to compare or copy files and folders :

dirdiff

dirdiff is a GUI for diff and can handle up to 5 trees. It displays a main window with a list of files which are different between the trees, with colored squares to indicate the relative ages of the versions. A menu allows you to display the differences between any two of the versions in another window. Another menu allows you to copy files and folders from one tree to another.

Summary : Most relevant of all is the quality of the USB disk and its writing speed capabilities !

share|improve this answer

The reason that you see the copying happening the way you do is that writes to the USB drive are asynchronous.

When you copy a file it actually copies it in to the usb drive's buffer, which is in the RAM of your computer. The first part of the copy is very fast because it is just going in to the buffer. The data is flushed from the buffer to the USB drive at a much slower rate. Once the buffer has filled up it has to wait for some of the data to be flushed to disk before it can place any more in the buffer, so the copy then slows right down, effectively to the speed of the USB drive. Once all the file has been placed into the buffer it appears that the file has been copied. However not all the data has been flushed from the buffer onto the USB disk itself. Some copy programs just return and let that flushing carry on in the background. Some will wait until all the data has been flushed, which is why it will stay on 100% for some time.

You can switch the disk into synchronous mode which means that all data is immediately written to the USB drive without using the buffer. This will give the impression of a smoother transfer of data, but may actually end up with an overall reduction of speed.

If you manually mount the disk from the command line you can add -o sync.

If you mount it using fstab you can add the sync option.

If you rely on Ubuntu mounting it for you when you access it in the GUI you can modify the mount options from the command line once it is mounted:

sudo mount -o remount -o sync /media/yourname/diskname
share|improve this answer
1  
This is the answer. – kos Feb 12 at 9:22

The problem is likely that the file is read and stored in memory completely before it's completely written to the target drive.

This doesn't mean to answer the question exactly, but a workaround could be using pv from the command line in case of big files:

sudo add-apt-repository universe && sudo apt-get update && sudo apt-get install pv

Whenever one needs to copy a big file:

pv /path/to/big_file >/media/username/usb/big_file

To be noted that this suffers from a similar unwanted buffering problem when used in a pipe; if that's the case a fix is limiting the transfer rate to something slightly above the target drive's write speed:

[...] | pv -L 10M >/media/username/usb/big_file # Limits the transfer rate to 10 MB/s
share|improve this answer

There are a number of alternatives. You could use the command line approach:

cp *source* *target*

where source is the file you want to copy and target is the file or folder you wish to copy to. Further options might be found at http://softwarerecs.stackexchange.com/

share|improve this answer
dd if=INPUT_FILE_PATH of=OUTPUT_FILE_PATH bs=$(( 64 * 1024 * 1024 )) oflag=sync

This will read from your if file and write to of file in 64MiB chunks and wait until each chunk is written out before starting the next one. The utility you are using is most likely just reading the file into memory and then sending it to the disk (and there is no telling how many bytes at a time it's doing it). The write caching can be in the usb dongle itself though.... So the 60MiB per second speed that you are getting is the transfer rate over the usb connection to the dongle's internal cache. But that's not likely unless it's a USB3 dongle. USB2 doesn't have enough throughput to handle 60MiB per second.

share|improve this answer

There is no need for all the above. Simply open a terminal window when the transfer is showing 0% left and type sync From the man pages, the sync command flushes the file system buffers, but of course it will only flush those to which you have the rights. If you want to flush them all type sudo sync

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.