Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux dd 指令進度監控技巧

編輯:Linux 教學

問題

dd 執行期間無任何輸出,僅完成後顯示平均速度,大量資料拷貝時讓操作者陷入漫長等待。

解法:發送 USR1 訊號

  1. 另開終端,找出 dd PID:
    pgrep -l '^dd$'
  2. 發送 USR1 訊號:
    kill -USR1 PID

    原 dd 視窗即顯示已拷貝資料量與即時速度。

  3. 單一 dd 進程可簡寫:
    kill -USR1 `pgrep ^dd`
  4. 每秒自動更新:
    watch -n1 'sudo kill -USR1 `pgrep ^dd`'
  5. 啟動 dd 時即內建監控迴圈:
    dd if=/dev/zero of=/home/test & pid=$!; while [[ -d /proc/$pid ]]; do kill -USR1 $pid && sleep 1 && clear; done

dd 參數速查

參數說明
if=檔案輸入檔(來源)
of=檔案輸出檔(目的)
ibs=bytes讀取區塊大小
obs=bytes寫入區塊大小
bs=bytes同時設定讀/寫區塊大小
cbs=bytes轉換緩衝區大小
skip=區塊數輸入檔開頭跳過區塊數
seek=區塊數輸出檔開頭跳過區塊數(適用磁帶/磁碟)
count=區塊數僅拷貝指定區塊數
conv=轉換關鍵字ascii, ebcdic, ibm, block, unblock, lcase, ucase, swab, noerror, notrunc, sync 等

實用範例

# 完整磁碟備份
dd if=/dev/hdb of=/dev/hdd
dd if=/dev/hdb of=/root/image
dd if=/root/image of=/dev/hdb

# 壓縮備份
dd if=/dev/hdb | gzip > /root/image.gz
gzip -dc /root/image.gz | dd of=/dev/hdb

# 備份 MBR (前 512 bytes)
dd if=/dev/hda of=/root/mbr.bin count=1 bs=512

# 備份軟碟
dd if=/dev/fd0 of=disk.img count=1 bs=1440k

# 記憶體映像
dd if=/dev/mem of=/root/mem.bin bs=1024

# 光碟燒錄映像
dd if=/dev/cdrom of=/root/cd.iso

# 建立 256MB Swap 檔
dd if=/dev/zero of=/swapfile bs=1024 count=262144
mkswap /swapfile; swapon /swapfile
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab

# 銷毀資料
dd if=/dev/urandom of=/dev/hda1

# 磁碟速度測試
dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file
dd if=/root/1Gb.file bs=64k | dd of=/dev/null

# 尋找最佳區塊大小
dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file
dd if=/dev/zero bs=2048 count=500000 of=/root/1Gb.file
dd if=/dev/zero bs=4096 count=250000 of=/root/1Gb.file
dd if=/dev/zero bs=8192 count=125000 of=/root/1Gb.file
# 比較執行時間

# 修復磁碟磁通量問題
dd if=/dev/sda of=/dev/sda
Copyright © Windows教程網 All Rights Reserved