How to back up and restore your server using dd disk images | INTROSERV
EUR
european

EUR

usa

USD

English En
Ex. VAT Ex. VAT 0%

How to back up and restore your server using dd disk images

dd creates a sector-by-sector image of an entire disk. You can use this image to restore the disk to the state it was in at the time of the backup. This guide shows how to create a disk image with dd and how to restore from it. Because dd works at the disk level, run it from a live environment (Finnix), not from the running system you are copying.

Use dd when you need a block-level copy of an entire disk. For file-level backups (individual files and folders) rsync or tar are usually a better fit.

Before you start

  • Finnix ISO
  • access to the server's IP-KVM (IP-based KVM)
  • storage with enough free space for the image (see the note in the backup scenarios)
  • SSH credentials, if you back up to remote storage
  • root access

1. A short note on dd

dd copies data block by block. The parts of the command that matter:

  • if= source (what you read from)
  • of= target (what you write to)
  • bs=8M sets the block size and can improve copy performance
  • status=progress shows how much has been copied, useful on large disks

By default the commands below copy a healthy disk. If the source disk has read errors, add conv=noerror,sync: dd then continues past read errors instead of stopping, and pads unreadable blocks with zeros. This keeps the following blocks aligned, but the padded areas lose their data, so the filesystem in the image may be damaged. For a failing disk, consider ddrescue, which is designed to recover data from failing disks and keeps a map of read errors.

Warning

dd overwrites the target completely and without asking. A wrong of= destroys data. Always check the device names before you run anything.

2. Preparation

Boot from Finnix. Mount the Finnix ISO through IP-KVM and boot the server from it. This lets you work with the server disks without running the installed operating system from the disk you are backing up. Avoid imaging a running system: if the source disk has mounted filesystems that are being modified, the image may be inconsistent. Make sure the source disk is not in use by the running environment.

Identify the disks. List the disks with their sizes and mount points:

lsblk -o NAME,SIZE,TYPE,MOUNTPOINTS

As an alternative:

fdisk -l

Find the system disk (for example /dev/sda) and note its device name. This is the most important step: dd does not ask for confirmation, so a mistake here wipes the wrong disk. In the commands below, /dev/sda is only an example. Replace it with the actual disk you identified with lsblk. Make sure the source disk shows no mount points in the lsblk output before you image it.

3. Scenario A: Back up to cloud storage over SSHFS (CloudBox)

Use this to store the image on INTROSERV CloudBox or any SSH storage. Take the SSH credentials (user, host, path) from your order details.

Create a mount point:

mkdir -p /mnt/backup

Mount the cloud storage:

sshfs user@host:/path /mnt/backup

Create the disk image:

dd if=/dev/sda of=/mnt/backup/sda.img bs=8M status=progress

When dd finishes, it reports how much data was copied. The image sda.img is now on your cloud storage.

Info

A large copy over SSHFS can be slow. If the SSH connection drops, the copy may fail and the image may be incomplete.

Info

The image size is approximately the size of the whole source disk, not the amount of used data. A 2 TB disk with 100 GB of data still produces an image of about 2 TB. Make sure the storage has enough free space.

Optional: to save space and reduce network transfer, compress the image while creating it:

dd if=/dev/sda bs=8M status=progress | gzip -c > /mnt/backup/sda.img.gz

Restore a compressed image with:

gunzip -c /mnt/backup/sda.img.gz | dd of=/dev/sda bs=8M status=progress

The compressed size depends on how compressible the disk contents are. The checksum check below applies to an uncompressed .img.

4. Scenario B: Back up to another physical disk in the same server

Use this if the server has a second disk (for example /dev/sdb) large enough to hold the image. The target disk must have enough free space for an image of the entire source disk, and it must not be the source disk.

Create a mount point and mount the second disk:

mkdir -p /mnt/backup mount /dev/sdb1 /mnt/backup

Create the disk image:

dd if=/dev/sda of=/mnt/backup/sda.img bs=8M status=progress

5. Verify the image (optional)

To verify the image, calculate the SHA-256 checksum of the source disk and of the image and compare them. The source disk must not change between creating the image and calculating the checksum. This reads the whole disk again, so it takes time on large disks:

sha256sum /dev/sda sha256sum /mnt/backup/sda.img

The two values should match.

6. Restoration

Restoration is the backup in reverse: the image becomes the source (if=) and the disk becomes the target (of=). Boot from Finnix again and mount the storage that holds the image, the same way as during backup.

Before you restore, make sure the target disk is not smaller than the original. A full-disk image cannot be restored to a smaller disk, even if little data was used on the source.

From cloud storage:

dd if=/mnt/backup/sda.img of=/dev/sda bs=8M status=progress

From a second disk, mount it first, then run the same command. Here too /dev/sda is only an example. Replace it with the actual target disk.

Warning

Restoration overwrites the whole target disk. Make sure of= points to the disk you want to restore to. When dd finishes, reboot the server and boot from the restored disk.

If the target disk is larger than the original, the extra space is left unused. You can extend the partition and filesystem afterwards if needed; the exact commands depend on the partition layout and filesystem. If you restore to different hardware, additional boot configuration may be required. If the source disk uses LVM, LUKS, RAID, or another storage layer, additional configuration may be required after restoring, especially on different hardware.

VAT

  • Other

    Ex. VAT

    0%
  • austria

    Austria

    20%
  • Belgium

    Belgium

    21%
  • Bulgaria

    Bulgaria

    20%
  • Croatia

    Croatia

    25%
  • Cyprus

    Cyprus

    19%
  • Czech Republic

    Czech Republic

    21%
  • Denmark

    Denmark

    25%
  • Estonia

    Estonia

    22%
  • France

    France

    20%
  • Finland

    Finland

    24%
  • Germany

    Germany

    19%
  • Greece

    Greece

    24%
  • Hungary

    Hungary

    27%
  • Ireland

    Ireland

    23%
  • Italy

    Italy

    22%
  • Latvia

    Latvia

    21%
  • Lithuania

    Lithuania

    21%
  • Luxembourg

    Luxembourg

    17%
  • Malta

    Malta

    18%
  • Netherlands

    Netherlands

    21%
  • Poland

    Poland

    23%
  • Portugal

    Portugal

    23%
  • Romania

    Romania

    19%
  • Slovakia

    Slovakia

    20%
  • Slovenia

    Slovenia

    22%
  • Spain

    Spain

    21%
  • Sweden

    Sweden

    25%
  • USA

    USA

    0%
european
states
  • germany
  • Español
  • Italiano
  • Poland
  • Русский
  • Slovenski
  • Türkçe
  • ukraine
  • kingdom
  • French
  • Hrvatska
  • Other
  • Austria
  • Belgium
  • Bulgaria
  • Croatia
  • Cyprus
  • Czech Republic
  • Denmark
  • Estonia
  • Finland
  • France
  • Germany
  • Greece
  • Hungary
  • Ireland
  • Italy
  • Latvia
  • Lithuania
  • Luxembourg
  • Malta
  • Netherlands
  • Poland
  • Portugal
  • Romania
  • Slovakia
  • Slovenia
  • Spain
  • Sweden
  • USA