Using dd to create disk images

Never mind Acronis True Image – you can use the command line to work with disk images and backups, without any extra software.

Create a hard disk image:

dd if=/dev/hda1 of=/home/hda1.bin

Create a compressed disk image

dd if=/dev/hda1 | gzip > /home/hda1.bin.gz

Back up the MBR

dd if=/dev/hda of=/home/hda.boot.mbr bs=512 count=1

Restore MBR (from a Live CD)

dd if=/mnt/hda1/home/hda.boot.mbr of=/dev/hda bs=512 count=1

Backup a drive to another drive

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

This entry was posted in Ubuntu and tagged , . Bookmark the permalink.

6 Responses to Using dd to create disk images

  1. gb says:

    Thank you for this Dougie.

    I want to clone my whole ubuntu hdd installation onto a smaller hdd. Could you advise which command will do this?

    Thank you for your time.

    Best wishes,
    Grant

    Like or Dislike: Thumb up 0 Thumb down 0

  2. Dougie says:

    You would need to use the last command but would have to compress the image if the available space on the drive to be backed up is larger than the backup drive.

    However as easier solution is to install partimage (sudo apt-get install partimage) which is designed for this purpose.

    Like or Dislike: Thumb up 0 Thumb down 0

  3. alex says:

    quick question: would this last command (for backing up to another disk) create a partition of identical size?
    i ran out of space and am looking for ways to move the entire system to a bigger drive…
    thanks!

    Like or Dislike: Thumb up 0 Thumb down 0

  4. Dougie says:

    @Alex, yes it would but you can use tools such as GParted to expand the disk.

    Like or Dislike: Thumb up 0 Thumb down 0

  5. Lews Therin says:

    dd and dd_rescue are great, I use them all the time.

    The advantage for file system aware tools like Acronis or Clonezilla is that they are MUCH faster than dd. dd and dd_rescue are fantastic, especially where the drive has issues (bad sectors, etc) and other imaging tools fail.

    However, if you just need to quickly mirror a drive, dd is pretty slow. That is where Acronis and even better Clonezilla come in. Clonezilla will let you do disk to disk and disk to image transfers, will place the image over the network using SSHFS, SMB etc. Acronis is perfect for going from different size drives as it dynamically resizes the partitions, save a lot of time and steps.

    Of course you can get fancy and just pipe dd through netcat to a listening port on a receiving server too – but it is still painfully slow. Clonezille let’s you dump to a remote server considerably faster.

    Generally, I say use Acronis or Clonezilla if the drive health is good, and fall back to dd_rescue if not.

    If you are interested I have an article on Clonezilla here:

    http://www.timelordz.com/wiki/index.php/Clonezilla

    It’s very easy to set this up on a PXE server so you can save / restore images over a network – very slick!

    Cheers,
    Pete

    Like or Dislike: Thumb up 0 Thumb down 0

  6. Dougie says:

    @Lews, I use Clonezilla quite a bit, from System Rescue CD. Thanks for the link!

    Like or Dislike: Thumb up 0 Thumb down 0

Leave a Reply

Your email address will not be published.


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>