Skip to content

Instantly share code, notes, and snippets.

@draekko
Forked from 2E0PGS/linux-usb-file-copy-fix.md
Last active February 15, 2023 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save draekko/2ce7c38619c77cba5a3512ca53842ae6 to your computer and use it in GitHub Desktop.
Save draekko/2ce7c38619c77cba5a3512ca53842ae6 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: https://unix.stackexchange.com/questions/107703/why-is-my-pc-freezing-while-im-copying-a-file-to-a-pendrive/107722#107722

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

For this to be persistent on Ubuntu add the following to my /etc/sysctl.d/99-sysctl.conf file.

vm.dirty_bytes=50331648
vm.dirty_background_bytes=16777216

original gist @ https://gist.github.com/2E0PGS/f63544f8abe69acc5caaa54f56efe52f

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