linuxdd命令的使用技巧备份MBR(1)
DD命令:
较为底层的复制工具
dd命令: dd if= of= bs= count= if: 源文件,用于指定数据流来源 of: 目标文件,用于指定数据流存储目标 bs: block size,一次io的数据量 count: 复制多少个bs指定的block 实例: 1,复制 [root@localhost /]# dd if=/etc/fstab of=/tmp/fstab.new 1+1 records in 1+1 records out 805 bytes (805 B) copied, 0.000216881 s, 3.7 MB/s [root@localhost /]# 2,bs=8一次复制八个字节,count=2 复制2次 [root@localhost /]# dd if=/etc/fstab of=/tmp/fstab.awk bs=8 count=2 2+0 records in 2+0 records out 16 bytes (16 B) copied, 0.000834677 s, 19.2 kB/s [root@localhost /]#
特殊功能 两个设备文件: /dev/null: bit bucket /dev/zero:泡泡机,吐零设备 应用1:创建本地回环设备文件: dd if=/dev/zero of=/PATH/TO/SOMEFILE bs= count= 例;从/dev/zero吐出10兆的大小的空间,为swap空间 [root@localhost /]#dd if=/dev/zero of=/tmp/myfile.1 bs=1M count=10 10+0 records in 10+0 records out 10485760 bytes (10 MB) copied, 0.0407088 s, 258 MB/s [root@localhost /]# [root@localhost /]#mkswap /tmp/myfile.1 Setting up swapspace version 1, size = 10236 KiB no label, UUID=c6a5c2b5-03c1-4929-9258-18ca4eb16d17 [root@localhost /]# swapon /tmp/myfile.1 [root@localhost /]# free total used free shared buffers cached Mem: 1012292 338592 673700 1396 24940 124860 -/+ buffers/cache: 188792 823500 Swap: 10236 0 10236 [root@localhost /]# swapoff /tmp/myfile.1 [root@localhost /]#free total used free shared buffers cached Mem: 1012292 338460 673832 1396 24980 124876 -/+ buffers/cache: 188604 823688 Swap: 0 0 0 [root@localhost /]#
应用2:备份MBR [root@localhost /]#dd if=/dev/sda of=/tmp/mbr.backup bs=512 count=1 1+0 records in 1+0 records out 512 bytes (512 B) copied, 0.000527532 s, 971 kB/s [root@localhost /]# 应用3:破坏其/dev/sdba MBR 删除sdaMBR: dd if=/dev/zero of=/dev/sda bs=512 count=1
恢复sdaMBR: [root@localhost /]#dd if=/tmp/mbr.backup of=/dev/sda bs=512 count=1