LoginSignup
60

More than 5 years have passed since last update.

ddコマンドのbsサイズ

Last updated at Posted at 2016-08-02

ddコマンドを使って、イメージファイルをsdcardとかに書き込む際に、bsオプションを使ってバッファリングサイズを調整すると、早くなります。
(参考:dd コマンドの bs の値の意味を詳しく教えてください。)

いくつにするのがいいのか、というのを、いつも忘れてしまうので、調べるスクリプトを貼っておきます。
元のソースコードは server fault - How to determine the best byte size for the dd commandより。

#!/bin/bash
#
#create a file to work with
#
echo "creating a file to work with"
dd if=/dev/zero of=/var/tmp/infile count=1175000

for bs in  16m 32m 64m 128m 256m 512m

do
        echo "---------------------------------------"
        echo "Testing block size  = $bs"
        dd if=/var/tmp/infile of=/var/tmp/outfile bs=$bs
        echo ""
done
rm /var/tmp/infile /var/tmp/outfile

私のMac Miniではこんな感じでした。いつもbs=32mで指定していましたが、bs=16mのが早いわけですね。

$> ./test_dd_bs.sh 

creating a file to work with
1175000+0 records in
1175000+0 records out
601600000 bytes transferred in 3.716253 secs (161883487 bytes/sec)
---------------------------------------
Testing block size  = 16m
35+1 records in
35+1 records out
601600000 bytes transferred in 1.312157 secs (458481751 bytes/sec)

---------------------------------------
Testing block size  = 32m
17+1 records in
17+1 records out
601600000 bytes transferred in 1.512825 secs (397666614 bytes/sec)

---------------------------------------
Testing block size  = 64m
8+1 records in
8+1 records out
601600000 bytes transferred in 1.472201 secs (408639823 bytes/sec)

---------------------------------------
Testing block size  = 128m
4+1 records in
4+1 records out
601600000 bytes transferred in 1.510589 secs (398255218 bytes/sec)

---------------------------------------
Testing block size  = 256m
2+1 records in
2+1 records out
601600000 bytes transferred in 1.574169 secs (382169855 bytes/sec)

---------------------------------------
Testing block size  = 512m
1+1 records in
1+1 records out
601600000 bytes transferred in 1.684105 secs (357222349 bytes/sec)

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
60