dd - Unix, Linux Command


Advertisements

Previous Page
Next Page  
 

NAME

dd convert and copy a file

SYNOPSIS

dd OPTION

DESCRIPTION

The dd command copies a file, converting the format of the data in the process, according to the operands specified.

OPTIONS

TAG DESCRIPTION
--help

display this help and exit

--version

output version information and exit

EXAMPLES

EXAMPLE-1:

To Backup entire harddisk using dd command:

# dd if=/dev/sda of=/dev/sdb

“if” represents inputfile, and “of” represents output file. So the exact copy of /dev/sda will be available in /dev/sdb.
If there are any errors, the above command will fail. If you give the parameter “conv=noerror” then it will continue to copy if there are read errors.
Input file and output file should be mentioned very carefully, if you mention source device in the target and vice versa, you might loss all your data.

EXAMPLE-2:

To create a disk image. # dd if=/dev/sda of=/tmp/sdadisk.img

The above creates the image of a harddisk /dev/hda. Backing up a disk to an image will be faster than copying the exact data. Also, disk image make the restoration much more easier.

EXAMPLE-3:

To create a compressed disk image.

# dd if=/dev/sda | gzip >/tmp/sdadisk.img.gz

EXAMPLE-4:

To restore hard disk image.

# dd if=hdadisk.img of=/dev/hdb

The image file hdadisk.img file, is the image of a /dev/hda, so the above command will restore the image of /dev/hda to /dev/hdb.

EXAMPLE-5:

To Restore compressed image.

# gzip –dc /tmp/sdadisk.img.gz | dd of=/dev/sda

EXAMPLE-6:

To clone one partition to another.

# dd if=/dev/sda1 of=/dev/sdb1 bs=4096 conv=noerror,sync

This will synchronize the partition /dev/sda1 to /dev/sdb1.
You must verify that the size of /dev/sdb1 should be larger than /dev/sda1

EXAMPLE-7:

To backup and restore of MBR

(The master boot record (MBR) is a small program that is executed when a computer is booting (i.e., starting up) in order to find the operating system and load it into memory.).

# dd if=/dev/sda of=/tmp/mbr.img bs=512 count=1

The option “count” refers to the number of input blocks to be copied.

To Backing up the boot data of MBR excluding the partition table.

   # dd if=/dev/sda of=/tmp/mbr.img bs=446 count=1

To Restore MBR from MBR image.

   # dd if=/tmp/mbr.img of=/dev/sda

To Display master boot record.

   # dd if=/dev/hda of=mbr.bin bs=512 count=1
   od -xa mbr.bin 

EXAMPLE-8:

Converting data formats.

Convert the data format of a file from ASCII to EBCDIC.

# dd if=textfile.ascii of=textfile.ebcdic conv=ebcdic

Convert the data format of a file from EBCDIC to ASCII

# dd if=textfile.ebcdic of=textfile.ascii conv=ascii

EXAMPLE-9:

Converting case of a file.

Converting a file to uppercase.

# dd if=file1 of=file2 conv=ucase

Converting a file to lowercase.

# dd if=file1 of=file2 conv=lcase .


EXAMPLE-10:

Creating or modifying data files.

Create a fixed size, say 10MB file.

# dd if=/dev/zero of=file1 bs=10485760 count=1

The block size is calculated as 10MB=10*1024*1024.

 Modify the first 512 bytes of a file with null data.

# dd if=/dev/zero of=file1 bs=512 count=1 conv=notrunc

 The option ‘notrunc’ refers to do not truncate the file,only replace the first
 512 bytes, if it exists. Otherwise, you will get a 512 byte file.
 

EXAMPLE-11:

Creating a Floppy Image

# dd if=/dev/fd0 of=myfloppy.img

EXAMPLE-12:

CDROM Backup

# dd if=/dev/cdrom of=tgsservice.iso bs=2048

dd command reads one block of input and process it and writes it into an output file.

Previous Page
Next Page