Replace a disk in a RAID
- Remove the disk from the array.
- Determine the disk partitioning 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
-
Connect to the server via SSH or via the KVM console.
-
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— the name of the RAID array assembled from partitionssda2andsdb2;md1— the name of the RAID array assembled from partitionssda3andsdb3.
-
Output information about partitions on the disks and RAID array configuration:
lsblkThe response will contain a list of disks with partitions. For 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— the name of the disk with working RAID arrays;sdb— the name of the disk to be replaced;sdb2— the name of the partition on disksdb, which is a component of the first RAID array;md0— the name of the first RAID array assembled from partitionssda2andsdb2;sdb3— the name of the partition on disksdb, which is a component of the second RAID array;md1— the name of the second RAID array assembled from partitionssda3andsdb3.
-
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>— the name of the first RAID array that you obtained in step 3, in the example it ismd0;<partition_1>— the name of the first RAID array partition on the disk to be replaced that you obtained in step 3, in the example it issdb2;<raid_array_2>— the name of the second RAID array that you obtained in step 3, in the example it ismd1;<partition_2>— the name of the second RAID array partition on the disk to be replaced that you obtained in step 3, in the 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>— the name of the first RAID array that you obtained in step 3, in the example it ismd0;<partition_1>— the name of the first RAID array partition on the disk to be replaced that you obtained in step 3, in the example it issdb2;<raid_array_2>— the name of the second RAID array that you obtained in step 3, in the example it ismd1;<partition_2>— the name of the second RAID array partition on the disk to be replaced that you obtained in step 3, in the example it issdb3.
2. Determine the disk partition scheme
-
Connect to the server via SSH or via the KVM console.
-
Install the utility for working with the GPT (GUID Partition Table) partition table on disks —
gdisk:apt-get install gdisk -y -
Output information about partitions on the disks:
lsblkThe response will contain information about partitions on the disks. For 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— the name of the disk with working RAID partitions;sdb— the name of the new disk.
-
Determine the disk partition scheme:
gdisk -l /dev/<source_disk>Specify
<source_disk>— the name of the disk with working RAID partitions that you obtained in step 3, in the 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 process of copying the partition table depends on the disk partitioning scheme — GPT or MBR.
When copying the layout, it is important to specify the disks in the correct order in the command. If the disk order is specified incorrectly, the healthy disk will be overwritten, and data will be deleted. Data cannot be recovered.
GPT
MBR
-
Connect to the server via SSH or via the KVM console.
-
Output information about partitions on the disks:
lsblkThe response will contain information about partitions on the disks. For 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— the name of the disk with working RAID partitions;sdb— the name of the new disk.
-
Copy the layout to the new disk. It is important to specify the disks in the correct order in the command; otherwise, the layout and data on the initially healthy disk will be destroyed.
sgdisk -R /dev/<new_disk> /dev/<source_disk>Specify:
<new_disk>— the name of the new disk to which the partition table is copied, you obtained it in step 2, in the example it issdb;<source_disk>— the name of the disk with working RAID partitions from which the partition table is copied, you obtained it in step 2, in the example it issda.
-
Assign a random UUID to the new disk:
sgdisk -G /dev/<new_disk>Specify
<new_disk>— the name of the new disk to which the partition table was copied, you obtained it in step 2, in the example it issdb. -
Ensure the partition schemes on the disks are identical:
lsblkThe response will contain information about partitions on the disks. For 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
-
Connect to the server via SSH or via the KVM console.
-
Output information about partitions on the disks and RAID array configuration:
lsblkThe response will contain information about partitions on the disks and RAID array configuration. For 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— the name of the first RAID array assembled from partitionsda2;md1— the name of the second RAID array assembled from partitionsda3;sdb2— the name of the first partition on the new disk to be added to the RAID array;sdb3— the 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>— the name of the first RAID array that you obtained in step 2, in the example it ismd0;<partition_1>— the name of the first partition on the new disk that you obtained in step 2, in the example it issdb2;<raid_array_2>— the name of the second RAID array that you obtained in step 2, in the example it ismd1;<partition_2>— the name of the second partition on the new disk that you obtained in step 2, in the example it issdb3.
After adding the disk to the RAID array, synchronization will start. The synchronization speed depends on the disk size and type — SSD or HDD.
-
Wait for synchronization to complete.
-
Ensure that the new disk has been added to the RAID array:
lsblkThe response will contain information about partitions on the disks and RAID array configuration. For 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 operating system 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
-
Connect to the server via SSH or via the KVM console.
-
Output information about partitions on the disks:
lsblk -o +FSTYPEThe response will contain information about partitions on the disks. For 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— the name of the disk with working RAID arrays;sdb— the name of the new disk.
-
Install the GRUB bootloader:
grub-install /dev/<new_disk>Specify
<new_disk>— the name of the new disk that you obtained in step 2, in the example it issdb.