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 MOUNTPOINTS
    loop0    7:0    0   512M  0 loop /mnt/bench
    loop1    7:1    0   300M  0 loop 
    loop2    7:2    0   128M  0 loop /mnt/clone-src
    nbd0    43:0    0     0B  0 disk 
    nbd1    43:32   0     0B  0 disk 
    nbd2    43:64   0     0B  0 disk 
    nbd3    43:96   0     0B  0 disk 
    nbd4    43:128  0     0B  0 disk 
    nbd5    43:160  0     0B  0 disk 
    nbd6    43:192  0     0B  0 disk 
    nbd7    43:224  0     0B  0 disk 
    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 
    nbd8    43:256  0     0B  0 disk 
    nbd9    43:288  0     0B  0 disk 
    nbd10   43:320  0     0B  0 disk 
    nbd11   43:352  0     0B  0 disk 
    nbd12   43:384  0     0B  0 disk 
    nbd13   43:416  0     0B  0 disk 
    nbd14   43:448  0     0B  0 disk 
    nbd15   43:480  0     0B  0 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   17G  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.232926 s, 576 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=a2d80e37-1b32-43c0-9afb-7b6d72794042, 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.