Skip to content

Instantly share code, notes, and snippets.

Last active May 11, 2024 06:48
Show Gist options
  • Save 2E0PGS/f63544f8abe69acc5caaa54f56efe52f to your computer and use it in GitHub Desktop.
Save 2E0PGS/f63544f8abe69acc5caaa54f56efe52f to your computer and use it in GitHub Desktop.
Fix Ubuntu and other Linux slow/hanging file copying via USB.

If your running a x64 bit Ubuntu or other Linux and find USB transfers hang at the end apply this fix:

echo $((16*1024*1024)) > /proc/sys/vm/dirty_background_bytes
echo $((48*1024*1024)) > /proc/sys/vm/dirty_bytes

I suggest you edit your /etc/rc.local file to make this change persistant across reboots.

sudo nano /etc/rc.local

Go to the bottom of the file and leave a space then paste in those two lines.

Save the file with ctrl + x then press y.

To revert the changes enter this in console and remove the lines in /etc/rc.local

echo 0 > /proc/sys/vm/dirty_background_bytes
echo 0 > /proc/sys/vm/dirty_bytes

More info and references:

Copy link

el-beth commented Apr 29, 2021

At the core of this problem is an unjustifiably low speed while, typically, writing to USB2.0 thumb drives. All these solutions appear to provide is an honest reporting of the -still sluggish- transfer progress and nothing to address the diminished speeds. What can one do about the low transfer speed?

Copy link

ghost commented Jul 22, 2021


Copy link

kiocosta commented Sep 4, 2021

I'm amazed at how Linux can fail to perform such basic tasks... This is ridiculous.

Copy link

altmsk commented Sep 5, 2021

thank you 😃

Copy link

Thanks a lot!

Copy link

reisept commented Nov 10, 2021

It's fucking 2020 and this problem has been around since 2014...Why the fuck hasn't this been fixed yet?

You literally can't transfer files over 4GB on to USB in 64bit Linux without this fix right now.

It's 2021 and still I have this problem! Later I will test the workaround to see if it's the problem that I have....

Copy link

Thank you!

Copy link

mfacen commented Mar 23, 2022




For instance in my Mint system
Open a terminal and use nano text editor with root permission, type:
sudo nano /etc/sysctl.d/*99-sysctl.conf
Introduce your password
Scroll to the end of the file and paste :
at the and of it, press ctrl-S to save and then ctrl-X to quit nano.
Thats it you are done.
Depending on the flavor of linux there are other console text editors you can use to modify that file, but being a system file you can not modify it until you provide the administrator password.
I hope this helps a little.

Copy link

nhasbun commented Apr 21, 2022

Shocked to see this is an issue under Linux.

Using Kubuntu I had this issue today and arrived here. What exactly that line does and what could be their side effects?

Copy link

mkeyCZ commented Apr 27, 2022

I got it fixed. Thank you

Copy link

MarcGuay's fix worked for me on Ubuntu 22.04. Before, I was unable to copy a 1.7GB file to a FAT-based USB stick. (Or at least, it seemed stuck. I didn't wait long for it to finish.)

Copy link

Pillgar commented Jul 13, 2022

Anyone know, does this fix effect all storage devices on the system, or just the USB one's?

Copy link

for those who dont have /etc/rc.local can use this: sudo sysctl -w vm.dirty_bytes=50331648 sudo sysctl -w vm.dirty_background_bytes=16777216

It seems to have fixed the issue. (Arch Linux)

Copy link

Screak42 commented Oct 16, 2022

I have tried "various" approaches, even completely disabling swap without any change. copying large files (and large amounts of files) to a USB exfat spinning HDD-drive freezes the system beyond usability. (POP_OS, asus TUF gaming, 16gigs of ram, 512 nvme)
Very frustrating. Funny enough - and I have no logical explanation, this does NOT happen to an exfat formatted SSD-USB. same USB enclosure, so not even the firmware of the case can be the problem. I don't even know where to start troubleshooting this anymore.

to add value to my rant; I found that gcp and rsync work flawlessly and fast, without causing a freeze / hog.
I used these two successfull for a large amount of files & large files (my 900gb steam library)

$ gcp -rv /whatever/* /some/other/place/

$ rsync --info=progress2 -auvz /whatever/* /some/other/place/

Copy link

jaytohe commented Dec 29, 2022

Based fix. Works!

Copy link

How on earth this still exist for basic task.. i thought this only happen on my Manjaro arch based linux, then its happen in Ubuntu also. This is sooooo frustrating.

Copy link

It works! Lubuntu 22 LXQt, 64GB USB, exFAT. THX!!!

Copy link

sudo sysctl -w vm.dirty_bytes=50331648

what about to remove it ..which code can i use

Copy link

CarnedeTun commented May 31, 2023

Same issue here. I decided to switch from Ubuntu to Mint recently. Now I am on Linux Mint 21.1 Vera - and still have this problem. Cannot believe it is still there. I am still a nuub and do not feel comfortable editing /etc/rc.local file. I will try to format USB as exFAT. Hopefully, that will work out.

Copy link

morvael commented Jul 31, 2023

This is ridiculous. Linux can't handle USB disks 🤦‍♂️. In case of my system setting kernel dirty parameters do not help at all. I get total system freeze within 10-15 seconds of initiating copying files from USB drive to local drive. Seeing how entire Ubuntu family may be compromised, is there a Linux distro that doesn't have such problem?

Copy link

Fuck it, I have been having the same damn problem since three bloody days!

Copy link

lz237 commented Sep 22, 2023

Still facing this problem today, unbelievable. And I have to use this setting suggested by Linus in 2013 to fix my system in 2023.

Copy link

DBryzz commented Oct 31, 2023

Why is Linux so slow in copying files ? Over the years it has been an issue. I don't get it.

Copy link

I'm not sure but suggested solution is just the placebo... nothing changed much...

Copy link

DBryzz commented Nov 10, 2023

I'm not sure but suggested solution is just the placebo... nothing changed much...

Nothing at all 😂

Copy link

I'm not sure but suggested solution is just the placebo... nothing changed much...

Nothing at all 😂

It did for me.

Copy link

J-khatri commented Dec 1, 2023

I'm not sure but suggested solution is just the placebo... nothing changed much...

Nothing at all


I did not get your point ... does it work... or I'm right ( its placebo ) :-)

Copy link

$ echo $((16*1024*1024)) > /proc/sys/vm/dirty_background_bytes
bash: /proc/sys/vm/dirty_background_bytes: Permission non accordée

$ echo $((48*1024*1024)) > /proc/sys/vm/dirty_bytes
bash: /proc/sys/vm/dirty_bytes: Permission non accordée

Is sudoing these commands safe? (Ubuntu 22.04)

Copy link

rktomz commented Mar 1, 2024

@guy-teube use - sudo su

Copy link

webolot commented Mar 27, 2024

Works! Thank's @2E0PGS !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment