Replace a disk in RAID
- Remove the disk from the array.
- Define a disk partitioning scheme.
- Copy the partitioning to the new disk.
- Add the disk to a RAID array.
- Install the bootloader.
1. Remove a disk from the array
-
Output the RAID configuration information:
cat /proc/mdstatRAID configuration information will appear in the response. For example:
Personalities : [raid1]
md1 : active raid1 sda3[0] sdb3[1]
975628288 blocks super 1.2 [2/2] [UU]
bitmap: 3/8 pages [12KB], 65536KB chunk
md0 : active raid1 sda2[2] sdb2[1]
999872 blocks super 1.2 [2/2] [UU]
unused devices: <none>Here:
md0- is the name of the RAID array that is assembled from the partitionssda2andsdb2;md1- is the name of the RAID array that is assembled from the partitionssda3andsdb3.
-
Output information about disk partitions and RAID configuration:
lsblkThe response will show a list of disks with partitions.For example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 985M 1 loop
sda 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 /Here:
sda- name of the disk with working RAID arrays;sdb- the name of the disk to be replaced;sdb2- disk partition namesdbwhich is a component of the first RAID array;md0- name of the first RAID array that is built from partitionssda2andsdb2;sdb3- disk partition namesdbwhich is a component of the second RAID array;md1- name of the second RAID array, which is built from partitionssda3andsdb3.
-
Mark the disk that needs to be replaced 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 you got in step 3, in the example it ismd0;<partition_1>- the partition name of the first RAID partition on the swap disk you got in step 3, in the example it issdb2;<raid_array_2>- the name of the second RAID you got in step 3, in the example it ismd1;<partition_2>- the partition name of the second RAID partition on the swap disk that you got in step 3, in the example it issdb3.
-
Remove the disk that 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 you got in step 3, in the example it ismd0;<partition_1>- the partition name of the first RAID partition on the swap disk you got in step 3, in the example it issdb2;<raid_array_2>- the name of the second RAID you got in step 3, in the example it ismd1;<partition_2>- the partition name of the second RAID partition on the swap disk that you got in step 3, in the example it issdb3.
2. Define the disk partitioning scheme
-
Install a utility to work with the GPT partition table (GUID Partition Table) on disks -
gdisk:apt-get install gdisk -y -
Print information about the partitions on the disks:
lsblkThe response will show information about the partitions on the disks.For example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 985M 1 loop
sda 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 diskHere:
sda- the name of the disk with working RAID partitions;sdb- the name of the new disk.
-
Define a disk partitioning scheme:
gdisk -l /dev/<source_disk>Specify
<source_disk>is the name of the working disk with RAID partitions that you got in step 3, in the example it issda.The answer depends on the disk partitioning scheme:
-
GPT:
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present -
MBR:
Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present
-
3. Copy the partitioning to a new disk
The process of copying partitioning depends on the disk partitioning scheme - GPT or MBR.
When copying partitioning, it is important to specify the disks in the correct order in the command.If the order of disks is specified incorrectly, the correct disk will be overwritten and the data will be deleted.The data cannot be recovered.
GPT
MBR
-
Print information about the partitions on the disks:
lsblkThe response will show information about the partitions on the disks.For example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 985M 1 loop
sda 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 diskHere:
sda- the name of the disk with working RAID partitions;sdb- the name of the new disk.
-
Copy the partitioning to the new disk.In the command, it is important to specify the disks in the correct order, otherwise the partitioning and data on the originally serviceable disk will be destroyed.
sgdisk -R /dev/<new_disk> /dev/<source_disk>Specify:
<new_disk>- the name of the new disk to which the partitioning is copied, you got it in step 2, in the example it issdb;<source_disk>- the name of the disk with working RAID partitions from which the partitioning is copied, you got 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>is the name of the new disk to which the partitioning was copied, you got it in step 2, in the example it issdb. -
Make sure that the partitioning on the disks matches completely:
lsblkThe response will show information about the partitions on the disks.For example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 985M 1 loop
sda 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
-
Print information about the partitions on the disks:
lsblkThe response will show information about the partitions on the disks.For example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 985M 1 loop
sda 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 diskHere:
sda- the name of the disk with working RAID partitions;sdb- the name of the new disk.
-
Copy the partitioning to the new disk.In the command, it is important to specify the disks in the correct order, otherwise the partitioning and data on the originally serviceable disk will be destroyed.
sfdisk -d /dev/<source_disk> | sfdisk /dev/<new_disk>Specify:
<source_disk>- name of the disk with working RAID partitions from which the partitioning is copied, you got it in step 2, in the example it issda;<new_disk>- the name of the new disk to which the partitioning is copied, you got it in step 2, in the example it issdb.
-
If the partitions are not visible in the system, update the partition information:
partprobe /dev/<new_disk>Specify
<new_disk>is the name of the new disk to which the partitioning was copied, you got it in step 2, in the example it issdb. -
Make sure that the partitioning on the disks matches completely:
lsblkThe response will show information about the partitions on the disks.For example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 985M 1 loop
sda 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