Replace a disk in a RAID
- Remove the disk from the array.
- Determine the disk partition scheme.
- Copy the partition table to the new disk.
- Add the disk to the RAID array.
- Install the bootloader.
1. Remove the disk from the array
-
Output current RAID array configuration:
cat /proc/mdstatThe output will contain information about the RAID array configuration. Example:
Personalities : [raid1]md1 : active raid1 sda3[0] sdb3[1]975628288 blocks super 1.2 [2/2] [UU]bitmap: 3/8 pages [12KB], 65536KB chunkmd0 : active raid1 sda2[2] sdb2[1]999872 blocks super 1.2 [2/2] [UU]unused devices: <none>Where:
md0— name of the RAID array assembled from thesda2andsdb2;md1— name of the RAID array assembled from thesda3andsdb3.
-
Output information about partitions on the disks and RAID array configuration:
lsblkThe output will contain a list of disks with partitions. Example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTloop0 7:0 0 985M 1 loopsda 8:0 0 931.5G 0 disk├─sda1 8:1 0 1M 0 part├─sda2 8:2 0 977M 0 part│ └─md0 9:0 0 976.4M 0 raid1└─sda3 8:3 0 930.6G 0 part└─md1 9:1 0 930.4G 0 raid1 /sdb 8:16 0 931.5G 0 disk├─sdb1 8:17 0 1M 0 part├─sdb2 8:18 0 977M 0 part│ └─md0 9:0 0 976.4M 0 raid1└─sdb3 8:19 0 930.6G 0 part└─md1 9:1 0 930.4G 0 raid1 /Where:
sda— name of the disk with functioning RAID arrays;sdb— name of the disk to be replaced;sdb2— name of the partition on disksdbthat is a component of the first RAID array;md0— name of the first RAID array assembled from thesda2andsdb2;sdb3— name of the partition on disksdbthat is a component of the second RAID array;md1— name of the second RAID array assembled from thesda3andsdb3.
-
Mark the disk you need to replace as faulty:
mdadm /dev/<raid_array_1> -f /dev/<partition_1>mdadm /dev/<raid_array_2> -f /dev/<partition_2>Specify:
<raid_array_1>— name of the first RAID array that you obtained in step 3; in this example, it ismd0;<partition_1>— name of the first RAID array partition on the replacement disk that you obtained in step 3; in this example, it issdb2;<raid_array_2>— name of the second RAID array that you obtained in step 3; in this example, it ismd1;<partition_2>— name of the second RAID array partition on the replacement disk that you obtained in step 3; in this example, it issdb3.
-
Remove the disk you marked as faulty in step 4 from all devices:
mdadm /dev/<raid_array_1> --remove /dev/<partition_1>mdadm /dev/<raid_array_2> --remove /dev/<partition_2>Specify:
<raid_array_1>— name of the first RAID array that you obtained in step 3; in this example, it ismd0;<partition_1>— name of the first RAID array partition on the replacement disk that you obtained in step 3; in this example, it issdb2;<raid_array_2>— name of the second RAID array that you obtained in step 3; in this example, it ismd1;<partition_2>— name of the second RAID array partition on the replacement disk that you obtained in step 3; in this example, it issdb3.
2. Determine the disk partition scheme
-
Install the utility for working with the GPT (GUID Partition Table) on disks —
gdisk:apt-get install gdisk -y -
Output information about partitions on the disks:
lsblkThe output will contain information about partitions on the disks. Example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTloop0 7:0 0 985M 1 loopsda 8:0 0 931.5G 0 disk├─sda1 8:1 0 1M 0 part├─sda2 8:2 0 977M 0 part│ └─md0 9:0 0 976.4M 0 raid1└─sda3 8:3 0 930.6G 0 part└─md1 9:1 0 930.4G 0 raid1 /sdb 8:16 0 931.5G 0 diskWhere:
sda— name of the disk with functioning RAID partitions;sdb— name of the new disk.
-
Determine the disk partition scheme:
gdisk -l /dev/<source_disk>Specify
<source_disk>— name of the disk with functioning RAID partitions that you obtained in step 3; in this example, it issda.The answer depends on the disk partition scheme:
-
GPT:
Partition table scan:MBR: protectiveBSD: not presentAPM: not presentGPT: present -
MBR:
Partition table scan:MBR: MBR onlyBSD: not presentAPM: not presentGPT: not present
-
3. Copy the partition table to the new disk
The partition table copying process depends on the disk partition scheme — GPT or MBR.
When copying the partition table, it is essential to specify the disks in the correct order in the command. If the disk order is incorrect, the healthy disk will be overwritten, and data will be deleted. Data cannot be recovered.
GPT
MBR
-
Output information about partitions on the disks:
lsblkThe output will contain information about partitions on the disks. Example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTloop0 7:0 0 985M 1 loopsda 8:0 0 931.5G 0 disk├─sda1 8:1 0 1M 0 part├─sda2 8:2 0 977M 0 part│ └─md0 9:0 0 976.4M 0 raid1└─sda3 8:3 0 930.6G 0 part└─md1 9:1 0 930.4G 0 raid1 /sdb 8:16 0 931.5G 0 diskWhere:
sda— name of the disk with functioning RAID partitions;sdb— name of the new disk.
-
Copy the partition table to the new disk. It is essential to specify the disks in the correct order in the command; otherwise, the partition table and data on the originally healthy disk will be destroyed.
sgdisk -R /dev/<new_disk> /dev/<source_disk>Specify:
<new_disk>— name of the new disk to which the partition layout is copied; you obtained it in step 2; in this example, it issdb;<source_disk>— name of the disk with functioning RAID partitions from which the partition layout is copied; you obtained it in step 2; in this example, it issda.
-
Assign a random UUID to the new disk:
sgdisk -G /dev/<new_disk>Specify
<new_disk>— name of the new disk to which the partition layout was copied; you obtained it in step 2; in this example, it issdb. -
Ensure the partition schemes on the disks are identical:
lsblkThe output will contain information about partitions on the disks. Example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTloop0 7:0 0 985M 1 loopsda 8:0 0 931.5G 0 disk├─sda1 8:1 0 1M 0 part├─sda2 8:2 0 977M 0 part│ └─md0 9:0 0 976.4M 0 raid1└─sda3 8:3 0 930.6G 0 part└─md1 9:1 0 930.4G 0 raid1 /sdb 8:16 0 931.5G 0 disk├─sdb1 8:17 0 1M 0 part├─sdb2 8:18 0 977M 0 part└─sdb3 8:19 0 930.6G 0 part
4. Add the disk to the RAID array
-
Output information about partitions on the disks and RAID array configuration:
lsblkThe output will contain information about partitions on the disks and RAID array configuration. Example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTloop0 7:0 0 985M 1 loopsda 8:0 0 931.5G 0 disk├─sda1 8:1 0 1M 0 part├─sda2 8:2 0 977M 0 part│ └─md0 9:0 0 976.4M 0 raid1└─sda3 8:3 0 930.6G 0 part└─md1 9:1 0 930.4G 0 raid1 /sdb 8:16 0 931.5G 0 disk├─sdb1 8:17 0 1M 0 part├─sdb2 8:18 0 977M 0 part└─sdb3 8:19 0 930.6G 0 partWhere:
md0— name of the first RAID array which is assembled from thesda2;md1— name of the second RAID array which is assembled from thesda3;sdb2— name of the first partition on the new disk to be added to the RAID array;sdb3— name of the second partition on the new disk to be added to the RAID array.
-
Add the partitions of the new disk to the RAID array:
mdadm /dev/<raid_array_1> -a /dev/<partition_1>mdadm /dev/<raid_array_2> -a /dev/<partition_2>Specify:
<raid_array_1>— name of the first RAID array that you obtained in step 2; in this example, it ismd0;<partition_1>— name of the first partition on the new disk that you obtained in step 2; in this example, it issdb2;<raid_array_2>— name of the second RAID array that you obtained in step 2; in this example, it ismd1;<partition_2>— name of the second partition on the new disk that you obtained in step 2; in this example, it issdb3.
After adding a disk to a RAID array, synchronization will start. The synchronization speed depends on the size and type of the disk — SSD or HDD.
-
Wait for synchronization to complete.
-
Ensure that the new disk has been added to the RAID array:
lsblkThe output will contain information about partitions on the disks and RAID array configuration. Example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTloop0 7:0 0 985M 1 loopsda 8:0 0 931.5G 0 disk├─sda1 8:1 0 1M 0 part├─sda2 8:2 0 977M 0 part│ └─md0 9:0 0 976.4M 0 raid1└─sda3 8:3 0 930.6G 0 part└─md1 9:1 0 930.4G 0 raid1 /sdb 8:16 0 931.5G 0 disk├─sdb1 8:17 0 1M 0 part├─sdb2 8:18 0 977M 0 part│ └─md0 9:0 0 976.4M 0 raid1└─sdb3 8:19 0 930.6G 0 part└─md1 9:1 0 930.4G 0 raid1 /
5. Install the bootloader
After adding the disk to the array, you need to install the OS bootloader on it.
You can install the bootloader both in the OS and in Rescue mode.
Server booted into the OS
Server booted in Rescue mode
-
Output information about partitions on the disks:
lsblk -o +FSTYPEThe output will contain information about partitions on the disks. Example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT FSTYPEloop0 7:0 0 985M 1 loopsda 8:0 0 931.5G 0 disk├─sda1 8:1 0 500M 0 part vfat├─sda2 8:2 0 977M 0 part│ └─md0 9:0 0 976.4M 0 raid1 ext4└─sda3 8:3 0 930.1G 0 part└─md1 9:1 0 929.9G 0 raid1 /sdb 8:16 0 931.5G 0 disk├─sdb1 8:17 0 500M 0 part├─sdb2 8:18 0 977M 0 part│ └─md0 9:0 0 976.4M 0 raid1 ext4└─sdb3 8:19 0 930.1G 0 part└─md1 9:1 0 929.9G 0 raid1 / ext4Where:
sda— name of the disk with functioning RAID arrays;sdb— name of the new disk.
-
Install the GRUB bootloader:
grub-install /dev/<new_disk>Specify
<new_disk>— name of the new disk that you obtained in step 2; in this example, it issdb.