How To Copy Partition To Another Hard Drive On Raspberry Pi: The Complete Migration Guide

How To Copy Partition To Another Hard Drive On Raspberry Pi: The Complete Migration Guide

Format Drive Raspberry Pi | How to Partition and Format the Hard Drives ...

Migrating a Raspberry Pi partition to an external hard drive or SSD requires a block-level clone using the dd utility or a file-level synchronization via rsync to ensure system integrity. Successful execution hinges on accurately updating the Partition Universally Unique Identifier (PARTUUID) within the cmdline.txt and fstab configuration files to prevent boot sequence failures.


Essential Hardware Configuration and Pre-Migration Planning

Transitioning your Raspberry Pi from a standard microSD card to a high-performance Hard Disk Drive (HDD) or Solid State Drive (SSD) significantly enhances input/output (I/O) speeds and long-term data reliability. Before initiating the transfer, you must evaluate the power requirements of your target drive. A standard Raspberry Pi 4 or 5 provides limited current through its USB ports; a mechanical HDD often requires an external power source or a powered USB hub to prevent undervoltage warnings and filesystem corruption.

The scope of this procedure involves cloning the primary Linux partition (ext4) and potentially the boot partition (FAT32) from your current storage medium to a new destination. You must account for the difference in storage capacities. If the destination drive is smaller than the source, you will need to shrink the source partition using tools like GParted before the migration. Conversely, if the destination is larger, you will perform a partition expansion after the copy is complete.

Mandatory Pre-Operation Checklist:



  • Target Storage Device: A high-end SSD or HDD with a USB 3.0 interface for optimal throughput.
  • Power Supply: A dedicated 5V/3A (for Pi 4) or 5V/5A (for Pi 5) power adapter to handle the increased load of the external drive.
  • Operating System Access: A terminal interface via SSH or a direct monitor and keyboard setup.
  • Data Integrity: A verified backup of critical files, as partition manipulation carries an inherent risk of data loss.
  • Time Allocation: 30 to 90 minutes depending on the volume of data and the bus speed of the storage interfaces.

Strategic Execution of the Partition Migration Process

The following steps detail the transition from a microSD card (typically identified as /dev/mmcblk0) to an external USB drive (typically identified as /dev/sda).



Step 1: Identification of Storage Device Architecture

Before any data is moved, you must precisely identify the device paths for both your source and destination. Connecting the external hard drive via a USB 3.0 port (the blue ports on a Raspberry Pi 4/5) is critical for performance.



  1. Open the terminal and execute the command lsblk. This lists all block devices.
  2. Locate your microSD card, which usually appears as mmcblk0 with two partitions: mmcblk0p1 (boot) and mmcblk0p2 (root).
  3. Identify your external hard drive. It will likely appear as sda, with partitions sda1, sda2, etc., if it has been previously formatted.
  4. Confirm the sizes to ensure you are targeting the correct physical hardware. Use the command sudo fdisk -l for a more granular view of the disk sectors and identifiers.


Step 2: Preparing the Destination Environment

If your external drive contains existing data, it must be wiped and re-partitioned to mirror the Raspberry Pi’s requirements. You can use the fdisk utility to create a new partition table.



  1. Launch the fdisk utility for your target drive by typing sudo fdisk /dev/sda.
  2. Delete existing partitions by pressing d and selecting the partition numbers.
  3. Create a new partition by pressing n, then follow the prompts for primary partition types. For a standard root partition, accept the default start and end sectors to utilize the full disk.
  4. Change the partition type if necessary by pressing t, though the default Linux type is usually sufficient for the root filesystem.
  5. Write the changes to the disk by pressing w.
  6. Format the new partition with the ext4 filesystem by executing sudo mkfs.ext4 /dev/sda1.


Step 3: Executing the Data Synchronization

While the dd command is a common choice for cloning, the rsync utility is often superior for live systems because it operates at the file level and handles open files more gracefully. However, for a perfect bit-for-bit copy of an inactive partition, dd is the industry standard.



  1. Create temporary mount points for the transfer process using sudo mkdir /mnt/target.
  2. Mount the external drive partition: sudo mount /dev/sda1 /mnt/target.
  3. To clone the root filesystem while the system is running, use rsync with flags that preserve permissions, ownership, and special files: sudo rsync -axHAWXS --numeric-ids --info=progress2 --exclude='/proc/' --exclude='/export/' --exclude='/sys/' --exclude='/dev/' --exclude='/run/' --exclude='/scripts/' --exclude='/tmp/*' --exclude='/lost+found' / /mnt/target.
  4. Wait for the synchronization to finish. The --info=progress2 flag provides a real-time transfer rate and percentage completion, which is essential for monitoring large data volumes.

Pro-Tip: If you prefer a block-level clone and are running this from a separate Linux machine with both the Pi SD card and the HDD plugged in, use: sudo dd if=/dev/sdb2 of=/dev/sdc1 bs=4M status=progress conv=fsync. This ensures that the buffer is fully flushed to the physical disk before completion.



Step 4: Configuring the Boot Sequence and PARTUUIDs

