≡ Menu

How Do I Make Linux / UNIX Filesystem Backup With dd?

dd command is all in one tool to Copy a file, converting and formatting according to the options. Since Linux (and other UNIX versions) understand everything as a file dd works like wonders. Please note dd is not created specifically for a backup purpose but it is real handy tool. Few months back I was new to HP-UX and I was unable to understand the HP-UX tape devices then I used dd to create backup. Later when I got information of tape device name I switched to age old tar and other dump commands

dd command syntax

The syntax of dd is as follows:


dd command examples

So to backup /dev/hda3 under Linux command should be as follows i.e. linux filesystem backup with dd:
# dd if=/dev/hda3 of=/backup/myhostname-15-nov-05-hda3.bak.dd
However if you are running planning to run dd in background and if you wish to kill it or want to sending a SIGUSR1 single to a running dd process then you need to start dd as follows (this is really useful stuff):
# dd if=/dev/hda3 of=/backup/myhostname-15-nov-05-hda3.bak.dd; dpid=$!
Now use kill command as follows:
# kill -USR1 $dpid; sleep 5; kill $dpid

dd command to backup boot loader / MBR

dd can be use to backup your boot loader too (if you install a Windows after Linux it will destroy grub/lilo boot loader):
# dd if=/dev/hdX of=/backup/mbr.bak bs=512 count=1
You can restore MBR with the following dd command:
# dd if=/backup/mbr.bak of=/dev/hdX bs=512 count=1
Note replace hdX with your actual device name. However I prefer to use grub-install.

Please note that dd is also capable of reading tapes that were created on other UNIX or written in a format other than Unix (like Windows 2000 server).

Here is one more practical example for Solaris UNIX:

To copy all but the label from disk to tape i.e. copy data in 512 KiB blocks between a disk and a tape, but do not save or restore:
# (dd bs=4k skip=1 count=0 && dd bs=512k) </dev/rdsk/c0t1d0s2 >/dev/rmt/0
Copy from tape back to disk, but leave the disk label alone (restore):
# (dd bs=4k seek=1 count=0 && dd bs=512k) < /dev/rmt/0 >/dev/rdsk/c0t1d0s2

Backing up entire disk/partition with dd command

Backup /dev/hda to /dev/hdb:
# dd if=/dev/hda of=/dev/hdb conv=noerror,sync

  • /dev/hda: Source disk
  • /dev/hdb: Target disk
  • sync: Use synchronized I/O for data and metadata
  • noerror: Continue copy operation after read errors

Above command will only work if the both disks are the same size and C/H/S geometry. I strongly suggest using partition level backup. dd is an easy to use (real life saver) command. Read the man page of dd for more information.
$ man dd

