How to Copy GPT Partition Table Between Disks
On this page
Why Copy GPT Partition Tables?
When configuring RAID or setting up identical disks, it’s essential to have the same partition tables across all disks. While sfdisk worked well for MBR (msdos) partition tables, it does not support GPT. Fortunately, we can achieve this using sgdisk.
Prerequisites and Safety Checks
Backup Your Data
🔴 WARNING: Always backup important data before manipulating partition tables!
bash
# Create a backup of the partition table
sudo sgdisk --backup=disk1_backup.gpt /dev/sd_src
# Optional: Create full disk image
sudo dd if=/dev/sd_src of=disk1_full_backup.img bs=4M status=progressVerify Disk Identification
bash
# List all disks with their identifiers
lsblk -o NAME,SIZE,MODEL,SERIAL
# Show detailed disk information
sudo fdisk -lInstall gdisk
Install gdisk based on your distribution:
Ubuntu/Debian:
bash
sudo apt-get install -y gdiskRHEL/CentOS/Fedora:
bash
sudo dnf install -y gdiskArch Linux:
bash
sudo pacman -S gptfdiskCopy GPT Partition Table
Basic Copy Operation
bash
# Copy partition table
sudo sgdisk -R /dev/sd_dest /dev/sd_src
# Verify the operation succeeded
echo $?Advanced Copy Options
bash
# Copy with progress information
sudo sgdisk --display-alignment -R /dev/sd_dest /dev/sd_src
# Copy and preserve original UUIDs (use with caution)
sudo sgdisk --backup=original.gpt /dev/sd_src
sudo sgdisk --load-backup=original.gpt /dev/sd_destExplanation:
-R /dev/sd_dest /dev/sd_src→ Copies the partition table from source disk to destination disk--display-alignment→ Shows alignment information during copy--backup→ Creates a backup of the partition table--load-backup→ Restores a partition table from backup
Update UUIDs for Unique Identification
Randomize UUIDs
bash
# Generate new UUIDs
sudo sgdisk -G /dev/sd_dest
# Verify unique UUIDs
sudo blkid /dev/sd_src*
sudo blkid /dev/sd_dest*Why is this necessary?
- Prevents duplicate partition detection
- Avoids boot failures and system confusion
- Essential for RAID and multi-disk setups
- Prevents mount conflicts in fstab
Verification Steps
Check Partition Table
bash
# Compare partition tables
sudo sgdisk -p /dev/sd_src
sudo sgdisk -p /dev/sd_dest
# Verify alignment
sudo sgdisk --verify /dev/sd_destValidate Partitions
bash
# List all partitions
sudo fdisk -l /dev/sd_dest
# Check partition details
sudo parted /dev/sd_dest printTroubleshooting
Common Issues and Solutions
Disk Busy Error
bash# Unmount all partitions sudo umount /dev/sd_dest* # Stop any RAID arrays sudo mdadm --stop /dev/md*Invalid GPT Error
bash# Fix GPT errors sudo sgdisk --verify /dev/sd_dest sudo sgdisk --rebuild-gpt /dev/sd_destUUID Conflicts
bash# Force UUID regeneration sudo sgdisk --randomize-guids /dev/sd_dest
Real-World Examples
Setting up Software RAID
bash
# Copy partition table to all RAID disks
for disk in /dev/sd[b-e]; do
sudo sgdisk -R $disk /dev/sda
sudo sgdisk -G $disk
donePreparing for Disk Migration
bash
# Copy and preserve alignment
sudo sgdisk --display-alignment -R /dev/newdisk /dev/olddisk
sudo sgdisk -G /dev/newdiskRecovery Procedures
Restore from Backup
bash
# Restore partition table from backup
sudo sgdisk --load-backup=disk1_backup.gpt /dev/sd_dest
# Verify restoration
sudo sgdisk -p /dev/sd_destEmergency Recovery
bash
# Attempt to recover damaged GPT
sudo sgdisk --rebuild-gpt /dev/sd_dest
# Create new protective MBR
sudo sgdisk --gpttombr /dev/sd_destConclusion
Using sgdisk, you can reliably clone GPT partition tables between disks, ensuring consistency in RAID setups and disk cloning operations. This method provides robust support for modern GPT-based partitions with built-in safety features and verification options.
Best Practices
- Always backup before partition operations
- Verify disk identifiers carefully
- Check UUIDs after copying
- Test mount points after completion
- Keep backup files until verification is complete