Total Pageviews

Wednesday, 8 August 2018

在mac中加快dd命令的运行速度


在用dd命令,将一个SD卡复制到另一个SD过程中,发现速度非常慢。
1
2
3
sudo diskutil unmount /dev/disk2s1
sudo diskutil unmount /dev/disk3s1
sudo dd bs=1m if=/dev/disk2  of=/dev/disk3
然后在另一个shell中运行命令可以查看进度情况:
1
2
3
4
5
6
sudo pkill -INFO dd   # mac系统
sudo killall -USR1 dd # linux系统
 
3+0 records in
2+0 records out
20971520 bytes transferred in 39.393646 secs (532358 bytes/sec)
还有另外几种查看进度的方法:
1
CTRL + T
Sends SIGINFO to the process. This is a BSD feature OS X inherited. You must have the terminal window executing dd selected when entering CTRL + T for this to work.
1
pv -tpreb /dev/sda | dd of=/dev/sdb bs=1M
Your platform may not have pv by default. If you are using Homebew on OSX, simply ‘brew install pv’.
1
while pgrep ^dd; do pkill -INFO dd; sleep 10; done
While a dd is running in one terminal, open another and enter the while loop. The sample output will be displayed in the window running the dd and the while loop will exit when the dd is complete. It’s possible that a “sudo” will need to be inserted before “pkill”, depending on your setup, for example:
1
while killall -USR1 dd; do sleep 5; done
Stops when the (last) dd process exits.
我这样用dd一个多小时后,8G大小的SD卡才复制2G多一点。觉得太慢了,然后上网查了怎么speed up,有人说加大bs=1m这个参数会有作用:
Adjusting the bs parameter can increase the speed, for example, I have 2 HDD that I know have a read/write speed greater than 100 MB/s so I do this:
1
dd if=/dev/sda of=/dev/sdb bs=100M
There is also pv (Needs to be installed first) that checks for the fastest speed on both drives and then proceeds on cloning. This has to be done of course from root:
1
pv < /dev/sda > /dev/sdb
参考 :http://askubuntu.com/questions/523037/how-would-i-speed-up-a-full-disk-dd
当我调整bs=1m,到bs=10m时,再次试验 ,发现速度根本没有太大变化。
后来再找资料,发现跟mac系统本身有关系。把 /dev/disk2 修改成 /dev/rdisk2 就会快了。

参考 :http://apple.stackexchange.com/questions/56159/how-can-i-speed-up-sd-card-writing-speed-using-dev-disk-on-a-macbook-pro
参考 :http://daoyuan.li/solution-dd-too-slow-on-mac-os-x

下面这样会快上几十倍:
1
2
3
4
5
6
7
8
9
10
sudo dd bs=10m if=/dev/rdisk2  of=/dev/rdisk3                                                                                               21:22:25
2+0 records in
1+0 records out
10485760 bytes transferred in 4.558941 secs (2300043 bytes/sec)
6+0 records in
5+0 records out
52428800 bytes transferred in 14.382413 secs (3645341 bytes/sec)
212+0 records in
211+0 records out
2212495360 bytes transferred in 523.833141 secs (4223664 bytes/sec)

No comments:

Post a Comment

Note: only a member of this blog may post a comment.