The Raspberry Pi does not boot by looking for /dev/sda1; it looks for a specific PARTUUID. When you copy a partition, you must ensure the boot configuration points to the new hardware ID.



  1. Retrieve the PARTUUID of your new partition by running blkid /dev/sda1. Copy the alphanumeric string found in the PARTUUID field.
  2. Mount the boot partition of your SD card: sudo mount /dev/mmcblk0p1 /mnt/target/boot (or directly edit the files in /boot if you are on the running Pi).
  3. Edit the cmdline.txt file: sudo nano /boot/cmdline.txt.
  4. Locate the section that says root=PARTUUID=xxxx-xx and replace the existing ID with the new PARTUUID from your external drive. Ensure the rootfstype is set to ext4.
  5. Save and exit (Ctrl+O, Enter, Ctrl+X).
  6. Update the filesystem table on the new drive: sudo nano /mnt/target/etc/fstab.
  7. Replace the PARTUUID for the / (root) entry with the new ID. This ensures that once the kernel loads, it mounts the external drive as the root filesystem.

Warning: Failure to update both cmdline.txt and fstab will result in an "Emergency Mode" boot loop or a kernel panic, as the system will attempt to mount a root partition that does not match the expected identifier.



Step 5: Partition Expansion and Verification

Once the Pi boots from the external drive, the OS may still believe it is confined to the size of the original partition if you used a block-level clone (dd).



  1. Reboot the system: sudo reboot.
  2. After logging back in, check the disk space using df -h.
  3. If the size does not reflect the external drive's capacity, use the resize2fs tool.
  4. Open the partition tool: sudo fdisk /dev/sda. Delete the root partition and recreate it with the exact same starting sector but a larger ending sector. This does not delete the data; it only updates the partition table.
  5. Run sudo resize2fs /dev/sda1 to expand the filesystem to fill the new partition boundaries.

How to turbo-charge your Raspberry Pi 5 with an NVMe boot drive ...

How to turbo-charge your Raspberry Pi 5 with an NVMe boot drive ...

Technical Comparison of Migration Methodologies



Feature dd (Block-Level) rsync (File-Level) SD Card Copier (GUI)
Transfer Accuracy 100% bit-for-bit match High (File-based) High (Optimized for Pi)
Speed Limited by slowest bus speed Variable; fast for incremental Moderate
Live Migration Dangerous on mounted drives Safe with proper excludes Safe
Flexibility Target must be $\ge$ Source Target can be any size Target must be $\ge$ Data size
Complexity Low (Single command) High (Requires flag knowledge) Very Low (Point and click)
Metadata Preservation Absolute Excellent with -aHAWXS flags Good

Troubleshooting Common Migration Failures

Partition cloning on ARM-based systems like the Raspberry Pi often encounters specific hurdles related to hardware initialization and Linux mount points.



  • Symptom: Kernel Panic - VFS: Unable to mount root fs on unknown-block(0,0)



    • Root Cause: The cmdline.txt file contains an incorrect PARTUUID or points to a device path that the kernel has not yet initialized.
    • Actionable Fix: Re-insert the SD card into a secondary computer, verify the PARTUUID of the external drive using blkid, and manually edit cmdline.txt to match the ID exactly. Ensure there are no trailing spaces or hidden characters in the file.
  • Symptom: Slow Performance or Random Disconnections



    • Root Cause: The USB-to-SATA bridge chip in the external drive housing is incompatible with the Raspberry Pi's UASP (USB Attached SCSI Protocol) implementation.
    • Actionable Fix: Disable UASP for that specific device by adding usb-storage.quirks=XXXX:YYYY:u (where XXXX:YYYY is the vendor and product ID from lsusb) to the beginning of the cmdline.txt file.
  • Symptom: Drive Not Detected During Boot



    • Root Cause: Insufficient power during the high-draw spin-up phase of an HDD or initialization of an SSD.
    • Actionable Fix: Use a double-headed USB "Y" cable to draw power from two ports or, preferably, switch to a dedicated 12V powered external desktop drive or a high-quality powered USB 3.0 hub.
  • Symptom: Permission Denied Errors After Migration



    • Root Cause: Using a copying method (like cp -r) that does not preserve root ownership and SUID bits.
    • Actionable Fix: Re-run the migration using rsync with the -a (archive) and -H (hard links) flags to ensure all system permissions remain intact.

Frequently Asked Questions



Can I copy a larger SD card partition to a smaller SSD?

Yes, but you must first shrink the source filesystem and partition using a tool like GParted on a separate Linux machine. The total used blocks on the source must be less than the total available blocks on the destination drive before using the dd or rsync command.



Why does my Raspberry Pi still require the SD card to be inserted?

On older models (Pi 3 and early Pi 4), the bootloader may still look at the SD card's FAT32 partition for the start.elf and fixup.dat files. You can configure the Pi 4 and 5 to boot entirely from USB by changing the boot order in the EEPROM configuration using the sudo raspi-config tool under Advanced Options.



Is it better to use a USB flash drive or a USB SSD?

A USB SSD is significantly better due to superior wear leveling and controller logic. Standard USB flash drives are not designed for the constant small-file random writes an operating system performs, leading to premature drive failure and significantly slower system responsiveness compared to even a budget SSD.



Do I need to format the new drive as FAT32 or EXT4?

The Raspberry Pi requires a small FAT32 partition for booting (containing the firmware and kernel) and a larger EXT4 partition for the Linux root filesystem. If you are only moving the root partition, the destination should be formatted as EXT4.

Optimize Your Raspberry Pi Infrastructure

Take your project to the next level by integrating professional-grade storage solutions that eliminate the bottlenecks of microSD cards. Implementing an external SSD migration ensures your Raspberry Pi remains stable and responsive under heavy server loads and complex automation tasks.


Run HatH On Portable External Hard Drive · Raspberry Pi Note

Run HatH On Portable External Hard Drive · Raspberry Pi Note

Read also: Ben McKenzie Documentary: The Definitive Breakdown of the "Easy Money" Fallout and Beyond