Skip to main content

Replace a disk in a RAID

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

    lsblk

    The response will contain 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 /

    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 disk sdb, which is a component of the first RAID array;
    • md0 — the name of the first RAID array assembled from partitions sda2 and sdb2;
    • sdb3 — the name of the partition on disk sdb, which is a component of the second RAID array;
    • md1 — the name of the second RAID array assembled from partitions 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> — the name of the first RAID array that you obtained in step 3, in the example it is md0;
    • <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 is sdb2;
    • <raid_array_2> — the name of the second RAID array that you obtained in step 3, in the example it is md1;
    • <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 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> — the name of the first RAID array that you obtained in step 3, in the example it is md0;
    • <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 is sdb2;
    • <raid_array_2> — the name of the second RAID array that you obtained in step 3, in the example it is md1;
    • <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 is sdb3.

2. Determine the disk partition scheme

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

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

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

    lsblk

    The response will contain information about 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

    Where:

    • sda — the name of the disk with working RAID partitions;
    • sdb — the name of the new disk.
  4. 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 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 process of copying the partition table depends on the disk partitioning scheme — GPT or MBR.

carefully

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.

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

  2. Output information about partitions on the disks:

    lsblk

    The response will contain information about 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

    Where:

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

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

    lsblk

    The response will contain information about 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

4. Add the disk to the RAID array

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

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

    lsblk

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

    Where:

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

    After adding the disk to the RAID array, synchronization will start. The synchronization speed depends on the disk size and type — SSD or HDD.

  4. Wait for synchronization to complete.

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

    lsblk

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

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.

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

  2. Output information about partitions on the disks:

    lsblk -o +FSTYPE

    The response will contain information about partitions on the disks. For 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 — the name of the disk with working RAID arrays;
    • sdb — the name of the new disk.
  3. 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 is sdb.