Share this on:
{ 12 comments… add one }
  • Jann January 28, 2009, 7:08 pm

    I know that you can later on mount partition-level dd dumps. Can you also somehow mount the dump of an entire disk?

  • A person June 25, 2009, 7:34 pm

    RE: Jann…

    dunno, give it a try. In unixland, you’d do something like:
    mkdir /mnt/mountpoint
    mount -t ext3 /somepath/ /mnt/mountpoint

    • Greg January 9, 2016, 2:01 am

      Jann is asking, I think, about dumping an entire disk (e.g. /dev/sdb) – can you mount the filesystems on /dev/sdb1 and /dev/sdb2 from the copy. I’m pretty sure the answer is ‘no’ – since the mount operation expects to find the filesystem at the start of the data – if you really wanted to, you could extract the partitions from the dump (again using dd) and mount those. It’s not very useful to dump an entire disk, all you can easily do is copy it back to a disk of the same size. And you’d probably be wasting time and space copying a ‘swap’ partition too.

  • Eric J December 16, 2010, 11:19 am

    I never knew about this tool. I was only recently exposed to it while reading how one man managed to boot ubuntu on the CR-48. He dd’ed the ubuntu rootfs to the CR-48 over ssh. SO. COOL.

  • Dave May 19, 2011, 4:59 pm

    I would like to use dd to make a backup of my USB flash drive to my HDD, I’m using a Live CD, both are unmounted.
    I tried:
    dd if=/dev/usbflashdrive of=/dev/sda1>usbdiskdate.img
    This destroyed the ext3 partition.

    Any suggestions for improvement?

  • robert June 17, 2011, 8:04 am


    Youre an idiot

  • CesarIII July 20, 2011, 5:00 am

    Hi there,

    If you are trying tu backup an USB you can try “dd” + “gzip” so you can compress your backed-up-data. You can improve compression ratio, and even more, If you create a file filled with “0” an then delete it, you’ll obtain a smallest file:

    To create a file with “0” so we erase the free area:

    dd if=/dev/zero of=DELETE.ME

    Once created, delete it.
    Once deleted, backup:

    dd if=/dev/usbflashdrive | gzip –best > backup.img.gz

    You can improve reading/writing by adding “bs” or “obs” on dd… check “man dd”

    dd obs=100MB if=/dev/usbflashdrive | gzip –best > backup.img.gz

    Make tests… eh!… to restore just do a:

    gunzip -c backup.img.gz | dd bs=100MB of=/dev/usbflashdrive


  • Oran November 4, 2011, 6:19 pm

    Thank you for the tutorial. I want to buy an identically sized drive for performing a dd backup, but am concerned about the ability to accomplish this. The drive that I currently have lists the capacity as 251.0 gb (using fdisk). Hard drives that I find advertised only list 250.0 gb. If I get a 250.0 gb hard drive, then the backup could potentially be corrupted due to losing 1.0 gb of space, right? How is this handled? Is there a way to find 251.0 gb hard drives?


  • JIEM February 20, 2012, 10:03 am

    I want to clone a 500GB hard drive (sda) to new hard drive (sdb)
    is it possible if using command, dd if=/dev/hda of=/dev/hdb conv=noerror,sync

  • Eric J February 20, 2012, 1:18 pm

    I believe you can. It wouldn’t hurt anything if you did, but the new drive would need to be at least or larger than the old one.

  • CesarIII February 20, 2012, 4:27 pm

    It is possible, if both hard drives are the same manufacturer, model.
    If not, you may have a partition table with wrong disk description.
    Try something like:

    dd bs=100MB if=/dev/hda of=/dev/hdb

    to make it in less time.


  • Greg January 9, 2016, 1:53 am

    One thing to watch out for when doing partition backups (I found this out the hard way). Partitions have ‘uuid’ values which are intended to be unique for each partition, and that gets cloned in the dd copy. This can be a problem if you leave the backup partition on the machine, since many systems use the uuids in the /etc/fstab

    For instance my laptop has this line in /etc/fstab:

    UUID=893f11f2-d032-45a9-8f34-bae72858dd11 / ext4 errors=remount-ro 0

    … which specifies that the partition with that UUID should be mounted on ‘/’. So, what happens if you copy that to another partition and then reboot? It may be unpredictable which of the two gets mounted. I had a machine set up for months, two 1 TB drives, and a 50 GB root partition at the start of each; one was a real root and the other a backup. But sometimes when I rebooted the machine without switching it off, it would act strange, e.g. ask for updates I’d already done … turned out that under those conditions it was actually mounting the backup as the root partition…

    To avoid this, there’s a way to change the uuid after you do the copy so that this won’t happen, it should be done right after you make the image copy, using tune2fs, as described here: http://www.sudo-juice.com/how-to-change-the-uuid-of-a-linux-partition/

    The use of UUIDs was intended to avoid problems using e.g. /dev/sdb, since the assignment of sda, sdb etc could change at a later reboot due to other drives being attached.
    Another approach to avoid this: the system creates symlinks in /dev/disk/by-id to /dev/sda1 etc, which are built from drive model # and serial #’s. for instance I have this

    ata-WDC_WD7500BPKX-22HPJT0_WD-WX41A93N9898-part1 -> ../../sda1

    ..so if I use /dev/disk/by-id/ata-WDC_WD7500BPKX-22HPJT0_WD-WX41A93N9898-part1 to identify the partition, that will find the same partition even the particular drive is at sdb or sdc. That string includes both the drive model and serial #, so it will work even I have two drives of the same model.

    A mount specified by UUID, on the other hand, will keep working if I replicate the partition to a new drive (including the UUID) and replace the old drive with the new one; whereas a mount using the drive identity would need to be updated. So the choice of one or the other depends on what problem you want to avoid.

Security: Are you a robot or human?

Leave a Comment

   Tagged with: , , , , , , , , , , , , , , , , ,