Cloning a hard drive or partition in Linux provides an exact backup for recovery, migration, and forensic analysis. A cloned image preserves all data, including partition layout and boot information, so a system can be restored or examined without modifying the original disk.

Block-level tools such as dd operate on device files like /dev/sdb1, reading raw sectors and writing them to another device or image file. Because this method works below the filesystem layer, every bit on the source is copied, including unused space and metadata, which is ideal for full-system replicas and low-level troubleshooting.

Operating at this level also carries risk because a single mistake in device names can overwrite critical data. Confirming the correct source and target with lsblk, unmounting filesystems before cloning, and checking available free space on the destination filesystem are essential precautions when running dd with elevated privileges.

Steps to clone hard drive or partition using dd:

  1. Open a terminal with sudo privileges.
    $ whoami
    user
  2. List available disks and partitions to identify the source device.
    $ lsblk
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    loop0    7:0    0 88.5M  1 loop /snap/core/7270
    loop1    7:1    0 54.1M  1 loop /snap/lxd/10972
    loop2    7:2    0 89.4M  1 loop /snap/core/6818
    loop3    7:3    0 54.1M  1 loop /snap/lxd/11098
    loop4    7:4    0 89.3M  1 loop /snap/core/6673
    sda      8:0    0   20G  0 disk
    ├─sda1   8:1    0    1M  0 part
    └─sda2   8:2    0   20G  0 part /
    sdb      8:16   0    5G  0 disk
    └─sdb1   8:17   0    5G  0 part /mnt/data
    sr0     11:0    1  748M  0 rom

    In this example, the partition sdb1 is a 5 GiB partition mounted on /mnt/data and serves as the cloning source.

  3. Confirm the source partition and note its device path.

    Careful selection of the source device (for example, /dev/sdb1) prevents accidental overwriting of another disk.

  4. Unmount the selected source partition before cloning.
    $ sudo umount --force /dev/sdb1

    Cloning a mounted filesystem can capture inconsistent data and may corrupt the resulting image.

  5. Check available free space on the target filesystem that will hold the image file.
    $ df -h /
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda2        20G  5.2G   14G  28% /

    The filesystem storing the image file must provide at least as much free space as the source size; here /dev/sda2 offers 14 GiB free for a 5 GiB source.

  6. Run dd to clone the source partition into an image file.
    $ sudo dd if=/dev/sdb1 of=/root/sdb1-backup.img conv=noerror,sync status=progress
    [sudo] password for user:
    5347731456 bytes (5.3 GB, 5.0 GiB) copied, 49 s, 109 MB/s
    10483712+0 records in
    10483712+0 records out
    5367660544 bytes (5.4 GB, 5.0 GiB) copied, 49.2271 s, 109 MB/s

    Reversing if and of or pointing of to the wrong device irreversibly overwrites data on the target disk.

  7. Verify the resulting image file format and filesystem metadata.
    $ sudo file /root/sdb1-backup.img
    /root/sdb1-backup.img: Linux rev 1.0 ext4 filesystem data, UUID=d430e0a1-ec3e-4bed-b16a-e2d35d0f4ed6 (extents) (64bit) (large files) (huge files)

    The file output confirms that the image contains a recognized ext4 filesystem header.

  8. Optionally test-mount the image via a loop device to validate contents.
    $ sudo mkdir --parents /mnt/sdb1-test
    $ sudo mount -o loop /root/sdb1-backup.img /mnt/sdb1-test
    $ ls /mnt/sdb1-test
    ##### snipped #####

    After inspection, detach the loop mount with

    sudo umount /mnt/sdb1-test

    to release /mnt/sdb1-test.

Discuss the article:

Comment anonymously. Login not required.