mdadm Raid5 – How to replace failed drive GPT partition

Install gdisk. On debian squeeze you need to add main backports
vi /etc/apt/source.list
#Add below
deb http://backports.debian.org/debian-backports squeeze-backports main contrib non-free

Install gdisk
aptitude install gdisk

Drive sdb1 failed? Show details of partition md0
mdadm --detail /dev/md0

cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdc1[1] sdd1[2]
3907028864 blocks level 5, 64k chunk, algorithm 2 [3/2] [_UU]


Drive sdb1 is already removed. but if you need to remove it manually you can:

mdadm /dev/mmdadm /dev/md0 -r /dev/sdb1

SHUT DOWN IF YOU NEED TO REPALCE DRIVE. MAKE SURE NEW DRIVE IS STILL sdb.
Look how disk is structured and what partition type it has
sgdisk -p /dev/sdb
Disk /dev/sdb: 3907029168 sectors, 1.8 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): 0ED13F81-6EEA-4E12-9F27-DD806CF1F09C
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 3907029134
Partitions will be aligned on 8-sector boundaries
Total free space is 0 sectors (0 bytes)

Number Start (sector) End (sector) Size Code Name
1 34 3907029134 1.8 TiB FD00

Now copy partition A structure into partition B

#sgdisk -R=/dev/TO_THIS_DISK /dev/FROM_THIS_DISK
sgdisk -R=/dev/sdb /dev/sda
#Give new GUID since above options clones the disk including GUID
sgdisk -G /dev/sdb

Now readd the drive to md0

mdadm /dev/md0 -a /dev/sdb1

Check the status

cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb1[3] sda1[1] sdc1[2]
3907028864 blocks level 5, 64k chunk, algorithm 2 [3/2] [_UU]
[>....................] recovery = 0.0% (124204/1953514432) finish=786.3min speed=41401K/sec

Done. Check back in few hours to see if it finished.
Keywords: fdisk,sdisk, sgdisk, gdisk,parted,gpt, mbr,raid5,mdadm,linux,debian,