According to the rasbery pi documentation, You can load your OS to a flash card with either /dev/disk or /dev/rdisk.

rdisk stands for raw disk.

/dev/disk is a block level device, why would rdisk be 20 times faster?

Using Mac OSX

Note: In OS X each disk may have two path references in /dev: /dev/disk# is a buffered device, which means any data being sent undergoes extra processing. /dev/rdisk# is a raw path, which is much faster, and perfectly OK when using the dd program. On a Class 4 SD card the difference was around 20 times faster using the rdisk path.

  • 2
    As a side note, I ran a test and rdisk actually took much longer. – spuder Aug 13 '13 at 22:26
  • 4
    As another side note, I felt I had to test too then, and found that an rdisk copy (via dd) was almost exactly 4 times faster than using the disk counterpart. – Travis Griggs Jan 7 '14 at 17:57
  • @TravisGriggs I'm curious which OS, Mac or linux? – spuder Jan 7 '14 at 18:06
  • 2
    I thought "rdisk" was a typo in some instructions for a Raspberry Pi SD card image I was reading. Upon further investigation I googled the difference and found this thread. Turns out in my case it was 13 times faster to write a 1.7GB image to an SD card using /dev/rdisk instead of /dev/disk! Macbook Pro Retina 13", early 2015 model. – tobias.mcnulty Aug 1 '15 at 0:48
  • 2
    As yet another sidenote, I just dd'ed an Ubuntu ARM image to my newly purchased Sandisk Extreme Pro MicroSD card. /dev/disk1 wrote at 2.3 MB/s, while /dev/rdisk1 wrote at 83.7 MB/s, or 36.4 times as fast. – DanielSmedegaardBuus Mar 11 '16 at 17:07
up vote 84 down vote accepted

From man hdiutil:

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

In layman's terms /dev/rdisk goes almost directly to disk and /dev/disk goes via a longer more expensive route

  • 13
    why use disk when you can use rdisk? – user391339 Jan 4 '15 at 22:34
  • 14
    @user391339 Because caching is still a desirable thing. In cases where you have removable media, you want to get the data on the physical device as fast as possible, because you want the data in another physical location. Internal hard drives are a different story. You usually don't carry them around, so you don't care when the data is actually written to the device. When you cache data written to/read from devices that's a more expensive way of writing to the disk, but your programs are still faster, since they don't need to wait until all the data they want to write is written to the disk. – Kritzefitz May 12 '15 at 9:01
  • @Dan, Re "force"; meaning? – Pacerier Mar 3 at 0:19

The accepted answer is right, but it doesn’t go into much detail.

One of the key differences between /dev/disk and /dev/rdisk, when you access them from user space, is that /dev/disk is buffered. The read/write path for /dev/disk breaks up the I/O into 4KB chunks, which it reads into the buffer cache, and then copies into the user space buffer (and then issues the next 4KB read…). This is nice in that you can do unaligned reads and writes, and it just works. In contrast, /dev/rdisk basically just passes the read or write straight to the device, which means the start and end of the I/O need to be aligned on sector boundaries.

If you do a read or write larger than one sector to /dev/rdisk, that request will be passed straight through. The lower layers may break it up (eg., USB breaks it up into 128KB pieces due to the maximum payload size in the USB protocol), but you generally can get bigger and more efficient I/Os. When streaming, like via dd, 128KB to 1MB are pretty good sizes to get near-optimal performance on current non-RAID hardware.

The caching being done by /dev/disk’s read and write paths is very simple and almost brain dead. It caches even if not strictly necessary; like if the device could memory map and directly transfer into your app's buffer. It does small (4KB) I/Os, which leads to a lot of per-I/O overhead. It does not do any read ahead or write behind.

  • many thanks for the explanation in details. – gpanda Oct 12 at 16:22

It seems /dev/disk and /dev/rdisk works different for HDDs and SSDs. Wanna checked it for MicroSD card. Just wrote 2GB disk image to Sandisk Ultra MicroSD 64GB (https://www.amazon.com/gp/product/B073JYVKNX).

Repeated tests several times, but results were stable: 17MB/s for /dev/disk vs 20MB/s for /dev/rdisk. Changing bs=1m to bs=16m gives absolutely no difference in writing speed.

  1. Writing to /dev/disk2

    sudo dd if=~/Downloads/ubuntu-18.04-4.14-minimal-odroid-xu4-20180531.img of=/dev/disk2 bs=1m
    2094006272 bytes transferred in 121.860007 secs (17183704 bytes/sec)
    
  2. Writing to /dev/rdisk2

    $ sudo dd if=~/Downloads/ubuntu-18.04-4.14-minimal-odroid-xu4-20180531.img of=/dev/rdisk2 bs=1m
    2094006272 bytes transferred in 102.743870 secs (20380839 bytes/sec)
    

Then I decided to test reading speed: 26MB/s for /dev/disk vs 87MB/s for /dev/rdisk. Changing bs=1m to bs=16m gives absolutely no difference in reading speed.

  1. Reading from /dev/disk2

    sudo dd if=/dev/disk2 of=~/Downloads/ubuntu-18.04-4.14-minimal-odroid-xu4-20180531-2.img bs=1m
    257949696 bytes transferred in 9.895572 secs (26067184 bytes/sec)
    
  2. Reading from /dev/rdisk2

    $ sudo dd if=/dev/rdisk2 of=~/Downloads/ubuntu-18.04-4.14-minimal-odroid-xu4-20180531.img bs=1m
    877658112 bytes transferred in 10.021974 secs (87573377 bytes/sec)
    

For the record, in macOS High Sierra at least, /dev/disk appears to be much faster than /dev/rdisk. Running either dd or ddrescue, my throughput comparison copying from a magnetic HD to an SSD was 3.7MBps using /dev/rdisk, and 45MBps using /dev/disk. So, on later versions of macOS, it may be best to use /dev/disk instead of /dev/rdisk for best performance.

  • 2
    While writing a 4.6GB raspbian-stretch image from the internal SSD storage to an SD card with dd and a bs of 1MB /dev/rdisk still performs much faster than /dev/disk on a late 2013 macbook pro running macOS 10.13.2. It took 27.16 minutes using /dev/disk and only 5.18 minutes using /dev/rdisk. – digitaladdictions Jan 22 at 21:03
  • @digitaladdictions just made a few tests on latest macOS: superuser.com/a/1346063/126537 – k06a Aug 4 at 7:27

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.