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

@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

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

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

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

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

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

Thank you!

@blackrose514
Copy link

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

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?

@FedericoCalzoni
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)

@Screak42
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/

@jaytohe
Copy link

jaytohe commented Dec 29, 2022

Based fix. Works!

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

@kovacspityu
Copy link

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

@smithmoh
Copy link

sudo sysctl -w vm.dirty_bytes=50331648

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

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