How to Easily Clone and Restore a Linux Disk Image With dd

Bertel King 17-04-2017

When the time comes to wipe, backup, or restore data on Linux, there are a number of apps you can pick. GParted is one of the most proven options out there. Disks is a more modern alternative that looks great in the GNOME desktop environment. But no matter which Linux operating system you run, there’s one option that always works — dd.


You can use Linux without ever needing to dip into the terminal. But once you add certain commands to your repertoire, not only will you save time, but you will learn skills that you can use across any version of Linux.

Why Use dd?

Whether you’re on a desktop or a server, dd simply works. dd began as a Unix command, so in addition to Linux, it supports other Unix-like operating systems 3 UNIX-Like Operating Systems That Aren't Linux Recently, people started to confuse "UNIX" with "Linux." Linux was influenced by UNIX, but UNIX systems have no relation to Linux. Here are some important UNIX-based systems worth knowing about. Read More such as FreeBSD and macOS.

dd is also fast. I don’t mean it will make speedy work of whatever drive you’re trying to eradicate. Rather, it takes mere seconds to initiate a wipe. Once you know what to type, you can open a terminal and erase a drive in the time it takes you to type in a search for instructions online.

With great power comes with great responsibility. A certain dd entry makes our list of Linux commands you should never run 9 Lethal Linux Commands You Should Never Run You should never run a Linux command unless you know exactly what it does. Here are some of the deadliest Linux commands that you'll, for the most part, want to avoid. Read More .

Are you nervous? Good. Even once you’re a dd expert, you always want to type out commands carefully. An absent mind can, at worst, ruin hardware and, more likely, result in data loss. Now, let’s get started.


Cloning a Drive

Cloning a drive is a surefire way to make a backup of your computer. You can back up data to a portable hard drive or Dropbox 5 Great Cloud Backup Tools & Services That Fully Support Linux If you ask any power user for one good piece of advice that applies to any operating system, it would be to back up your files regularly. As much as technology can be helpful, it... Read More , but this only saves your files. To save your apps, you can have to learn how to back up each individual one. For some, that means exporting a specific file. For others, that means copying a hidden folder. Then there are those apps that you can’t backup at all.

dd gets around this by creating an exact copy of your entire hard drive or partition. When you restore this copy, you bring your computer back to exactly how it was. You will get back your files, your apps, your browsing history, and even your system settings. Everything.

To clone your drive, you will need a second drive that has more space than the one you’re copying. Likely, this will be a portable hard drive or a large flash drive.

Start by opening the terminal. You will need administrator rights to execute any dd commands. You can type su to sign in as an administrator, or you can type sudo at the beginning of the dd command.


When you’re ready to copy, type the command below. Note, it will erase any pre-existing data on the second drive, so make sure to backup any data beforehand.

dd if=/dev/sdX of=/dev/sdY

Now, let’s make sense of what’s going on. dd is the command. if is the input, as in the location you want to copy. of is the output, or the location you’re replacing with your copy.

sdX and sdY refer to the drives you are interacting with. Drives are often given a name such as /dev/sda, /dev/sdb, or /dev/sdc. You can find out the names using a partition editor How to Write, Format and Manage an SD Card in Linux There are multiple ways to configure an SD card in Linux, either from the command line or using a graphical application. Here's how you do it. Read More . Or, since you’re already in the terminal, you can use the lsblk command.

Creating an Image File

Another way to clone a drive is to create a disk image that you can move around and restore as you would a bootable USB.


Creating image files allows you to save multiple backups to a single destination, such as a large portable hard drive. Again, this process only requires one command:

dd if=/dev/sdX of=path/to/your-backup.img

To save space, you can have dd compress your backup.

dd if=/dev/sdX | gzip -c > path/to/your-backup.img.gz

This command shrinks your backup into an IMG.GZ file, one of the many compression formats Linux can handle Linux Archive Managers Compared: Ark vs. File Roller Archive managers may seem pretty simple at first glance, but they could potentially offer a lot more than you think. I compared the two default archive managers for Linux, File Roller and Ark, based on... Read More .

Restoring a Drive

What good are those backups if you can’t use them? When you’re ready to restore a clone, you have two options. If you used the first approach, simply swap the two destinations.

dd if=/dev/sdY of=/dev/sdX

When restoring from an image file, the same concept applies:

dd if=path/to/your-backup.img of=/dev/sdX

If your image file is compressed, then things get a little different. Use this command instead:

gunzip -c /path/to/your-backup.img.gz | dd of=/dev/sdX

