Skip to content

Instantly share code, notes, and snippets.

@2E0PGS
Last active February 20, 2025 20:55
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

@rktomz
Copy link

rktomz commented Mar 1, 2024

@guy-teube use - sudo su

@webolot
Copy link

webolot commented Mar 27, 2024

Works! Thank's @2E0PGS !

@AdnanTemur
Copy link

If someone still has the copying issue, they can use Grsync, a gui app of rsync.
sudo apt update
sudo apt install grsync

@msenol86
Copy link

msenol86 commented Feb 15, 2025

The year is 2025 and Linux cannot still manage to move files from local drive to usb efficiently. Instead of 20 different desktop environment we need to solve these base problems.

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

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