dd命令使用總結

dd經常使用參數

if:就是input file,也能夠是某設備文件
of:就是output file,也支持是設備文件
bs:規劃的一個block大小,若未指定則默認爲512byte
count:指定bs的數量
skip=n,指 if 後面的原文件跳過 n bytes 再開始讀取;
seek=n,指 of 後面的目標文件跳過 n bytes 再開始寫入;
oflag=direct,真實磁盤io ssh

測試硬盤讀寫速度

  • 測試磁盤的IO寫速度
~# time dd if=/dev/zero of=1.db bs=8k count=30000  
30000+0 records in
30000+0 records out
245760000 bytes (246 MB) copied, 0.731931 s, 336 MB/s

real    0m0.735s
user    0m0.001s
sys     0m0.151s
  • 測試磁盤的IO讀速度
~# dd if=test.dbf bs=8k count=300000 of=/dev/null
30000+0 records in
30000+0 records out
245760000 bytes (246 MB) copied, 0.0342157 s, 7.2 GB/s

dd備份磁盤

  • 查看磁盤信息
root@aikeru:~# fdisk -u -l /dev/sdb
Disk /dev/sdb: 50 MiB, 52428800 bytes, 102400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: C94E55EA-A4D2-4E78-9D73-46CBAE7A03EF

Device     Start    End Sectors Size Type
/dev/sdb1   2048  32767   30720  15M EFI System
/dev/sdb2  32768  94207   61440  30M Linux filesystem
/dev/sdb3  94208 102366    8159   4M BIOS boot
  • 備份爲文件ide

    • count=fdisk命令中最大的end數+1
dd bs=512 count=102367 if=/dev/sdb of=./nas.img
  • 備份到遠程主機
dd bs=512 count=102367 if=/dev/sdb | ssh 192.168.2.2 "of=./nas.img"
  • 添加硬盤不重啓
partprobe
for i in `seq 0 32`; do echo "- - -" > /sys/class/scsi_host/host$i/scan;done
  • 還原
dd bs=512 count=102367 if=./nas.img of=/dev/sdc

dd克隆硬盤

  • 本地克隆
dd bs=512 count=102367 if=/dev/sdb of=/dev/sdc
  • 遠程克隆
dd bs=512 count=102367 if=/dev/sdb | ssh 192.168.2.2 "of=./dev/sdc"

dd添加swap分區

dd if=/dev/zero of=/swapfile bs=1M count=4000
    mkswap /swapfile
    chmod 600 /swapfile
    swapon /swapfile
相關文章
相關標籤/搜索