Mac OS X と Linux での dd パフォーマンス

Mac OS X と Linux での dd パフォーマンス

ディスクを焼かないように、Windows インストーラーの ISO をハード ドライブにコピーしようとしていました。最初にディスク ユーティリティの復元機能を試しましたが、何らかの理由で ISO がうまくいきませんでした。次に、dd を使用してみました。

dd if=/path/to/image.iso of=/dev/disk3

ファイルのコピー速度が 160 KB/秒と非常に遅いことに気付きました。Linux インストールを再起動して、ほぼそのままのコマンドを再度実行しました。

dd if=/path/to/image.iso of=/dev/sdc

今回は、コマンドは 1 分以内に実行され、平均速度は 57 MB/秒でした。どちらの場合も、ソースと宛先は同じ物理ハード ドライブでした。何が起こっているのでしょうか。

OSX 10.7.3 と Linux 2.6.38-13 を実行しています。

答え1

OS Xの場合は、 を使用します/dev/rdisk3

何らかの理由で はrdiskよりも高速ですdisk。これはバッファに関係していると思います。

また、一般的にbsフラグを使用するとdd速度が向上します。

dd if=/path/to/image.iso of=/dev/sdc bs=1M

1mバイトサイズは 1M で、転送速度が速くなります。OS X では、 の代わりに (小文字)を使用する必要があります1M

答え2

BSD RAW ディスク

BSD には一般に、バッファ付きとバッファなし (raw) の 2 種類のディスク デバイスがあります。hdutil(1)マニュアル ページから引用します。

DEVICE SPECIAL FILES
     Since any /dev entry can be treated as a raw disk image, it is worth
     noting which devices can be accessed when and how.  /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.

     It is not possible to read from a /dev/disk node while a filesystem
     is mounted from it, ...

2番目の段落のため、ディスクはマウント解除dd「raw モード」で使用できるようにします。

dd ブロックサイズ

dd(1)manページより:

     Where sizes are specified, a decimal, octal, or hexadecimal number of bytes
     is expected.  If the number ends with a ``b'', ``k'', ``m'', ``g'', or ``w'',
     the number is multiplied by 512, 1024 (1K), 1048576 (1M), 1073741824 (1G) or
     the number of bytes in an integer, respectively.  Two or more numbers may be
     separated by an ``x'' to indicate a product.

デフォルトのブロックサイズは 512 バイトです...

関連情報