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

@msenol86
Copy link

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.

I have tried both NTFS and exFat. The result is same.

@linuxtavarez
Copy link

linuxtavarez commented Feb 15, 2025 via email

@msenol86
Copy link

I came to the conclusion that the problem is directly related to the slow device/USB controller. After switching to a more powerful laptop and faster USB storage, I no longer have issues.

On Sat, Feb 15, 2025, 5:32 PM Mucahit Senol @.> wrote: @.* commented on this gist. ------------------------------ 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. I have tried both NTFS and exFat. The result is same. — Reply to this email directly, view it on GitHub https://gist.github.com/2E0PGS/f63544f8abe69acc5caaa54f56efe52f#gistcomment-5440809 or unsubscribe https://github.com/notifications/unsubscribe-auth/BD4IVPECREHJABHD5EQPBS32P6XANBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVA2DMMBQGIZTMMVHORZGSZ3HMVZKMY3SMVQXIZI . You are receiving this email because you commented on the thread. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub .

No same machine with same usb drive. I can move files on Windows in 1-2 minutes and shut down the system. On Linux it took 30 minutes and I cannot eject the system succesfully. Both NTFS and exFat will gave same result.

@NazimAliev
Copy link

Great! My Ubuntu 22.04 with 32 Gb RAM freezes every time when I tried to copy to usb3 drive. The issue is resolved now

@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