2009年11月29日 星期日

Linux Command - dd

dd: Image Copy
This utility is ``useful for making an image copy of any media. An image copy is an exact byte-for-byte copy" [8, p. 80,].


dd [if=input-file] [of=output-file] [option]
where both input-file and output-file are optional. If omitted, input-file will default to the standard input, whereas output-file will default to the standard output.
option can be one or more of:

bs (block size): default is 512 bytes.
conv=arg... where arg is one or more of the following, separated by commas:
ascii: convert EBCDIC to ASCII.
ebcdic: convert ASCII to EBCDIC.
swab: swap every pair of bytes.
noerror: do not stop processing on detecting an error.
sync: pad every input record to (default) 512 bytes.
see your system manual for more details.
To read an older Silicon Graphics tape on a Sun, the dd command is:

dd if=/dev/tape conv=swab,noerror,sync | tar xf -
The input of dd is the file on the cartridge tape. dd converts that file by swapping every pair of bytes, and padding every record to 512 bytes (while not stopping if an error occurs). The resulting output file is fed (through the pipe) to tar, which then reads the file.

When a hyphen (-) is used instead of a file name on the tar command, the input is taken from the standard input on the extract and put to the standard ouput on the create function.


我的經驗
dd -if -of /dev/sda bs=512


My experience
複製Target image 到 target machine 的memory 中,然後利用dd 寫到 compact flash上的方法

首先第一步先將compact flash unmount下來
# umount /flash/

再來建立一個子目錄
# mkdir /tmp2
並且把/tmp2 device mount 到 /tmp2
# mount -t tmpfs /tmp2 /tmp2/

將target image 檔案下載放到新建的目錄/tmp2目錄下
# cd /tmp2
# ftp 192.168.XX.XX
get image file myImage.img

檢查系統資訊
# df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/root.old 1766 684 1082 39% /initrd
/dev/ram1 58093 35785 22308 62% /
/mnt 32768 212 32556 1% /mnt
/tmp2 254248 62788 191460 25% /tmp2

# mount
/dev/root.old on /initrd type ext2 (rw)
/dev/ram1 on / type ext2 (rw)
/proc on /proc type proc (rw)
/mnt on /mnt type tmpfs (rw)
/tmp2 on /tmp2 type tmpfs (rw)


再來檢查要將compact flash 是掛在系統的哪一個device file上,這裡是XXX-5000, compact flash 是屬於/dev/hdc這一個file
# dmesg | grep hdc
hdc: SanDisk SDCFB-64, CFA DISK drive
hdc: attached ide-disk driver.
hdc: task_no_data_intr: status=0x51 { DriveReady SeekComplete Error }
hdc: task_no_data_intr: error=0x04 { DriveStatusError }
hdc: 125440 sectors (64 MB) w/1KiB Cache, CHS=490/8/32
hdc: hdc1
hdc: hdc1
hdc: hdc1
hdc: hdc1
hdc: hdc1
hdc: hdc1
hdc: hdc1

最後實際執行dd command bs (block size)為 512k
# dd if=myImage.img of=/dev/hdc bs=512k
122+1 records in
122+1 records out

sync 將記憶體的資料寫到flash中
# sync
# sync
# sync

沒有留言: