Skip to main content

Replace a disk in a RAID

Last update:
  1. Remove the disk from the array.
  2. Determine the disk partition scheme.
  3. Copy the partition table to the new disk.
  4. Add the disk to the RAID array.
  5. Install the bootloader.

1. Remove the disk from the array

  1. Connect to the server via SSH or via KVM console.

  2. Output current RAID array configuration:

    cat /proc/mdstat

    The 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 chunk

    md0 : 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 the sda2 and sdb2;
    • md1 — name of the RAID array assembled from the sda3 and sdb3.
  3. Output information about partitions on the disks and RAID array configuration:

    lsblk

    The output will contain a list of disks with partitions. 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 /

    Where:

    • sda — name of the disk with functioning RAID arrays;
    • sdb — name of the disk to be replaced;
    • sdb2 — name of the partition on disk sdb that is a component of the first RAID array;
    • md0 — name of the first RAID array assembled from the sda2 and sdb2;
    • sdb3 — name of the partition on disk sdb that is a component of the second RAID array;
    • md1 — name of the second RAID array assembled from the sda3 and sdb3.
  4. 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 is md0;
    • <partition_1> — name of the first RAID array partition on the replacement disk that you obtained in step 3; in this example, it is sdb2;
    • <raid_array_2> — name of the second RAID array that you obtained in step 3; in this example, it is md1;
    • <partition_2> — name of the second RAID array partition on the replacement disk that you obtained in step 3; in this example, it is sdb3.
  5. 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 is md0;
    • <partition_1> — name of the first RAID array partition on the replacement disk that you obtained in step 3; in this example, it is sdb2;
    • <raid_array_2> — name of the second RAID array that you obtained in step 3; in this example, it is md1;
    • <partition_2> — name of the second RAID array partition on the replacement disk that you obtained in step 3; in this example, it is sdb3.

2. Determine the disk partition scheme

  1. Connect to the server via SSH or via KVM console.

  2. Install the utility for working with the GPT (GUID Partition Table) on disks — gdisk:

    apt-get install gdisk -y
  3. Output information about partitions on the disks:

    lsblk

    The output will contain information about partitions on the disks. 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

    Where:

    • sda — name of the disk with functioning RAID partitions;
    • sdb — name of the new disk.
  4. 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 is sda.

    The answer depends on the disk partition 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 partition table to the new disk

The partition table copying process depends on the disk partition scheme — GPT or MBR.

carefully

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.

  1. Connect to the server via SSH or via KVM console.

  2. Output information about partitions on the disks:

    lsblk

    The output will contain information about partitions on the disks. 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

    Where:

    • sda — name of the disk with functioning RAID partitions;
    • sdb — name of the new disk.
  3. 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 is sdb;
    • <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 is sda.
  4. 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 is sdb.

  5. Ensure the partition schemes on the disks are identical:

    lsblk

    The output will contain information about partitions on the disks. 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

4. Add the disk to the RAID array

  1. Connect to the server via SSH or via KVM console.

  2. Output information about partitions on the disks and RAID array configuration:

    lsblk

    The output will contain information about partitions on the disks and RAID array configuration. 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

    Where:

    • md0 — name of the first RAID array which is assembled from the sda2;
    • md1 — name of the second RAID array which is assembled from the sda3;
    • 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.
  3. 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 is md0;
    • <partition_1> — name of the first partition on the new disk that you obtained in step 2; in this example, it is sdb2;
    • <raid_array_2> — name of the second RAID array that you obtained in step 2; in this example, it is md1;
    • <partition_2> — name of the second partition on the new disk that you obtained in step 2; in this example, it is sdb3.

    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.

  4. Wait for synchronization to complete.

  5. Ensure that the new disk has been added to the RAID array:

    lsblk

    The output will contain information about partitions on the disks and RAID array configuration. 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 /

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.

  1. Connect to the server via SSH or via KVM console.

  2. Output information about partitions on the disks:

    lsblk -o +FSTYPE

    The output will contain information about partitions on the disks. Example:

    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT FSTYPE
    loop0 7:0 0 985M 1 loop
    sda 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 / ext4

    Where:

    • sda — name of the disk with functioning RAID arrays;
    • sdb — name of the new disk.
  3. 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 is sdb.