Linux backup entire disk drive image to a file or another drive with dd command

Posted on August 7, 2008 by admin.
Categories: Linux tips and tricks.

You can:

Clone from one hard drive to another of different size:
Backup a drive to another drive dd
Use dd command to image
Backup drive using linux
Linux dd backup drive or Linux disk image dd

This works with Windows 7, Mac OS X, Vista and any Linux.

Note: If you just want to backup or restore your partition table and or the MBR click here.

From Linux Questions Wiki:

Creating a hard drive backup directly to another hard drive, or linux backup entire disk.

# dd if=/dev/hda of=/dev/sda conv=noerror,sync bs=4k

This command is used often to create a backup of a drive (/dev/hda) directly to another hard drive (/dev/sda). The device name /dev/hda is typical of an IDE hard drive, the device /dev/sda is typical of a USB disk – key drive. This works only if the destination hard drive (of=) has enough storage to accommodate the source drive’s (if=) filesystem. The advantage of this is that you do not have to mount the hard drive to make a backup and the only reference to hda is in /dev and in the command which is usually in a script in cron. Another huge advantage of using dd to clone one hard drive to another is that this is the only way I know of that copies raw data instead of partitions, so you can clone an encrypted drive or one without partitions.

The option “bs=4k” is used to specify the block size used in the copy. The default for the dd command is 512 bytes: use of this small block size can result in significantly slower copying. However, the tradeoff with larger block sizes is that when an error is encountered, the remainder of the block is filled with zero-bytes. So if you increase your block size when copying a failing device, you’ll lose more data but also spend less time trying to read broken sectors. Tools like dd_rescue and dd_rhelp can provide a more flexible solution in such cases, combining the speed of a large block size for the regions without errors with finer-grained block-copies for regions with errors.

Creating a hard drive backup image or dd command image backup linux.

# dd if=/dev/hda | gzip > /mnt/hdb1/system_drive_backup.img.gz

Here dd is making an image of the first harddrive, and piping it through the gzip compression program. The compressed image is then placed in a file on a seperate drive. To reverse the process:

# gzip -dc /mnt/hdb1/system_drive_backup.img.gz | dd of=/dev/hda

Here, gzip is decompressing (the -d switch) the file, sending the results to stdout (the -c switch), which are piped to dd, and then written to /dev/hda.

To backup or copy a cd to a file with linux using dd is very easy:

dd if=/dev/cdrom of=image.iso bs=2k.

3 comments.

AiL0
Comment on February 9th, 2012.

mas que un comentario es una pregunta, me pidieron investigar si drive image 7 funciona para discos de linux, supongo que se refieren a si se puede hacer un clon en imagen del windows 7, no se si pudieran ayudarme al respecto me seria muy util de antemano muchas gracias

Comment on February 9th, 2012.

AiL0 – Here’s what I got of your question from a google translate:
“but a comment is a question I was asked to investigate whether drive image 7 discs works for linux, I guess you refer to if you can make a clone image of windows 7 do not know if I could help in this regard would be very useful for advance thank you very much”

The dd command from linux works for getting and image of windows 7 also, though I use it most often to copy a boot sector and partition table.

For reliably creating and restoring Linux or Windows 7 disk images I’ve had good results with my favorite program “Image for Linux”. It has an option to use Windows 7 MBR compatible image, but you have to set that in the program options at the first screen, before you start the actual imaging process.

For entire operating system backups as an image, I’ve had good results with Acronis True Image, Norton Ghost, Paragon, Active Disk Image, Drive Snapshot, dd, and a couple others. Of these I prefer Drive Snapshot for creating a disk image out from under a running Windows. But the most reliable disk image for me is “Image for Windows” or it’s partner program “Image for Linux”, which I run from a boot disk to get an image of Windows while it’s not running.

codvali
Comment on July 10th, 2012.

Great post !!!

Leave a comment

Names and email addresses are required (email addresses aren't displayed), url's are optional.

Comments may contain the following xhtml tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>