The dd command of linux
The dd command stands for “data duplicator” and used for copying and converting data. It is very powerful low level utility of Linux which can do much more like;
- Backup and restore the entire hard disk or partition.
- Backup of MBR (Master Boot Record)
- It can copy and convert magnetic tape format, convert between ASCII and EBCDIC formats, swap bytes and can also convert lower case to upper case.
- It can also be used by Linux kernel make files to make boot images.
Only superuser can run this command because you can face a big data loss due to it’s improper usage, so you should be very careful while working with this utility. At that moment data loss can convert the dd utility as a “data destroyer” for you. That’s why it is recommended that beginners should not use this command on a production machine until they get familiarity on this. You must make sure that target location must have sufficient space while running this command.
SYNTAX
Before we start with some practical work we need to talk about it’s syntax.
dd if=<source file name> of=<target file name> [Options]
We normally do not explain about syntax but this command syntax require some explanation. The syntax is totally different when compared to many Linux commands we know. In this syntax dd is followed by two things
if= –This is a source from where you want to copy data and ‘if’ stands for input-file.
of= –This is a source from where you want to write/paste data and ‘of’ stands for output-file.
[options] –These options include, how fast data should be written, what format etc.
if =输入文件(或设备名称)。
of =输出文件(或设备名称)。
ibs = bytes 一次读取bytes字节,即读入缓冲区的字节数。
skip = blocks 跳过读入缓冲区开头的ibs*blocks块。
obs = bytes 一次写入bytes字节,即写 入缓冲区的字节数。
bs = bytes 同时设置读/写缓冲区的字节数(等于设置obs和obs)。
cbs = bytes 一次转换bytes字节。
count = blocks 只拷贝输入的blocks块。
conv = ASCII 把EBCDIC码转换为ASCII码。
conv = ebcdic 把ASCII码转换为EBCDIC码。
conv = ibm 把ASCII码转换为alternate EBCDIC码。
conv = blick 把变动位转换成固定字符。
conv = ublock 把固定们转换成变动位
conv = ucase 把字母由小写变为大写。
conv = lcase 把字母由大写变为小写。
conv = notrunc 不截短输出文件。
conv = swab 交换每一对输入字节。
conv = noerror 出错时不停止处理。
conv = sync 把每个输入记录的大小都调到ibs的大小(用ibs填充)。
fdformat 命令,低级格式化软盘。
EXAMPLE
Example 1
: Clone one hard disk to another hard disk. This is useful when we are building many machines with same configuration. We no need to install OS on all the machines. Just install OS and required software on machine then clone with below example.
dd if=/dev/sda of=/dev/sdb
Example 2
: We can take backup of a partition/complete HDD for future restoration.
Backing up a partition to a file(to my home directory as hdadisk.img)
dd if =/dev/sda2 of=~/hdadisk.img
Restoring this image file in to other machine
dd if=hdadisk.img of=/dev/sdb3
Example 3
: Do you feel hdadisk.img is bit big? Use gzip or bzip2 to compress when creating image.
dd if =/dev/sda2 | bzip2 hdadisk.img.bz2
Example 4
: Do you know dd command can be used as file copier as well? Yes, if you don’t have cp command use dd command to copy a file from one location to other.
dd if=/home/imran/abc.txt of=/mnt/abc.txt
Example 5
: Wipe/delete content of a disk so that it will be empty for some one to use it.
dd if=/dev/zero of=/dev/sdb
This will wipe out your second hard disk and every bit is written with zero. you may be interested in learning /dev/null and /dev/zero files which do similar stuff but there is a bit of difference.
HOW WRITING OF A FILE ON HARD DISK WITH DATA HAPPEN?
Normally what ever you write on to a disk at the block level it will write combination of zeros and ones. Hope you know this and what we are doing here is that we are just writing zeros which will clear all 1’s from the hard disk. This eventually makes your disk empty.
Example 6
: What to hide your ass by deleting your personal data. Many people think if we do rm -rf / will do the needful. But we can recover those deletion by using disk recovery tools like Photorec or some forensic tools. But if you want some not to recover your data you have to write random data on your partition where you data resides.
dd if=/dev/random of=/dev/sdb
Do above command multiple times so that it is real hard to recover data. If I am in your place, I will write below shell script to do that.
for i in {1..10};do dd if=/dev/random of=/dev/sdb;done
This will execute dd command 10 times in a row one after the other.
Example 7
: We can create virtual file system with dd command which can be used as swap. To know more about you should know on how to create virtual swap space in Linux .
dd if=/dev/zero of=/swapfile bs=1024 count=200000
where bs
stands for block size and count is nothing but number of such blocks used to crate this swap file.
Make sure you use block sizes in multiples of 1024 bytes which is equal to 1KB. Ff you do not specify block size, dd use a default block size of 512 bytes. Below conventions will work for block sizes.
Example 8
: We can even create ISO files from a CD-ROM or DVD-ROM using dd command.
dd if=/dev/dvd of=/opt/my_linux_image.iso
or with more
dd if=/dev/sr0 of=/home/$user/mycd_image.iso bs=2048 conv=sync
Some other examples:
dd if=/dev/sda1 of=/dev/sdb1 bs=4096 conv=noerror,sync
This will make clone of one partition sda1 to other sdb1 partition, also used sync option to synchronize the partition
dd if=/dev/sdx of=/dev/sdy bs=64k conv=noerror,sync
This will clone the entire drive, including MBR, all partitions and data where noerrr instructs dd to ignore all read errors while continuing operations. The snyc data offsets stay in sync And bs=sets block size which is set to 64k.
Example 9
: We can even check disk quota using dd command by creating huge files which eats up HDD in no time.
dd if=/dev/zero of=/usr/disk-img/disk-quota.ext3 count=40960
This will create 20MB file (disk image) at said path.
Example 10
: We can even create bootable USB’s using dd command.
dd if=/home/$user/bootimage.img of=/dev/sdc
This will create boot-able USB drive where /dev/sdc is an USB drive.
The dd command of linux的更多相关文章
- Using Android Phone to recover SD card formatted with DD command under linux
Using Android Phone to recover SD card formatted with DD command under linux 1. Formatted a sd card ...
- 6个关于dd命令备份Linux系统的例子
数据丢失带来的损失是相当昂贵的.关键数据的丢失会对各种规模的企业带来影响.有几种方法来备份Linux系统,包括rsync的和rsnapshot等.本文提供有关使用dd命令备份Linux系统的6个实例. ...
- Sending Email from mailx Command in Linux Using Gmail’s SMTP
The mailx or mail command in Linux is still providing service for guys like me, especially when we n ...
- screen command of linux
[screen command of linux] 常用键: 补充: Ctrl-a S # split terminal horizon Ctrl-a TAB # switch to ano ...
- 下载tree命令的源代码 - The Tree Command for Linux Homepage
The Tree Command for Linux Homepage http://mama.indstate.edu/users/ice/tree/ [root@test ~]# ll -as m ...
- (6)dd命令安装Linux
1.面对大批量服务器的安装,人们往往热衷于选择"无人值守安装"的方式,而此方式需要对服务器进行过多的配置,并不适合初学者. 无人值守安装(Kickstart),又称全自动安装,其工 ...
- 使用dd命令备份Linux分区
为了备份分区,开始使用的是Remastersys,但最终生成的iso文件仅有几十K,应该是软件bug,且此软件不再更新,后尝试使用Linux Respin,但github一直连接不上. 其实可以尝试使 ...
- Changing the Color of Linux ls Command 改变Linux的ls命令显示的颜色
Linux command ls basically use the file /etc/DIR_COLORS or /etc/DIR_COLORS.xterm to define the color ...
- linux下创建可引导的U盘系统,使用dd命令进行Linux的ghost
1,通过iso创建可引导的U盘系统. 1.0,格式化U盘为FAT32格式 linux下能够使用命令: mkfs.vfat U盘的设备路径 比如: mkfs.vfat /dev/sdb 当中U盘的路径能 ...
随机推荐
- c++数组遍历十种方式
int ia[3][4] = {1,2,3,4,5,6,7,8}; //下标 for (int i = 0; i < 3; i++) { for (int j = 0; j < 4 ...
- Java--图片浏览器
功能:启动后选择打开文件,可以打开图片进行浏览. v 1.0 :支持上一张 下一张功能.(欠缺,窗口大小未随着图片大小而改变) import java.awt.BorderLayout; import ...
- asp.net实现access数据库分页
最近在编程人生上看到篇文章很有感触,觉得人生还是要多奋斗.今天给大家贡献点干货. <divclass="page"id="ctrlRecordPage"& ...
- [linux]ubuntu在线安装mysql
1. sudo apt-get install mysql-server 2. apt-get isntall mysql-client 3. sudo apt-get install li ...
- cms替换主页
cms替换主页的步骤 1.先做好静态页面: 2.在D:\wamp\www\phpcms\install_package\phpcms\templates文件夹下建新的文件夹tianqiwangluo( ...
- python学习笔记(十四)之字典
字典:是python中唯一的映射类型,字典中每一项都是由键-值对组成的项.字典中没有索引,只有键和值.键的类型可以是整型,变量或字符串. 创建和访问字典: >>> dict1 = { ...
- Let's Encrypt 免费通配 https 签名证书 安装方法
安装环境 centOs7 主要通过 acme.sh (bash脚本)来注册签名 git地址:https://github.com/Neilpang/acme.sh 申请证书流程 1.申请证书-> ...
- Oozie与Coordinator调度讲解及系统时区配置与定时触发两种配置方式
1:修改本地linux时区 查看时区 - 号代表西 + 号 代表东 北京时间是东八区 设置时区的配置文件所在位置 cd /usr/share/zoneinfo/ 选择以亚洲的上海 的时区为基址 删除 ...
- oozie的简易安装
1. 解压 tar -zxvf oozie-4.0.0-cdh5.3.6.tar.gz 2.配置hadoop的集群,添加一个代理用户(给oozie运行mapreduce的权限) 在hadoop的co ...
- flask插件系列之flask_cors跨域请求
前后端分离在开发调试阶段本地的flask测试服务器需要允许跨域访问,简单解决办法有二: 使用flask_cors包 安装 pip install flask_cors 初始化的时候加载配置,这样就可以 ...