Skip to content

Instantly share code, notes, and snippets.

@2E0PGS
Last active July 3, 2025 12:52
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: https://unix.stackexchange.com/questions/107703/why-is-my-pc-freezing-while-im-copying-a-file-to-a-pendrive/107722#107722

@rgaufman
Copy link

rgaufman commented Jul 3, 2025

This is so bizarre, when I run:

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

My CPU drops from 100% to 50% for a little while and then goes back up to 100% when I guess the dirty_bytes buffer fills up. This is writing to a slow USB eternal drive. So SURELY it should show IO wait, and the 50% load is just IO wait, but no, sudo top shows:

top - 13:52:06 up 11 min,  2 users,  load average: 10.64, 7.35, 4.31
Tasks: 385 total,  10 running, 375 sleeping,   0 stopped,   0 zombie
%Cpu(s):  6.5 us, 25.8 sy, 66.7 ni,  0.0 id,  0.0 wa,  0.0 hi,  1.0 si,  0.0 st
MiB Mem :   7235.0 total,   1591.9 free,   2961.4 used,   3033.9 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.   4273.6 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
    922 deployer  35  15 3226472 453824  23296 S  16.2   6.1   2:10.62 ruby
  78721 deployer  39  19  448872 100736  77824 S   8.3   1.4   0:00.25 ffprobe

What on earth is going on!!

Linux 6.8.0-63-generic #66-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 13 20:25:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

on  Intel(R) N100

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