Skip to content →

Solution: dd too slow on Mac OS X

When I was cloning SD cards on Mac OS X using `dd’, it takes ages to get things done. I was using the following command:

diskutil unmountDisk /dev/disk2
sudo dd bs=1m if=~/Downloads/2013-10-09.alice.img of=/dev/disk2

It takes much less time when using /dev/rdisk2 instead of /dev/disk2:

diskutil unmountDisk /dev/disk2
sudo dd bs=1m if=~/Downloads/2013-10-09.alice.img of=/dev/rdisk2

The reason is that rdisks are “raw” thus resulting in a higher R/W speed, according to `man hdiutil` [1]:

/dev/rdisk nodes are character-special devices, but are “raw” in the BSD sense and force block-aligned I/O. They are closer to the physical disk than the buffer cache. /dev/disk nodes, on the other hand, are buffered block-special devices and are used primarily by the kernel’s filesystem code.

[1] http://superuser.com/questions/631592/mac-osx-why-is-dev-rdisk-20-times-faster-than-dev-disk

Published in OS

58 Comments

  1. Greg Spenipp

    Incredible! Been banging my head on this for a couple hours now, thanks a bunch!

  2. Darkcaster

    Nice … always a good thing to know 😉 … and a lot of comments helps more =)

     

    Thx you all !

  3. Anonymous

    Life saver!

  4. Tim

    I’m dying from the slowness as well, but using the r trick isn’t working for me. I get the following error:

    dd: /dev/rdisk4: Invalid argument

    Any idea how to fix that?

  5. Mario

    Instead of pv or any other commands you could simply use ‘CTRL + T’ to get the bytes progress.

  6. Mikhail

    Thanks a lot!

    Another tip for OSX (High Sierra) to check status during the process (pv not installed).

    In another Terminal window:

    sudo kill -INFO $(pgrep ^dd)

     

  7. thank you

    818+0 records in
    818+0 records out
    857735168 bytes transferred in 75.526248 secs (11356782 bytes/sec)

     

  8. parabolan

    legendary pro tip, much appreciated

  9. Dixon Dick

    Thank you! Four years later, still a useful tip.

  10. Thanks for the tune-up! Much appreciated advice. 20x increase in performance. By prepending an ‘r’. Who knew…

  11. 3299514 bytes/sec
    vs
    15451963 bytes/sec
     

    Thanks a lot! 🙂

  12. bail(){
    echo “Usage: $0 source destination”
    exit 1
    }

    nofile(){
    echo “Usage: $0 source destination – path invalid”
    exit 1
    }

    [[ -z “$1” || -z “$2” ]] && bail
    [[ ! -e “$1” || ! -e “$2” ]] && nofile

    read -p “Are you sure? Y/[N] ” -n 1 -r
    echo # (optional) move to a new line
    [[ ! $REPLY =~ ^[Yy]$ ]] && exit 1

    BLKSZ=1048576
    FSZE=$(stat -f “%z” $1)
    su root -c “dd bs=$BLKSZ if=$1 | pv -s $FSZE | sudo dd of=$2 bs=$BLKSZ”

  13. Apple:~ apple$ sudo dd if=/Users/apple/Desktop/2017-07-05-raspbian-jessie-lite.img of=/dev/rdisk1 bs=1048576
    Password:
    load: 0.59 cmd: dd 1621 uninterruptible 0.00u 0.92s
    1130+0 records in
    1129+0 records out
    1183842304 bytes transferred in 2143.597669 secs (552269 bytes/sec)

    size of jessie -> 1,72,56,29,563 bytes (1.73 GB on disk)

  14. Dill

    Big hug !

  15. Anonymous

    Thank you!

  16. Wow. That one character makes a HUGE difference. My DD job went from 3 hours to 5 minutes. Thank you!

  17. Salvatore Restuccia

    Amazing!! 84MB/S Thank you!!!!!

     

  18. Anonymous

    Thank you very much, it works like a charm!

  19. Ken H.

    Nm, I just found out what I did wrong.  I realized that my sd card changed to disk6 instead of disk5.  Doh

  20. Ken H.

    Sorry for the newbie question, but I keep getting a “dd: /dev/rdisk5: Operation not permitted”  when I enter “sudo dd bs=1m if=/Users/me/Desktop/file.img of=/dev/rdisk5”  Not sure what I’m doing wrong.

  21. Rainer S.

    Bonus: for those who use pv for getting a progress meter:
    Use dd from gnu coreutils (both macports and homebrew should have it) and then append

    status=progress

    to your command.

  22. Brian

    Wohoo!!  45MB/s!!!  Thanks!

  23. Name

    Soooo much better – thanks!

  24. Big data

    谢谢分享!

  25. Jon

    Holy Crap!

    Sustained io writes @ 7mb/s!!

    Thank you!!!

  26. darkfader

    Same for databases (like 50%+ faster running off raw devices) but rarely used there because there’s too high chance junior sysadmins / devs will confuse your database storage for empty disks 🙁

  27. John Doe

    Damn I read this too late, now I won’t kill the process because the whole image is “only” 3,3 GB:

    sudo killall -INFO dd

    2459+0 records in
    2458+0 records out
    2577399808 bytes transferred in 5596.141697 secs (460567 bytes/sec)

     

  28. Shane

    AWESOME! You just made my day with this.

  29. Petersen

    Xie xie hen hao!!

     

  30. jdoubleu

    Thanks a lot !!
    Here with pv command to see the copy progress ?
    dd bs=1m if=~/Downloads/20131009.alice.img | pv | sudo dd bs=1m of=/dev/rdisk2

    I’d use:
    sudo -s — “dd bs=1m if=imagefile.img | pv | dd bs=1m of=/dev/rdisk2”
    Because you have to run dd with root privileges.

  31. Kamal

    What a great Tip

  32. Mark

    WOW, this made all the difference it the world!! add the pv command (not needed as much now due to how fast it is) and I can get back to work.

  33. Anonymous

    Amazing.. I was spending hours and it was killing me

  34. Anonymous

    Thanks a lot !!
    Here with pv command to see the copy progress 😉
    dd bs=1m if=~/Downloads/20131009.alice.img | pv | sudo dd bs=1m of=/dev/rdisk2

  35. Anonymous

    Thanks a lot man!!! You saved my life!!!!

    I have a fast external disk that I want to backup to the local MAC disk and an USB 3.0 SATA adapter and got only 30 Mbytes/s.

    Now is 300Mbytes/s!!!!!

     

    Thanks!!!!

    Thanks!!!!

    Thanks!!!

  36. Christophe Nouvel

    So I can keep my Mac and don’t throw it away! Thanks a LOT, x16 speed on a USB stick!

     

  37. Anonymous

    This is huge! Thanks!

  38. test

    thanks

  39. Eik

    Thanks man. You prolonged my life 😉

  40. Jeffrey

    Thank you very mutch saved me mutch time 🙂

  41. Paul

    You Sir, just made my day. This clever trick just speed up dd from 1MB/s to almost 7MB/s

  42. I have been looking for a way to do this for ages 😀

  43. Stuart

    I think I love you. Thank you so much for this!

  44. Great tip.  Thanks.  Amazing speed increase.

  45. fred

    Thnx !!

    After more then 10 hours writing to a sd cancelled it,

    Now done in a couple of minutes

  46. Joern

    3284139520 bytes transferred in 19705.137328 secs (166664 bytes/sec)

    vs

    3284139520 bytes transferred in 255.784407 secs (12839483 bytes/sec)

     

    Thanx! 🙂

  47. Waldemar Barbe

    Thank you! 🙂

  48. Gonzo Fialho

    Wow, that improved my life 100%
    Thanks for sharing

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.