Copy a partition using dd or ddrescue from the command line

The fastest way to copy a partition from one drive to another on a Raspberry Pi is to use dd, a command-line tool that reads data block-by-block and writes it exactly as-is to the destination. You identify the source partition (like /dev/sda1) and the target partition (like /dev/sdb1), then run a single command that clones everything — the filesystem, files, permissions, and boot information all at once.

Before you start, connect both drives to your Raspberry Pi via USB adapter or dock. Open a terminal and run lsblk to see which device name each drive has. The output shows device names like sda, sdb, sdc, and partition numbers like sda1, sda2. Write down the exact names — getting these wrong will overwrite the wrong drive and destroy data.

If your source partition is damaged or has bad sectors, use ddrescue instead of dd. It reads around errors and logs which sectors failed, so you recover what you can rather than stopping at the first problem. Install it with sudo apt install gddrescue, then run sudo ddrescue /dev/sda1 /dev/sdb1 logfile.txt. The logfile tracks which areas had trouble.

Key Takeaways

  • Use lsblk to identify the exact device and partition names before running any copy command, because a mistake will overwrite the wrong drive.
  • The dd command copies a partition byte-for-byte, including the filesystem and all permissions, in one operation.
  • Make sure the target partition is at least as large as the source partition, or the copy will fail partway through.
  • Unmount both partitions before copying — a partition in use may copy incomplete or corrupted data.
  • Use ddrescue instead of dd if the source drive has physical damage or read errors.

Unmount both partitions before you copy

A partition that is mounted (actively in use by the operating system) cannot be safely copied. The system may be writing to it while dd is reading, which means the copy will be incomplete or corrupted. Before you start, unmount both the source and target partitions.

If the source partition is your Raspberry Pi's own boot or root drive, you cannot unmount it while the Pi is running from it. In that case, boot from a USB drive or SD card instead, then unmount the internal drive and copy it. If you do not have a second boot device, shut down the Pi, remove the drive you want to copy, connect it to another computer, and run dd from there.

To unmount a partition, run sudo umount /dev/sda1 (replace sda1 with your actual partition name). If the system says the partition is busy, close any open files on that drive and try again. Verify it is unmounted by running lsblk again — the MOUNTPOINT column should be empty for that partition.

Run the dd command with the correct source and target

Once both partitions are unmounted, the basic dd command is:

sudo dd if=/dev/sda1 of=/dev/sdb1 bs=4M status=progress

Break this down: if= is the input file (source partition), of= is the output file (target partition), bs=4M sets the block size to 4 megabytes (faster than the default), and status=progress shows you how much has been copied so far. Replace sda1 and sdb1 with your actual partition names.

The command will run silently for a while, then show a progress bar. Do not interrupt it — stopping dd partway through leaves the target partition incomplete and unusable. Depending on the partition size, copying can take minutes to hours. A 64 GB partition typically takes 10 to 30 minutes on a Raspberry Pi 4.

When dd finishes, it prints a summary showing how many bytes were copied. If the number matches the size of your source partition (check with lsblk), the copy succeeded. If the numbers do not match, the copy was incomplete — do not use the target drive.

Verify the copy is complete and bootable

After dd finishes, mount the target partition and spot-check a few files to make sure they copied correctly. Run sudo mount /dev/sdb1 /mnt, then ls /mnt to list the files. If you see the expected directories and files, the copy worked.

If you copied a boot partition (like the Raspberry Pi's /boot directory), test it by connecting the target drive to the Pi and booting from it. If you copied the root filesystem, do the same test. A successful boot means the partition is usable. If the Pi does not boot or shows errors, the copy may have been corrupted — go back to the source drive and try again.

Unmount the target partition when you are done checking: sudo umount /mnt. If you plan to use this partition as a replacement, you can now physically remove the source drive and use the target drive in its place.

Handle partitions of different sizes

If your target partition is smaller than the source, dd will fail because there is not enough space. If your target partition is larger, dd will copy only the data that exists on the source — the extra space on the target will be unused.

To use the extra space on a larger target partition, you need to resize the filesystem after copying. First, copy the partition with dd as normal. Then run sudo e2fsck -f /dev/sdb1 to check the filesystem, followed by sudo resize2fs /dev/sdb1 to expand it to fill the entire partition. These commands work for ext4 filesystems (the standard on Raspberry Pi). If your partition uses a different filesystem, the resize command will differ.

If you need to shrink a partition before copying (because the target is smaller), you must resize the source filesystem first, then resize the partition itself, then copy. This is complex and error-prone — it is usually easier to use a larger target drive or delete files from the source to make it smaller.

Use Clonezilla for a graphical interface

If you prefer not to use the command line, Clonezilla is a free tool that copies partitions with a menu-driven interface. read the Clonezilla ISO, write it to a USB drive using Balena Etcher or a similar tool, boot your Raspberry Pi from that USB drive, and follow the on-screen prompts to select source and target partitions.

Clonezilla is slower than dd because it includes extra checks and logging, but it is more forgiving for beginners — it will not let you accidentally overwrite the wrong drive, and it shows you exactly what it is about to do before it does it. The trade-off is that a large partition may take significantly longer to copy.

To use Clonezilla on a Raspberry Pi, you need a USB adapter that supports booting. Not all Raspberry Pi models boot from USB reliably, so test this before you rely on it for an important backup.

Frequently Asked Questions

What if dd says "No space left on device"?

The target partition is smaller than the source. Check the sizes with lsblk and make sure the target is at least as large as the source. If you need to use a smaller target, delete files from the source first or use a larger drive.

Can I copy a partition while the Raspberry Pi is running?

Not safely. If the partition you are copying is in use, the copy will be incomplete or corrupted. Boot from a different drive or shut down and connect both drives to another computer.

How do I know if the copy worked?

Mount the target partition and check that files are there and readable. If you copied a boot partition, test by booting from it. If the Pi starts normally, the copy succeeded.

What is the difference between dd and ddrescue?

dd stops if it hits a read error. ddrescue skips bad sectors and keeps going, so you recover most of the data even if the source drive is damaged. Use ddrescue if the source drive has physical problems.

Do I need to format the target partition before copying?

No. dd overwrites the entire partition, so any existing data and filesystem on the target will be replaced. Formatting first is unnecessary and wastes time.