Skip to content

Commit 6feae60

Browse files
committed
Add guide on copying GPT partition tables between disks and update ZFS pool creation tutorial for improved clarity and performance tips.
1 parent 3c8d28c commit 6feae60

File tree

2 files changed

+319
-60
lines changed

2 files changed

+319
-60
lines changed
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
---
2+
title: "How to Copy GPT Partition Table Between Disks"
3+
date: 2025-02-16T01:30:00-05:00
4+
draft: false
5+
tags: ["GPT", "Partitioning", "Linux", "RAID"]
6+
categories:
7+
- Storage
8+
- Linux
9+
- Disk Management
10+
author: "Matthew Mattox - mmattox@support.tools"
11+
description: "A quick guide on copying a GPT partition table between disks when setting up RAID or disk cloning."
12+
more_link: "yes"
13+
url: "/how-to-copy-gpt-partition-table/"
14+
---
15+
16+
## Why Copy GPT Partition Tables?
17+
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`.
18+
19+
## Prerequisites and Safety Checks
20+
21+
### Backup Your Data
22+
🔴 **WARNING**: Always backup important data before manipulating partition tables!
23+
```bash
24+
# Create a backup of the partition table
25+
sudo sgdisk --backup=disk1_backup.gpt /dev/sd_src
26+
27+
# Optional: Create full disk image
28+
sudo dd if=/dev/sd_src of=disk1_full_backup.img bs=4M status=progress
29+
```
30+
31+
### Verify Disk Identification
32+
```bash
33+
# List all disks with their identifiers
34+
lsblk -o NAME,SIZE,MODEL,SERIAL
35+
36+
# Show detailed disk information
37+
sudo fdisk -l
38+
```
39+
40+
## Install `gdisk`
41+
Install `gdisk` based on your distribution:
42+
43+
### Ubuntu/Debian:
44+
```bash
45+
sudo apt-get install -y gdisk
46+
```
47+
48+
### RHEL/CentOS/Fedora:
49+
```bash
50+
sudo dnf install -y gdisk
51+
```
52+
53+
### Arch Linux:
54+
```bash
55+
sudo pacman -S gptfdisk
56+
```
57+
58+
## Copy GPT Partition Table
59+
60+
### Basic Copy Operation
61+
```bash
62+
# Copy partition table
63+
sudo sgdisk -R /dev/sd_dest /dev/sd_src
64+
65+
# Verify the operation succeeded
66+
echo $?
67+
```
68+
69+
### Advanced Copy Options
70+
```bash
71+
# Copy with progress information
72+
sudo sgdisk --display-alignment -R /dev/sd_dest /dev/sd_src
73+
74+
# Copy and preserve original UUIDs (use with caution)
75+
sudo sgdisk --backup=original.gpt /dev/sd_src
76+
sudo sgdisk --load-backup=original.gpt /dev/sd_dest
77+
```
78+
79+
### Explanation:
80+
- `-R /dev/sd_dest /dev/sd_src` → Copies the partition table from **source disk** to **destination disk**
81+
- `--display-alignment` → Shows alignment information during copy
82+
- `--backup` → Creates a backup of the partition table
83+
- `--load-backup` → Restores a partition table from backup
84+
85+
## Update UUIDs for Unique Identification
86+
87+
### Randomize UUIDs
88+
```bash
89+
# Generate new UUIDs
90+
sudo sgdisk -G /dev/sd_dest
91+
92+
# Verify unique UUIDs
93+
sudo blkid /dev/sd_src*
94+
sudo blkid /dev/sd_dest*
95+
```
96+
97+
### Why is this necessary?
98+
- Prevents **duplicate partition** detection
99+
- Avoids **boot failures** and system confusion
100+
- Essential for **RAID** and **multi-disk** setups
101+
- Prevents **mount conflicts** in fstab
102+
103+
## Verification Steps
104+
105+
### Check Partition Table
106+
```bash
107+
# Compare partition tables
108+
sudo sgdisk -p /dev/sd_src
109+
sudo sgdisk -p /dev/sd_dest
110+
111+
# Verify alignment
112+
sudo sgdisk --verify /dev/sd_dest
113+
```
114+
115+
### Validate Partitions
116+
```bash
117+
# List all partitions
118+
sudo fdisk -l /dev/sd_dest
119+
120+
# Check partition details
121+
sudo parted /dev/sd_dest print
122+
```
123+
124+
## Troubleshooting
125+
126+
### Common Issues and Solutions
127+
128+
1. **Disk Busy Error**
129+
```bash
130+
# Unmount all partitions
131+
sudo umount /dev/sd_dest*
132+
133+
# Stop any RAID arrays
134+
sudo mdadm --stop /dev/md*
135+
```
136+
137+
2. **Invalid GPT Error**
138+
```bash
139+
# Fix GPT errors
140+
sudo sgdisk --verify /dev/sd_dest
141+
sudo sgdisk --rebuild-gpt /dev/sd_dest
142+
```
143+
144+
3. **UUID Conflicts**
145+
```bash
146+
# Force UUID regeneration
147+
sudo sgdisk --randomize-guids /dev/sd_dest
148+
```
149+
150+
## Real-World Examples
151+
152+
### Setting up Software RAID
153+
```bash
154+
# Copy partition table to all RAID disks
155+
for disk in /dev/sd[b-e]; do
156+
sudo sgdisk -R $disk /dev/sda
157+
sudo sgdisk -G $disk
158+
done
159+
```
160+
161+
### Preparing for Disk Migration
162+
```bash
163+
# Copy and preserve alignment
164+
sudo sgdisk --display-alignment -R /dev/newdisk /dev/olddisk
165+
sudo sgdisk -G /dev/newdisk
166+
```
167+
168+
## Recovery Procedures
169+
170+
### Restore from Backup
171+
```bash
172+
# Restore partition table from backup
173+
sudo sgdisk --load-backup=disk1_backup.gpt /dev/sd_dest
174+
175+
# Verify restoration
176+
sudo sgdisk -p /dev/sd_dest
177+
```
178+
179+
### Emergency Recovery
180+
```bash
181+
# Attempt to recover damaged GPT
182+
sudo sgdisk --rebuild-gpt /dev/sd_dest
183+
184+
# Create new protective MBR
185+
sudo sgdisk --gpttombr /dev/sd_dest
186+
```
187+
188+
## Conclusion
189+
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.
190+
191+
### Best Practices
192+
1. **Always backup** before partition operations
193+
2. **Verify disk identifiers** carefully
194+
3. **Check UUIDs** after copying
195+
4. **Test mount points** after completion
196+
5. **Keep backup files** until verification is complete

0 commit comments

Comments
 (0)