Data loss will be costly. At the very least, critical data loss will have a financial impact on companies of all sizes. In some cases, it can cost your job. I’ve seen cases where sysadmins learned this in the hard way.


• Backup and restore the entire hard disk or partition.
• Backup of MBR (Master Boot Record)


Syntax of dd command

Before we start with some practical work we need to talk about its syntax.







Learn Linux dd command with examples

Warning: Only superuser can run this command because you can face a big data loss due to its 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.

Example 1. Backup Entire Harddisk

To backup an entire copy of a hard disk to another hard disk connected to the same system, execute the dd command as shown below. In this dd command example, the UNIX device name of the source hard disk is /dev/hda, and device name of the target hard disk is /dev/hdb.




Example 2. Create an Image of a Hard Disk

Instead of taking a backup of the hard disk, you can create an image file of the hard disk and save it in other storage devices.There are many advantages to backing up your data to a disk image, one being the ease of use. This method is typically faster than other types of backups, enabling you to quickly restore data following an unexpected catastrophe.

# dd if=/dev/hda of=~/hdadisk.img

The above creates the image of a harddisk /dev/hda. 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 3. Restore using Hard Disk Image


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


Example 4. Creating a Floppy Image

Using dd command, you can create a copy of the floppy image very quickly. In input file, give the floppy device location, and in the output file, give the name of your floppy image file as shown below.

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

Example 5. Backup a Partition

You can use the device name of a partition in the input file, and in the output either you can specify your target path or image file as shown in the dd command example below.

# dd if=/dev/hda1 of=~/partition1.img

Example 6. 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. You can specify the block size for input and output file. In the above dd command example, the parameter “bs” specifies the block size for the both the input and output file. So dd uses 2048bytes as a block size in the above command.

Note: If CD is auto mounted, before creating an iso image using dd command, its always good if you unmount the CD device to avoid any unnecessary access to the CD ROM.

Example 7: Wipe/delete content of a disk

Erase entire disk, so that it will be empty for someone to use it



How writing of a file  on hard disk with data happen?


Example 8: Quick personal data deleting

Example 7 shows you a complete way to erase your disk, but takes time, you want quick and safe delete your personal data ? Many people think if we do rm -rf /<your data> will do the needful. But we can recover those deletion by using disk recovery tools like Photorec or some forensic tools

Here is another way if you want some not to recover your data you have to write random data on your partition where you data resides.





Example 9:  Create a certain size empty file

For whatever reason, the following dd command creates a huge file which eats up HDD in no time.



Example 10: Create a bootable USB

We can even create bootable USB’s using dd command.

