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
    root
  2. List available disks and partitions to identify the source device.
    $ lsblk
    NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
    loop0    7:0    0     1G  0 loop /mnt/data
    loop1    7:1    0   512M  0 loop 
    loop2    7:2    0   128M  0 loop 
    ##### snipped #####
    vda    254:0    0   1.8T  0 disk 
    `-vda1 254:1    0   1.8T  0 part /etc/hosts
                                     /etc/hostname
                                     /etc/resolv.conf
    vdb    254:16   0 606.5M  1 disk

    In this example, the loop device loop2 is used as the cloning source.

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

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

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

    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
    overlay         1.8T   14G  1.7T   1% /

    The filesystem storing the image file must provide at least as much free space as the source size; here the root filesystem has ample space for the loop-device image.

  6. Run dd to clone the source partition into an image file.
    $ sudo dd if=/dev/loop2 of=/root/sg-work/disk-lab/clone-src-backup.img conv=noerror,sync status=progress
    262144+0 records in
    262144+0 records out
    134217728 bytes (134 MB, 128 MiB) copied, 0.258536 s, 519 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/sg-work/disk-lab/clone-src-backup.img
    /root/sg-work/disk-lab/clone-src-backup.img: Linux rev 1.0 ext4 filesystem data, UUID=5527e155-295b-46d9-9f98-4bcc3121d1c2, volume name "clone-src" (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/clone-test
    $ sudo mount -o loop /root/sg-work/disk-lab/clone-src-backup.img /mnt/clone-test
    $ ls /mnt/clone-test
    lost+found
    sample.txt

    After inspection, detach the loop mount with

    sudo umount /mnt/clone-test

    to release /mnt/clone-test.

Discuss the article:

Comment anonymously. Login not required.