<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[BIWEB开源PHP WMS系统创始人ArthurXF肖飞的blog]]></title> 
<link>http://www.bizeway.net/index.php</link> 
<description><![CDATA[网务通 - 网务公司发展之路]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[BIWEB开源PHP WMS系统创始人ArthurXF肖飞的blog]]></copyright>
<item>
<link>http://www.bizeway.net/read.php?</link>
<title><![CDATA[DD命令使用大全]]></title> 
<author>ArthurXF &lt;arthurxf@gmail.com&gt;</author>
<category><![CDATA[FreeBSD]]></category>
<pubDate>Thu, 02 Oct 2008 03:47:11 +0000</pubDate> 
<guid>http://www.bizeway.net/read.php?</guid> 
<description>
<![CDATA[ 
	dd 是 Linux/UNIX 下的一个非常有用的命令，作用是用指定大小的块拷贝一个文件，并在拷贝的同时进行指定的转换。<br/><br/>1. 命令简介<br/><br/>dd 的主要选项：<br/><br/>指定数字的地方若以下列字符结尾乘以相应的数字:<br/><br/>b=512, c=1, k=1024, w=2, xm=number m<br/><br/>if=file<br/><br/>输入文件名，缺省为标准输入。<br/><br/>of=file<br/><br/>输出文件名，缺省为标准输出。<br/><br/>ibs=bytes<br/><br/>一次读入 bytes 个字节(即一个块大小为 bytes 个字节)。<br/><br/>obs=bytes<br/><br/>一次写 bytes 个字节(即一个块大小为 bytes 个字节)。<br/><br/>bs=bytes<br/><br/>同时设置读写块的大小为 bytes ，可代替 ibs 和 obs 。<br/><br/>cbs=bytes<br/><br/>一次转换 bytes 个字节，即转换缓冲区大小。<br/><br/>skip=blocks<br/><br/>从输入文件开头跳过 blocks 个块后再开始复制。<br/><br/>seek=blocks<br/><br/>从输出文件开头跳过 blocks 个块后再开始复制。(通常只有当输出文件是磁盘或磁带时才有效)。<br/><br/>count=blocks<br/><br/>仅拷贝 blocks 个块，块大小等于 ibs 指定的字节数。<br/><br/>conv=conversion[,conversion...]<br/><br/>用指定的参数转换文件。<br/><br/>转换参数:<br/><br/>ascii 转换 EBCDIC 为 ASCII。<br/><br/>ebcdic 转换 ASCII 为 EBCDIC。<br/><br/>ibm 转换 ASCII 为 alternate EBCDIC.<br/><br/>block 把每一行转换为长度为 cbs 的记录，不足部分用空格填充。<br/><br/>unblock 使每一行的长度都为 cbs ，不足部分用空格填充。<br/><br/>lcase 把大写字符转换为小写字符。<br/><br/>ucase 把小写字符转换为大写字符。<br/><br/>swab 交换输入的每对字节。<br/><br/>noerror 出错时不停止。<br/><br/>notrunc 不截短输出文件。<br/><br/>sync 把每个输入块填充到ibs个字节，不足部分用空(NUL)字符补齐。<br/><br/><br/>2.实例分析<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;2.1.数据备份与恢复<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.1.1整盘数据备份与恢复<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;备份：<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/dev/hdx of=/dev/hdy<br/><br/>将本地的/dev/hdx整盘备份到/dev/hdy<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/dev/hdx of=/path/to/image<br/><br/>将/dev/hdx全盘数据备份到指定路径的image文件<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/dev/hdx &#124; gzip >/path/to/image.gz<br/><br/>备份/dev/hdx全盘数据，并利用gzip工具进行压缩，保存到指定路径<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;恢复：<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/path/to/image of=/dev/hdx<br/><br/>将备份文件恢复到指定盘<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>gzip -dc /path/to/image.gz &#124; dd of=/dev/hdx<br/><br/>将压缩的备份文件恢复到指定盘<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.1.2.利用netcat远程备份<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/dev/hda bs=16065b &#124; netcat < targethost-IP > 1234<br/><br/>在源主机上执行此命令备份/dev/hda<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>netcat -l -p 1234 &#124; dd of=/dev/hdc bs=16065b<br/><br/>在目的主机上执行此命令来接收数据并写入/dev/hdc<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>netcat -l -p 1234 &#124; bzip2 > partition.img<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;netcat -l -p 1234 &#124; gzip > partition.img<br/><br/>以上两条指令是目的主机指令的变化分别采用bzip2 &nbsp;gzip对数据进行压缩，并将备份文件保存在当前目录。<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.1.3.备份MBR<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;备份：<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/dev/hdx of=/path/to/image count=1 bs=512<br/><br/>备份磁盘开始的512Byte大小的MBR信息到指定文件<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;恢复：<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/path/to/image of=/dev/hdx<br/><br/>将备份的MBR信息写到磁盘开始部分<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.1.4.备份软盘<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/dev/fd0 of=disk.img count=1 bs=1440k<br/><br/>将软驱数据备份到当前目录的disk.img文件<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.1.5.拷贝内存资料到硬盘<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/dev/mem of=/root/mem.bin bs=1024<br/><br/>将内存里的数据拷贝到root目录下的mem.bin文件<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.1.6.从光盘拷贝iso镜像<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/dev/cdrom of=/root/cd.iso<br/><br/>拷贝光盘数据到root文件夹下，并保存为cd.iso文件 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;2.2.增加Swap分区文件大小<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/dev/zero of=/swapfile bs=1024 count=262144<br/><br/>创建一个足够大的文件（此处为256M）<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>mkswap /swapfile<br/><br/>把这个文件变成swap文件<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>swapon /swapfile<br/><br/>启用这个swap文件<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>/swapfile swap swap defaults 0 0<br/><br/>在每次开机的时候自动加载swap文件, 需要在 /etc/fstab 文件中增加一行<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;2.3.销毁磁盘数据<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/dev/urandom of=/dev/hda1<br/><br/>利用随机的数据填充硬盘，在某些必要的场合可以用来销毁数据。执行此操作以后，/dev/hda1将无法挂载，创建和拷贝操作无法执行。<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;2.4磁盘管理<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.4.1.得到最恰当的block size<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dd if=/dev/zero bs=2048 count=500000 of=/root/1Gb.file<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dd if=/dev/zero bs=4096 count=250000 of=/root/1Gb.file &nbsp; &nbsp; &nbsp; <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dd if=/dev/zero bs=8192 count=125000 of=/root/1Gb.file<br/><br/>通过比较dd指令输出中所显示的命令执行时间，即可确定系统最佳的block size大小<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.4.2测试硬盘读写速度<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/root/1Gb.file bs=64k &#124; dd of=/dev/null<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dd if=/dev/zero of=/root/1Gb.file bs=1024 count=1000000<br/><br/>通过上两个命令输出的执行时间，可以计算出测试硬盘的读／写速度 &nbsp; &nbsp; &nbsp; <br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.4.3.修复硬盘<br/><br/>[Copy to clipboard] [ - ]<br/>CODE:<br/>dd if=/dev/sda of=/dev/sda<br/><br/>当硬盘较长时间（比如1，2年）放置不使用后，磁盘上会产生magnetic flux point。当磁头读到这些区域时会遇到困难，并可能导致I/O错误。当这种情况影响到硬盘的第一个扇区时，可能导致硬盘报废。上边的命令有可能使这些数据起死回生。且这个过程是安全，高效的。<br/>Tags - <a href="tag.php?tag=freebsd" rel="tag">freebsd</a> , <a href="tag.php?tag=dd" rel="tag">dd</a>
]]>
</description>
</item><item>
<link>http://www.bizeway.net/read.php?&amp;guid=0#topreply</link>
<title><![CDATA[[评论] DD命令使用大全]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.bizeway.net/read.php?&amp;guid=0#topreply</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>