How to make disk image with dd on Linux or Unix

How do I create disk image using dd command? How do I perform disk cloning from a live Linux cd for backup or recovery purpose?

You can easily use the dd command for making an image of a partition or of a full hard disk drive.

What is a dd image?

Disk cloning is nothing but a mere process of creating an image of an entire disk. This can be useful for copying disks, backups, recovery and more. The dd command is easy to use tool for making such clones.

Warning: You should be very careful when using dd command; it can destroy data. Remember the order of input file (if=) and output file (of=).

How to clone an entire hard disk

The syntax is:
dd if=/dev/input/DEVICE-HERE of=/dev/OUTPUT/DEVICE-HERE bs=64K conv=noerror,sync
To clone /dev/sdc (250G) to /dev/sdd (250G) in Linux, enter:
# dd if=/dev/sdc of=/dev/sdd bs=64K conv=noerror,sync
To clone /dev/ada0 (250G) to /dev/adb0 (250G) in FreeBSD, enter:
# dd if=/dev/ada0 of=/dev/adb0 bs=64K conv=noerror,sync

  1. if=/dev/file : Input device/file.
  2. of=/dev/file : Output device/file.
  3. bs=64k : Sets the block size to 64k. You can use 128k or any other value.
  4. conv=noerror : Tell dd to continue operation, ignoring all read errors.
  5. sync : Add input blocks with zeroes if there were any read errors, so data offsets stay in sync.

How to clone a partition

To clone /dev/sdc1 to /dev/sdd1, enter:
# dd if=/dev/sdc1 of=/dev/sdd1 bs=128K conv=noerror,sync
Sample outputs:

15874+0 records in
15873+0 records out
1040252928 bytes transferred in 3.805977 secs (273320858 bytes/sec)

dd make disk image

You can boot from a live cd. Once booted, make sure no partitions are mounted from the source hard drive disk. You can store disk image on an external USB disk. The syntax is as follows
dd if=/dev/INPUT/DEVICE-NAME-HERE conv=sync,noerror bs=64K | gzip -c > /path/to/my-disk.image.gz
In this example, create disk image for /dev/da0 i.e. cloning /dev/da0 and save in the current directory:
# dd if=/dev/da0 conv=sync,noerror bs=128K | gzip -c > centos-core-7.gz
Sample outputs:

Fig.01: dd command in action

Fig.01: dd command in action

The above command just cloned the entire hard disk, including the MBR, bootloader, all partitions, UUIDs, and data.

How to restore system (dd image)

The syntax is:
# gunzip -c IMAGE.HERE-GZ | dd of=/dev/OUTPUT/DEVICE-HERE
For example:
# gunzip -c centos-core-7.gz | dd of=/dev/da0

Tip #1: Not enough disk space locally? Use remote box

You can send the image through ssh and save it on the remove box called
# dd if=/dev/da0 conv=sync,noerror bs=128K | gzip -c | ssh dd of=centos-core-7.gz

Tip #2: See progress while making an image with dd

You need to use GNU dd with coreutils version 8.24 as follows (pass the status=progress to the dd):
# dd if=/dev/sdc1 of=/dev/sdd1 bs=128K conv=noerror,sync status=progress
Sample outputs:

gdd (GNU DD) in action with progress bar running on MacOS X

gdd (GNU DD) in action with progress bar running on MacOS X

Tip #3: Save extra information

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 5 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • Sandy Aug 18, 2016 @ 12:37

    Excellent info. How does DD deal with the of= being smaller than the if=. eg imaging a 500GB disc to a 240 SSD?

    • 🐧 Vivek Gite Aug 18, 2016 @ 20:12

      You need to make sure that of= is equal or greater size than the if=. If not your cloning will fail.

  • ncl Aug 24, 2016 @ 19:29

    I have a sandisk card that I can mount on a usb drive that I want to clone via dd to a local drive. however, I keep getting errors that I cannot do this. it appears that dd cannot be used with drives mounted via usb. is there a way around this?

    • 🐧 Vivek Gite Aug 24, 2016 @ 20:36

      Just unmount the drive and try it directly. If drive mounted as /dev/sdc1 run
      sudo umount /dev/sdc1
      Now use /dev/sdc to make disk image.

  • Carlos Alexandre Jun 14, 2017 @ 18:25

    To get a better progress information you cam just use pv command, for example

    pv -rbtpe disk.img.gz | gunzip | dd of=/dev/OUTPUT/DEVICE-HERE conv=noerror,sync

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum