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 if=INPUT-FILE-NAME of=OUTPUT-FILE-NAME
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
Where,
- /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
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop









![Sending Email With Attachments From Unix / Linux Command [ Shell Prompt ]](http://s13.cyberciti.org/images/shared/rp/3/26.jpg)




{ 9 comments… read them below or add one }
I know that you can later on mount partition-level dd dumps. Can you also somehow mount the dump of an entire disk?
RE: Jann…
dunno, give it a try. In unixland, you’d do something like:
mkdir /mnt/mountpoint
mount -t ext3 /somepath/ /mnt/mountpoint
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.
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?
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
Regards,
CesarIII
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?
Thanks!
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
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.
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.
CesarIII