ThisCalculator

Everyday

How to Clone ext4 Partitions Safely

Updated · Standard formula, shown below

How to Clone ext4 Partitions Safely

Cloning an ext4 partition copies its filesystem and files to another partition or disk, which is useful for migration, backup, or replacement. The safest method is to work from a Linux live environment and use GNU ddrescue for a byte-for-byte copy; the destination partition must be at least as large as the source. This guide explains how to identify devices, make the clone, and check it before relying on it.

What You’ll Need

  • A Linux computer or bootable Linux live USB with a terminal.
  • The source and destination drives connected at the same time.
  • A backup of important files. A clone is not a substitute for a separate backup.
  • GNU ddrescue installed. On Debian- or Ubuntu-based systems, the package is commonly named gddrescue.
  • Administrator access, enough time for the copy, and a destination partition at least as large as the source.

Step-by-Step

  1. Boot a live Linux session. If either partition is part of the system currently running, boot from a live USB instead. Do not clone a mounted, actively changing filesystem: writes during the copy can leave the destination inconsistent. Avoid opening either partition in a file manager, which may mount it automatically.
  2. Identify source and destination carefully. In a terminal, run lsblk -o NAME,SIZE,FSTYPE,LABEL,UUID,MOUNTPOINTS. Match devices using their size, filesystem, label, and mount point; never rely on a device name alone, because names can change after reboot. For example, /dev/sda2 is a partition, while /dev/sda is an entire drive. Write down the exact source and destination partition paths.
  3. Check the sizes and unmount both partitions. Use sudo blockdev --getsize64 /dev/source and repeat for /dev/destination, replacing the example paths with your actual ones. The destination must have at least as many bytes as the source. If either partition is mounted, unmount it with sudo umount /dev/source or the corresponding destination command. Check lsblk again to confirm the mount points are blank. Do not proceed if you cannot confidently identify the devices.
  4. Install ddrescue if needed. On a Debian- or Ubuntu-based live session, connect to the network and run sudo apt update, followed by sudo apt install gddrescue. The command used to run the program is ddrescue. Other Linux distributions may use a different package name; consult that distribution’s package manager.
  5. Copy the partition. Run sudo ddrescue -f -n /dev/source /dev/destination /tmp/ext4-clone.map, substituting the real partition paths. The -f option permits writing to the destination, and -n makes an initial pass without retrying difficult areas. The map file records progress; keep it if you may need to resume. This command overwrites the destination partition’s contents. Check the source and destination paths one more time before pressing Enter.
  6. Retry read errors if appropriate. If ddrescue reports read errors and the source is still accessible, you can make a limited retry pass with sudo ddrescue -f -r3 /dev/source /dev/destination /tmp/ext4-clone.map. This reuses the map file and attempts up to three retries. If the source drive is making unusual noises, repeatedly disconnecting, or deteriorating, stop and consider professional data recovery rather than stressing it with repeated reads.
  7. Check the cloned filesystem. First confirm the copy completed and the destination is still unmounted. Run sudo e2fsck -f -n /dev/destination. The -n option answers no to proposed repairs, so this is a check rather than a repair. Review the output; if it reports errors, preserve the original and consider making a second copy before any repair attempt.
  8. Mount and verify files. Create temporary mount points with sudo mkdir -p /mnt/source-check /mnt/clone-check, then mount each partition read-only: sudo mount -o ro /dev/source /mnt/source-check and sudo mount -o ro /dev/destination /mnt/clone-check. Compare directory listings and open several important files. When finished, unmount them with sudo umount /mnt/source-check /mnt/clone-check.
  9. Address duplicate UUIDs before using both copies together. A block-level clone carries over the ext4 UUID. If both filesystems are connected, tools may select or mount the wrong one by UUID. To give the clone a new UUID, keep it unmounted and run sudo tune2fs -U random /dev/destination. Update any boot configuration or /etc/fstab entries that should refer to the clone, and verify the new UUID with sudo blkid /dev/destination.

Common Mistakes

  • Reversing the paths: ddrescue writes to its second device argument. Putting the original there can destroy the source. Verify both paths and sizes immediately before running it.
  • Cloning a mounted partition: Active changes may not be represented consistently. Unmount it, or boot from another environment first.
  • Using a smaller destination: A raw copy requires a destination at least as large as the source, even if the source contains little data. Shrinking ext4 safely requires separate filesystem and partition steps before cloning.
  • Confusing a disk with a partition: Copying to /dev/sdb is not the same as copying to /dev/sdb1. Choose the intended destination precisely; writing to a whole disk overwrites its partition table and other contents.
  • Forgetting UUID duplication: Identical UUIDs can cause ambiguous mounts or boot behavior when the original and clone are connected at once.
  • Treating a successful copy as a verified backup: Run a filesystem check and inspect important files. Keep another independent backup until the clone has been tested.

Tips

  • For a straightforward copy of a healthy, unmounted partition, sudo dd if=/dev/source of=/dev/destination bs=4M status=progress conv=fsync is another option. It is less forgiving of read errors and has no resume map, so ddrescue is generally safer when the source condition is uncertain.
  • Save the ddrescue map file somewhere persistent if the operation may be interrupted; a file under /tmp can disappear when the live session ends.
  • For a portable file-level backup rather than an identical partition, use a filesystem-aware backup tool instead. A raw clone copies unused space as well as data and duplicates filesystem identifiers.
  • Keep the original unchanged until you have confirmed the clone works in its intended role. If using it as a boot partition, cloning that partition alone may not copy the bootloader, EFI system partition, or other required system partitions.

Troubleshooting

  • “Device is busy” or unmount fails: Check lsblk for mount points. Close file-manager windows using the partition, exit shells whose current directory is on it, and unmount any listed mount points. Do not force a clone while it is in use.
  • Destination is too small: Choose a larger partition or disk. Do not assume that free space inside ext4 makes a smaller raw destination safe. A deliberate shrink-and-copy procedure needs additional checks and should be done on a backup, not the only original.
  • ddrescue cannot open a device: Recheck the device path and permissions, then use sudo. Confirm the drive is connected and visible in lsblk.
  • The filesystem check reports errors: Keep the source safe and do not immediately repair your only clone. Make another copy if possible. Once you have a verified backup, you can consider a repair with e2fsck -f on the unmounted destination; repairs can change data.
  • The clone does not boot: A partition clone copies that partition’s contents, not necessarily the full boot setup. Check whether the system also needs other partitions, a bootloader installation, or updated UUID references. Test changes with the original preserved.

Frequently Asked Questions

Does cloning copy deleted files?
A raw clone copies filesystem blocks, including unused areas, but it does not guarantee recovery of deleted data. Some blocks may already have been overwritten or may not be readable.

Can I clone an ext4 partition to a larger partition?
Yes. The clone initially retains the original filesystem size, leaving extra destination space unused. After verifying the copy, grow the filesystem with an appropriate ext4 resizing procedure if you want to use that space.

Can I clone a mounted ext4 partition?
It is not recommended for a consistent copy. Boot from a live environment and unmount the partition first, or use a filesystem-aware snapshot and backup method designed for online copying.

Will the cloned partition have the same UUID?
Yes, a raw clone duplicates it. If both copies will be connected at once, assign the clone a new UUID and update any configuration that refers to it.

Does this copy the whole disk?
No. The commands above copy one partition. To reproduce a bootable disk, you may also need its partition table, EFI or boot partitions, and bootloader setup.

Can I clone ext4 to a different filesystem?
A raw clone is for a destination partition intended to contain the same ext4 filesystem. To move files to another filesystem, copy files with a tool that preserves the attributes you need instead of copying blocks.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.