Pinterest Stumbleupon Whatsapp

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 It Doesn't Matter Which Linux Operating System You Use Why It Doesn't Matter Which Linux Operating System You Use There's always going to be arguments about which Linux operating system is "better". Overall, Linux provides a good experience, regardless of how you run it. Let's look at those similarities -- and celebrate them! Read More .

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 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 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 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 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 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 4 Methods To Clone Your Linux Hard Drive 4 Methods To Clone Your Linux Hard Drive Need to clone your Linux hard disk drive, or a partition? You can use the built in dd tool, or several alternatives to clone your disk for restoring later, fuss-free. Read More .

What’s your preferred method for backing up your computer? Are you a fan of dd? Is there an app you would recommend instead? Don’t hesitate to share your experience with fellow readers!

Image Credit: wavebreakmedia, Jane Kelly via

Leave a Reply

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

  1. 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.