Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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: https://unix.stackexchange.com/questions/107703/why-is-my-pc-freezing-while-im-copying-a-file-to-a-pendrive/107722#107722

@SaltyPaws
Copy link

SaltyPaws commented Dec 4, 2019

This fix did not fully work for me. After I applied the fix, I would still experience machine freeze but less frequently. What did work was disabling the swap file. I first tried increasing the swap file to 64 GB, this did not work, I then disabled the swap file altogether. I am on a dual CPU server with 32 GB memory. I did run memtest extensively, so I know it is not a memory issue. I did copy from exFAT 2 TB system (via usb) to ZFS Z2 6x10TB array.

@stdonato
Copy link

stdonato commented Dec 12, 2019

SaltyPaws, disable swap works fine. Thanks.

@fharookshaik
Copy link

fharookshaik commented Jan 30, 2020

It didn't worked with my system.
my system is of 8gb ram,intel i5-8300H running on ubuntu 18.04.3 and the external storage is 2TB Seagte UltraSlim Hardisk

@roeniss
Copy link

roeniss commented Mar 20, 2020

with 32 RAM, 128 SSD, 16 USB, It worked.

but I really wonder what exactly this two lines do. Anyway Thankyou.

@KarthikKavinA
Copy link

KarthikKavinA commented Apr 5, 2020

Thank you very much.
It works better for Ubuntu 18.04.3

@axdeveloper
Copy link

axdeveloper commented May 20, 2020

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

@RS0307
Copy link

RS0307 commented Sep 1, 2020

I AM NEW ON UBANTU CAN ANYONE PLEASE TELL ME FROM ZERO STEP BY STEP TO DO ALL USB HANG ANSWERS
I HAVE ALSO THIS ISSUE BUT I AM NOT GETTING HOW TO FIND /ETC/RC.LOCAL

CAN ANYONE HELP ME

@RS0307
Copy link

RS0307 commented Sep 1, 2020

I AM NEW ON UBANTU CAN ANYONE PLEASE TELL ME FROM ZERO STEP BY STEP TO DO ALL USB HANG ANSWERS
I HAVE ALSO THIS ISSUE BUT I AM NOT GETTING HOW TO FIND /ETC/RC.LOCAL

CAN ANYONE HELP ME

@RS0307
Copy link

RS0307 commented Sep 1, 2020

It worked just fine, thank you so much!

After searching a lot in different sources, this was the only answer to actually work.
I use Linux Mint 18.

can you please tell me how to do

@Lumumba
Copy link

Lumumba commented Oct 3, 2020

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

is this persistent or do i have to apply this every boot?

@MarcGuay
Copy link

MarcGuay commented Nov 26, 2020

For this to be persistent on Ubuntu 18.04 I had to add the following to my /etc/sysctl.conf file.

vm.dirty_bytes=50331648
vm.dirty_background_bytes=16777216

@Bewbman
Copy link

Bewbman commented Dec 25, 2020

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.

@polkaulfield
Copy link

polkaulfield commented Jan 20, 2021

finally i found this, thank you man

@JoanLlu
Copy link

JoanLlu commented Mar 7, 2021

Bewbman nailed it.
Still a long way to go for Linux.

@Lumumba
Copy link

Lumumba commented Mar 13, 2021

MarcGuay thank you

@junguler
Copy link

junguler commented Apr 7, 2021

thanks for this, i had issues with usb sticks being read-only and very slow speeds, now i think with this fix and opening my file manager (krusader) in root mode my problems are hopefully fixed.

update: i have managed to fix my issues copying files to usb stick with the help of this page and also formatted the usb stick with gnome disk, it's not a big deal for me as i'm the tinkerer type but things like this might make people think twice about switching to linux and i think saner defaults are needed.

@Whytecrowe
Copy link

Whytecrowe commented Apr 16, 2021

Thanks so much man! Saved my day!

@el-beth
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?

@dagim360
Copy link

dagim360 commented Jul 22, 2021

leave

@kiocosta
Copy link

kiocosta commented Sep 4, 2021

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

@altmsk
Copy link

altmsk commented Sep 5, 2021

thank you 😃

@kdkanishka
Copy link

kdkanishka commented Oct 2, 2021

Thanks a lot!

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

@alirzaev
Copy link

alirzaev commented Nov 15, 2021

Thank you!

@blackrose514
Copy link

blackrose514 commented Jan 26, 2022

In my case (Arch Linux), I had to create a file at /etc/sysctl.d/99-sysctl.conf and add these 2 lines to be persistant across reboots

vm.dirty_bytes=50331648
vm.dirty_background_bytes=16777216

@mfacen
Copy link

mfacen commented Mar 23, 2022

I AM NEW ON UBANTU CAN ANYONE PLEASE TELL ME FROM ZERO STEP BY STEP TO DO ALL USB HANG ANSWERS

I HAVE ALSO THIS ISSUE BUT I AM NOT GETTING HOW TO FIND /ETC/RC.LOCAL

CAN ANYONE HELP ME

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 :
vm.dirty_bytes=50331648
vm.dirty_background_bytes=16777216
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.

@nhasbun
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?

@mkeyCZ
Copy link

mkeyCZ commented Apr 27, 2022

I got it fixed. Thank you

@nolanlawson
Copy link

nolanlawson commented Jun 11, 2022

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

@Pillgar
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?

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