How to Safely Clone an Ubuntu System Disk with dd: Step‑by‑Step Guide
This article provides a comprehensive, step‑by‑step guide on using the low‑level dd tool to back up and restore an Ubuntu system disk, covering prerequisites, preparation, command examples, optional compression, feasibility analysis, precautions, and a concise conclusion.
Overview
ddis a low‑level data copying tool that can clone an entire disk or partition bit‑by‑bit. Using
ddto back up the system disk creates an exact replica of the OS, configuration files, installed software, and user data.
Prerequisites
Source device : the disk containing the system, e.g.,
/dev/sda.
Target device or file : another disk (e.g.,
/dev/sdb) or a backup file such as
/mnt/backup/system_backup.img. This guide tests backup to an image file.
Spare storage : a device with capacity equal to or larger than the source.
Bootable LiveCD/LiveUSB : used to perform the backup while the system is offline.
Preparation before backup
Prepare LiveCD/LiveUSB : download an Ubuntu ISO and create a bootable medium; boot from it to avoid filesystem changes during backup.
Confirm device names : use
lsblkto identify source and target names.
<code>lsblk</code>Check disk capacity : ensure the target has enough space for the source data.
Environment description : the test environment uses
/dev/sdaas the source,
/dev/sdbas the backup storage, and
/dev/sdcas the LiveUSB.
Backup procedure
Use dd to create the backup :
If the target is another disk:
<code>sudo dd if=/dev/sda of=/dev/sdb bs=4M status=progress</code>If the target is a backup file:
<code>sudo dd if=/dev/sda of=/mnt/ubuntu_2.0.img bs=4M status=progress</code>Optional compression : pipe the output through
gzipto reduce file size when storage is limited.
<code>sudo dd if=/dev/sda bs=4M | gzip > /mnt/backup/system_backup.img.gz</code>Restore procedure
Restore from backup file to disk :
<code>sudo mount /dev/sdb1 /mnt
sudo dd if=/mnt/ubuntu_2.0.img of=/dev/sda bs=4M status=progress</code>If the backup file is compressed:
<code>gunzip -c /mnt/backup/system_backup.img.gz | sudo dd of=/dev/sda bs=4M status=progress</code>Restore from backup disk to original disk :
<code>sudo dd if=/dev/sdb of=/dev/sda bs=4M status=progress</code>Feasibility analysis
Advantages :
ddprovides a simple, direct method that copies the entire system, including boot sector and partition table, suitable for exact hardware restoration.
Disadvantages : backup can be time‑consuming and the resulting image size equals the source disk unless compressed; hardware differences may require additional adjustments after restore.
Applicable scenarios : system migration, disaster recovery, and replicating identical environments.
Precautions
Do not write to the source device during backup or restore to avoid data inconsistency.
If the target capacity is smaller than the source,
ddcannot create a full backup.
When using LiveCD/LiveUSB, ensure the target device is correctly recognized and free of corruption.
Conclusion
Using
ddto back up an Ubuntu system disk is a reliable method for full‑system cloning and recovery. With optional compression and proper disk management, the large backup size can be mitigated, ensuring the system can be restored to a working state when needed.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.