巨大ファイルを作成する
巨大なファイルを高速に作るメモ。
実行結果はさくらのVPS 1GにUbuntu 12.10を入れた環境でのものです。
中身をゼロで埋める場合
埋めるというか空っぽのsparse fileですが。
$ time dd if=/dev/zero of=temp.bin bs=1 count=0 seek=1G0+0 records in0+0 records out0 bytes (0 B) copied, 1.1289e-05 s, 0.0 kB/sdd if=/dev/zero of=temp.bin bs=1 count=0 seek=1G 0.00s user 0.00s system 0% cpu 0.002 total
比較用
真面目に書き込む場合の結果です。
$ time dd if=/dev/zero of=temp.bin bs=1G count=11+0 records in1+0 records out1073741824 bytes (1.1 GB) copied, 29.3218 s, 36.6 MB/sdd if=/dev/zero of=temp.bin bs=1G count=1 0.00s user 10.84s system 36% cpu 29.666 total
中身をランダムにする場合
擬似乱数でも気にしないのであれば、/dev/random
や /dev/urandom
を流し込むより openssl rand
コマンドを使うのがいいみたいです。
$ time openssl rand 1073741824 > temp.binopenssl rand 1073741824 > temp.bin 35.07s user 1.35s system 99% cpu 36.524 otal
比較用
/dev/urandom
を流し込んだ場合の結果です。
$ time dd if=/dev/urandom of=temp.bin bs=1G count=11+0 records in1+0 records out1073741824 bytes (1.1 GB) copied, 134.728 s, 8.0 MB/sdd if=/dev/urandom of=temp.bin bs=1G count=1 0.00s user 105.87s system 78% cpu 2:14.98 total