Clone a disk over SSH

You can copy a disk byte for byte to another server by piping dd through SSH, but on a running system that is risky and the target must not be running from the disk you overwrite. For CheapVPS servers the better method is almost always file-level: create the new server from the same image, then copy your data and configuration with rsync. This guide shows both, with progress, checksums and the fixes needed afterwards.

Servers and storage guide, updated 2026-12-03

When should you use dd and when rsync?

NeedToolWhy
Move a server to a new plan or cityrsyncCopies files only, works while both systems run, target keeps its own network and boot setup
Exact image of an unmounted data partitionddCopies every block, including filesystem metadata
Archive a disk image for forensicsdd to a fileKeeps deleted data and the exact layout
Regular copies of changing datarsync, restic, borgOnly changes travel

dd copies empty space too, so it moves the full disk size even if most of it is free. rsync moves only the files you have.

Why is cloning a booted system risky?

While Linux runs, files change constantly: logs, database pages, the journal. A block copy of a mounted, writable filesystem captures blocks from different moments and can produce a filesystem that needs repair or loses recent writes. Databases are the worst case.

The usual answer on physical machines is to boot a rescue system and copy an unmounted disk. Our servers have no rescue system, and the target server cannot overwrite the root disk it is running from. That is why a whole-disk dd between two CheapVPS servers is not a practical migration path; use it for data partitions or image files, and use rsync for systems.

How do you copy an unmounted partition with dd?

Say you have a separate data partition or loop image that you can unmount. First identify devices carefully on both sides:

lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINTS

Stop the services that use it and unmount it (umount /srv/data). Then stream it compressed to a file on the other server:

dd if=/dev/sdb1 bs=4M status=progress | gzip -1 | ssh root@198.51.100.20 "cat > /srv/images/data.img.gz"

Writing to a file is far safer than writing to a device on the target, because a typo cannot erase a running system. If you do write to a device, the target device must be unmounted, at least as large as the source, and named correctly:

dd if=/dev/sdb1 bs=4M | gzip -1 | ssh root@198.51.100.20 "gzip -d | dd of=/dev/sdb1 bs=4M"

Read the of= part twice before pressing Enter. dd does not ask for confirmation.

How do you show progress with pv?

status=progress works on the sending dd. pv gives a nicer bar with an ETA when you tell it the size:

apt install pv
SIZE=$(blockdev --getsize64 /dev/sdb1)
dd if=/dev/sdb1 bs=4M | pv -s "$SIZE" | gzip -1 | ssh root@198.51.100.20 "cat > /srv/images/data.img.gz"

gzip -1 is quick and shrinks empty, zero-filled areas very well. If CPU becomes the limit, try zstd -1 on both ends instead (zstd -d to decompress). Each byte sent counts as outgoing traffic from the source server, so a disk the size of 2 vCPU, 4 GB RAM, 80 GB NVMe needs room in the 20 TB allowance of P4 in Europe.

How do you verify the copy?

Compare checksums of the source and the result. For a device-to-device copy of the same size:

sha256sum /dev/sdb1
ssh root@198.51.100.20 sha256sum /dev/sdb1

For an image file, decompress on the fly:

ssh root@198.51.100.20 "gzip -dc /srv/images/data.img.gz | sha256sum"

The two hashes must be identical. If the target device is larger than the source, hash only the source length with head -c "$SIZE" /dev/sdb1 | sha256sum. Then check the filesystem without changing it: fsck -n /dev/sdb1 for ext4, xfs_repair -n for xfs.

How do you fix fstab and UUIDs after a block copy?

A dd copy carries the filesystem UUID along. Two filesystems with the same UUID on one machine confuse mounting, and a new disk may need a fresh entry. Read the values:

blkid /dev/sdb1

Give the copy a new UUID if both will be attached to one system: tune2fs -U random /dev/sdb1 for ext4 (run e2fsck -f first if asked), or xfs_admin -U generate /dev/sdb1 for xfs. Then update /etc/fstab with the UUID that blkid prints, run systemctl daemon-reload and test with mount -a before you reboot. A wrong fstab line can stop the boot, and with SSH as the only way in, test is not optional.

Why is file-level rsync usually better here?

For moving a server, the clean path is: create a new server with the same image, then copy the parts that make your system yours. The new server keeps its own kernel, boot loader, network configuration and disk UUIDs, so nothing needs fixing to boot. Steps:

  1. Order the new server with the same distribution and version; see creating a server.
  2. Install the same packages: on Debian and Ubuntu, export the list with dpkg --get-selections > pkgs.txt and restore it on the target with dpkg --set-selections < pkgs.txt && apt-get dselect-upgrade.
  3. Stop write-heavy services on the source and dump databases.
  4. Copy data and selected configuration.
rsync -aHAX --numeric-ids --info=progress2 /var/www/ root@198.51.100.20:/var/www/
rsync -aHAX --numeric-ids /etc/nginx/ root@198.51.100.20:/etc/nginx/
rsync -aHAX --numeric-ids /root/db-dumps/ root@198.51.100.20:/root/db-dumps/

Do not copy /etc/fstab, /etc/netplan or other network files, /etc/hostname, /boot, /proc, /sys or /dev. Run rsync a second time just before the switch; it sends only what changed.

What should you check before switching traffic?

On the new server, restore databases, start services and test with your domain pointed locally through /etc/hosts on your own computer. Compare file counts with find /var/www -type f | wc -l on both sides, check systemctl --failed and read journalctl -p err -b. When everything matches, change DNS as in pointing a domain, wait for the old server to go quiet, and delete it from the console. A delete wipes the disk, so keep your own backup until you are sure.

Questions about this guide

Can I dd the root disk of a running server?

You can read it, but the copy may be inconsistent because files change while it runs. For migrations, use a new server plus rsync.

Is there a rescue system for offline cloning?

No. Plan copies that work with both systems running, or unmount data partitions before a dd.

Can I copy a server to a different plan size?

Yes, with rsync. File-level copies do not care about disk size as long as the data fits; see moving to a bigger plan.

Does dd over SSH use my traffic allowance?

Yes, on the sending server. Compression with gzip -1 or zstd -1 keeps empty space from costing much.

Why does my clone not boot after dd?

Usually a UUID or fstab mismatch, or a target smaller than the source. That is the main reason we recommend the rsync method.

Can I move a server from Arm to x86 this way?

Not with dd. Use rsync for data and configuration, and install packages fresh on the new architecture.