Do not like the silent dd on unix? Let’s add a progress bar for it. (Using pv)

Though dd is not efficient, it’s still widely used for many years until now, especially when we are “burning” the disk image of the famous Raspberry Pi or some related boards, the worst point I hate about dd is the silence, it makes me worried, we can not know the progress of the process, and if it takes too much time, we may start to think about if the computer hung, the SD card broken, or something else … until the process finished, that’s very bad.

I’ve found pv and also use it for a while, it’s the Pipe Viewer, a terminal-based tool for monitoring the progress of data through a pipeline, I know it’s not so famous and widely used, so I would like to share and talk about it, let’s start it!

pv is a OSI(Open Source Initiative, not the network Open Systems Interconnection model) certified open source software, here is the homepage of it: https://www.ivarch.com/programs/pv.shtml

pv-homepage.png

The latest release until now is v1.6.0, the version in Ubuntu 14.04 LTS is v1.2.0, but still works well, I am going to use Raspbian Jessie, version February 2016 (Release date:2016-02-09) as the example image in this post, and writing an raw image to a microSD card as the scenario.

Traditionally, we use dd like this, dd in, dd out, with silence:

dd_install_2016-02-09-raspbian-jessie.png

繼續閱讀

在 Linux 上快速建立 空白檔案 / 大檔案 的幾個方法

建立 swap 置換空間的或是跑一些效能測試時候經常會需要建立一個超大檔案(這邊談的都是空白檔案)

最常用的方法應該是 dd,例如從 /dev/zero 讀空白資料出來寫到我們的目的地檔案./dd_1G,一次寫入 1MB 的資料,總共寫入 1024 塊,就可以產生一個 1GB 的檔案:

在我的電腦上大概花了6秒鐘左右,如果檔案更大的話花的時間會更多

與其用 dd ,其實有更快的方法

0.001秒啊 … 不想花時間解釋太多,會用就好,大家可以想像成把檔案頭尾的起點終點設定完就結束了,檔案中間的內容跳過不管他,所以會很快

除了dd, 其實有別的方法 – fallocate / truncate

不過 fallocate 可能不適用於所有檔案系統,已知支援:btrfs, ext4, ocfs2 及 xfs

如果不考慮速度的還有一個工具 – xfs_mkfile
Debian / Ubuntu based GNU/Linux 可以透過 apt-get install xfsprogs 來安裝
雖然他是 xfs 的 utility 但也可以在其他檔案系統上面使用

最後比較一下產出的檔案有什麼差異?看起來是沒差~ 如果等一下是要做 mkswap 這類初始化的動作就更沒差了 …

這些差異在檔案更大的時候會更明顯