dd命令原理
一:dd命令是什么
dd其实是工作于比较低层的一个数据拷贝和转换的*nix平台的工具,但是因为dd命令支持*nix平台的一些特殊设备,因此我们可以利用dd命令的这个特性来简单的测试磁盘的性能。把指定的输入文件拷贝到指定的输出文件中,并且在拷贝过程中可以进行格式转换
dd - convert and copy a file: 转换或者复杂一个文件
Copy a file, converting and formatting according to the operands:复制一个文件,转换和格式化根据给定的操作符
二:用途
可以用来备份,恢复,测试硬盘性能,恢复磁盘,制作swap文件等
三:dd命令常用选型
bs=BYTES
read and write BYTES bytes at a time (also see ibs=,obs=)
cbs=BYTES
convert BYTES bytes at a tim
conv=CONVS
convert the file as per the comma separated symbol list
count=BLOCKS
copy only BLOCKS input blocks
ibs=BYTES
read BYTES bytes at a time (default: 512)
if=FILE
read from FILE instead of stdin
iflag=FLAGS
read as per the comma separated symbol list
obs=BYTES
write BYTES bytes at a time (default: 512)
of=FILE
write to FILE instead of stdout
oflag=FLAGS
write as per the comma separated symbol list
四:实例
1.测试磁盘性能
root@lmz ~]# dd if=/dev/zero of=test bs=64k count=4k 4096+0 records in 4096+0 records out 268435456 bytes (268 MB) copied, 8.19248 s, 32.8 MB/s
2. 备份文件mbr文件
[root@lmz mnt]# dd if=/dev/cdrom of=/root/centos.iso
[root@lmz ~]# dd if=/dev/vda of=/root/mbr count=1 bs=512 1+0 records in 1+0 records out 512 bytes (512 B) copied, 5.9382e-05 s, 8.6 MB/s
3.制作swap文件
[root@lmz ~]# dd if=/dev/vda of=swapfile bs=1k count=100000 100000+0 records in 100000+0 records out 102400000 bytes (102 MB) copied, 7.66489 s, 13.4 MB/s
[root@lmz ~]# dd if=/dev/vda of=swapfile bs=1k count=100000 100000+0 records in 100000+0 records out 102400000 bytes (102 MB) copied, 7.66489 s, 13.4 MB/s [root@lmz ~]# mkswap swapfile mkswap: swapfile: warning: don't erase bootbits sectors on whole disk. Use -f to force. Setting up swapspace version 1, size = 99996 KiB no label, UUID=04679b6c-1b63-4cd0-8e19-bfe8ff21a7d0 [root@lmz ~]# swapon swapfile /swapfile swap swap default 0 0
4.制作ISO镜像
[root@lmz mnt]# dd if=/dev/cdrom of=/root/centos.iso