How do I create a compressed backup image of a Red Hat Enterprise Linux machine to an external drive using dd?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 4
  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7

Issue

  • How do I create a compressed backup image of a Red Hat Enterprise Linux machine to an external drive using dd?
  • Is it possible to create an image of installed system and use it to boot the system?

Resolution

To create a compressed disk image with "dd" :

  1. Boot into rescue mode with the installation media

  2. Create a mount point for your external drive:

    # mkdir /mnt/external
    
  3. Mount your external drive:

    # mount /dev/sdb1 /mnt/external
    
  4. Create the compressed disk image:

    # dd if=/dev/sda | gzip -9 > /mnt/external/filename.img.gz
    

To recover this in future, run the following command :

# zcat /mnt/external/filename.img.gz | dd of=/dev/sda

Note: Do not use dd to backup block devices that are currently in use. Doing so will likely cause inconsistency on the filesystem(s).

Create an image of installed system

  • To create an image of installed system, get USB of exact same size.
  • Recreate the initrd with USB support
# vi /etc/dracut.conf
        add_drivers+="ehci-hcd uhci-hcd xhci-hcd usb-storage scsi-mod sd-mod sd hid-microsoft hid-generic usbhid"     
# dracut -f -v
  • Force a file check on boot
#  touch /forcefsck
  • Create image using dd command:
#  dd if=/dev/sda  of=/dev/<usb device> bs=8192
  • Add any subsequent partitions to the usb drive in 4gb chunks.
  • Insert usb and boot machine.

Disclaimer: The following information has been provided by Red Hat, but is outside the scope of our posted Service Level Agreements and support procedures. The information is provided as-is and any configuration settings or installed applications made from the information in this article could make your Operating System unsupported by Red Hat Support Services. The intent of this article is to provide you with information to accomplish your system needs. Use the information in this article at your own risk.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

5 Comments

Dear Redhat Team,
Can I use dd command in a running system ?.

Hello Ashraf,

Thank you for your comment. It's not recommended to run dd command on filesystem which is currently in use and hence the note: Do not use dd to backup block devices that are currently in use. Doing so will likely cause inconsistency on the filesystem(s).

Hope this helps.

Best Regards, Amol Deshmukh

Thanks What is best way for taking Linux Image and restore operation. Regards Ashraf

irrespective of the system configuration and Memory space , can i take image of RHEL7 with 3rd Party Softwares and data into 1 TB external HD.

For backup image and restore you can make use of the Red Hat provided utility - ReaR (Relax and Restore). I've used it successfully for Red Hat 7 both Physical/VM imaging and restoring.

ReaR

Cheers \(-_-)//