To be clear, gunzip is g unzip, as in the opposite of g zip This command decrompresses your backup. Then dd replaces the existing drive with this image.

Parameters to Consider

You can alter your command by sticking a parameter at the end. By default, dd can take a while to transfer data. You can speed up the process by increasing the block size. Do so by adding bs= at the end.

dd if=/dev/sdX of=/dev/sdY bs=64

This example increases the default block size from 512 bytes to 64 kilobytes.

conv=noerror tells dd to continue despite any errors that occur. The default behavior is to stop, resulting in an incomplete file. Keep in mind that ignoring errors isn’t always safe. The resulting file may be corrupted.

conv=sync adds input blocks with zeroes whenever there are any read errors. This way data offsets remain in sync.

You can combine these last two as conv=noerror,sync if you so desire. There is no space after the comma.

Getting to Know dd

In case you’re interested, dd’s name refers to a statement in IBM’s Job Control Language. If you don’t understand what’s going on there, no sweat. I don’t either. That doesn’t make the command any harder to use.

Need more information that can help you improve your relationship with dd? The wiki page is pretty thorough. There’s also a great write-up on the Arch Linux wiki. Again, it doesn’t matter if you’re using Arch or not. dd works the same way regardless of your Linux operating system.

If it turns out dd isn’t for you, you’re not out of luck. There are other ways to clone a hard drive How to Clone Your Linux Hard Drive: 4 Methods Need to clone your Linux hard disk drive or partition? Use one of these drive cloning tools to clone your Linux disk. Read More !

Image Credit: wavebreakmedia, Jane Kelly via

Related topics: Hard Drive, Linux.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Gabriel Llorens
    July 11, 2019 at 2:16 pm

    Thank you very much for the information. It's the best I could find about this command.
    Would it be possible to use the dd command from the partition you want to erase, i.e. if you are using ubuntu in /dev/sda/ and you have an .img file in a usb and from the command line in that ubuntu you write:
    dd if=path/to/your-backup.img of=/dev/sda
    Will it work erasing the data and updating the system?
    How should I proceed if not?

    Thank you very much in advanced.

  2. Jim Mooney
    August 1, 2018 at 10:11 pm

    I wanted to print the directions out since they won't be handy once I'm restoring, but the page is loaded with so many ads and stuff I'd have a mini-book. Any chance of just a text file with the directions?

    • Donald Mickunas
      December 9, 2018 at 9:27 pm

      Why not pull up the instructions on your smart phone? Then they will be available during your operation.

    • Dan
      December 18, 2018 at 8:27 pm

      You can use a Chrome (or Chromium) extension called "Just Read" and that'll print just the text and nothing else.
      -Just Read:
      With one click, you can remove distractions like:
      - The page's styling
      - Ads
      - Popups
      - Comments
      You could also create a new document and copy and paste the text.

  3. Power Chino
    July 10, 2018 at 9:58 am

    Thanks a lot for taking your personal time to share your knowledge allowing me to learn from you. Because of this article I have successfully completed my first Linux disk clone. I have been a Windows person for a while now but the more I do Linux and come accross very smart people like you who are willing to share their knowlegde with other people like me the more I like Linux. Thanks again for sharing your knowledge it is awesome.

  4. zach
    November 23, 2017 at 8:20 pm

    What I love about linux is the learning experience. I've been on windows since 3.1 ages ago and take everything I know for granted. Almost every day I learn something new on linux. I'm getting into RHEL7 trying to make a career change and thought using this dd would make restoring easier than reinstalling everything when something 'breaks.' I started the process last night, it had failed by morning because it ran out of space... The img file was over 400gb lol How about a command that creates an image of non-empty data on the hard drive??

    • Aaron Peters
      November 27, 2017 at 2:59 pm

      Hi Zach,

      Check out partimage ( it creates the same sort of one-file archive of a disk or partition, and one of the options you can select is to pack up only used data.

      In theory fiddling with that data (i.e. leaving empty space out) at the block level can be seen as somewhat riskier than a straight copy, which is what dd is doing. But I've used partimage on several occasions and never had an issue. There's even a convenient live CD you can burn so you're not working with the hard disk while the host OS is running.

  5. Vincent
    April 17, 2017 at 1:36 pm

    When you are restored data, it must be the same machine, otherwise system will faile. Also hardisk size must be the exact size or larger.

    • Bertel King, Jr.
      April 20, 2017 at 6:02 pm

      Thanks for pointing this out! Those are very important details.