---
title: "Replace a disk in a RAID"
sidebar_label: "Replace a disk in a RAID"
sidebar_position: 6
description: "How to replace a disk in a RAID"
---

import Formbricks from '@theme/MDXComponents/Formbricks'
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import {TabItemLabel} from 'docs-kit/components'

# Replace a disk in a RAID

1. [Remove the disk from the array](#remove-disk-from-array).
2. [Determine the disk partition scheme](#determine-the-partition).
3. [Copy the partition table to the new disk](#copy-partition-table-to-new-disk).
4. [Add the disk to the RAID array](#add-disk-to-array).
5. [Install the bootloader](#install-bootloader).

## 1. Remove the disk from the array \{#remove-disk-from-array}

1. [Connect to the server via SSH](/dedicated/manage/connect-to-server.mdx#connect-via-ssh) or via [KVM console](/dedicated/manage/connect-to-server.mdx#connect-via-kvm-console).

2. Output current RAID array configuration:

   ```bash
   cat /proc/mdstat
   ```

   The output will contain information about the RAID array configuration. Example:

   ```bash
   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:

   ```bash
   lsblk
   ```

   The response will contain a list of volumes with partitions.For example:

   ```bash
   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:

   ```bash
   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:

   ```bash
   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 \{#determine-the-partition}

1. [Connect to the server via SSH](/dedicated/manage/connect-to-server.mdx#connect-via-ssh) or via [KVM console](/dedicated/manage/connect-to-server.mdx#connect-via-kvm-console).

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

   ```bash
   apt-get install gdisk -y
   ```

3. Output information about partitions on the disks:

   ```bash
   lsblk
   ```

   The response will contain information about partitions on the volumes.For example:

   ```bash
   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:

   ```bash
   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:

     ```bash
     Partition table scan:
     MBR: protective
     BSD: not present
     APM: not present
     GPT: present
     ```

   * MBR:

     ```bash
     Partition table scan:
     MBR: MBR only
     BSD: not present
     APM: not present
     GPT: not present
     ```

## 3. Copy the partition table to the new disk \{#copy-partition-table-to-new-disk}

The partition table copying process depends on the [disk partition scheme](#determine-the-partition) — GPT or MBR.

:::danger

When copying the layout, it is important to specify the volumes in the correct order in the command.If the order of the volumes is incorrect, the operational volume will be overwritten and the data deleted.The data cannot be recovered.

:::

<Tabs queryString="transfer-partition-table-to-new-disk">
  <TabItem value="copy-partition-for-gpt" default>
    <TabItemLabel>
      GPT
    </TabItemLabel>

    1. [Connect to the server via SSH](/dedicated/manage/connect-to-server.mdx#connect-via-ssh) or via [KVM console](/dedicated/manage/connect-to-server.mdx#connect-via-kvm-console).

    2. Output information about partitions on the disks:

       ```bash
       lsblk
       ```

       The response will contain information about partitions on the volumes.For example:

       ```bash
       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 layout to the new volume.It is important to specify the volumes in the correct order in the command, otherwise the layout and data on the initially operational volume will be destroyed.

       ```bash
       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:

       ```bash
       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:

       ```bash
       lsblk
       ```

       The response will contain information about partitions on the volumes.For example:

       ```bash
       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
       ```
  </TabItem>

  <TabItem value="copy-partition-for-mbr">
    <TabItemLabel>
      MBR
    </TabItemLabel>

    1. [Connect to the server via SSH](/dedicated/manage/connect-to-server.mdx#connect-via-ssh) or via [KVM console](/dedicated/manage/connect-to-server.mdx#connect-via-kvm-console).

    2. Output information about partitions on the disks:

       ```bash
       lsblk
       ```

       The response will contain information about partitions on the volumes.For example:

       ```bash
       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 layout to the new volume.It is important to specify the volumes in the correct order in the command, otherwise the layout and data on the initially operational volume will be destroyed.

       ```bash
       sfdisk -d /dev/<source_disk> | sfdisk /dev/<new_disk>
       ```

       Specify:

       * `<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`;
       * `<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`.

    4. If partitions are not visible in the system, refresh partition information:

       ```bash
       partprobe /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:

       ```bash
       lsblk
       ```

       The response will contain information about partitions on the volumes.For example:

       ```bash
       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
       ```
  </TabItem>
</Tabs>

## 4. Add the disk to the RAID array \{#add-disk-to-array}

1. [Connect to the server via SSH](/dedicated/manage/connect-to-server.mdx#connect-via-ssh) or via [KVM console](/dedicated/manage/connect-to-server.mdx#connect-via-kvm-console).

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

   ```bash
   lsblk
   ```

   The response will contain information about partitions on the volumes and RAID array configurations.For example:

   ```bash
   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:

   ```bash
   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`.

   Once the volume has been added to the RAID array, synchronization will begin.The synchronization speed depends on the size and type of the volume — SSD or HDD.

4. Wait for synchronization to complete.

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

   ```bash
   lsblk
   ```

   The response will contain information about partitions on the volumes and RAID array configurations.For example:

   ```bash
   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 \{#install-bootloader}

After [adding the disk to the array](#add-disk-to-array), you need to install the OS bootloader on it.

You can install the bootloader both in the OS and in Rescue mode.

<Tabs queryString="install-bootloader">
  <TabItem value="install-bootloader-boot" default>
    <TabItemLabel>
      Server booted into the OS
    </TabItemLabel>

    1. [Connect to the server via SSH](/dedicated/manage/connect-to-server.mdx#connect-via-ssh) or via [KVM console](/dedicated/manage/connect-to-server.mdx#connect-via-kvm-console).

    2. Output information about partitions on the disks:

       ```bash
       lsblk -o +FSTYPE
       ```

       The response will contain information about partitions on the volumes.For example:

       ```bash
       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:

       ```bash
       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`.
  </TabItem>

  <TabItem value="install-bootloader-rescue">
    <TabItemLabel>
      Server booted in Rescue mode
    </TabItemLabel>

    1. [Boot the server into Rescue emergency and recovery mode](/dedicated/troubleshooting/boot-to-recovery.mdx).

    2. [Connect to the server via SSH](/dedicated/manage/connect-to-server.mdx#connect-via-ssh) or via [KVM console](/dedicated/manage/connect-to-server.mdx#connect-via-kvm-console).

    3. Output information about the OS boot mode:

       ```bash
       [ -d /sys/firmware/efi ] && echo "UEFI" || echo "BIOS"
       ```

       The output will contain information about the OS boot mode — `BIOS` or `UEFI`.

    4. Check if the system has detected RAID arrays by outputting information about partitions on the disks:

       ```bash
       lsblk -o +FSTYPE
       ```

       The response will contain information about partitions on the volumes and RAID array configurations.For example:

       ```bash
       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 
       ```

       Here `md0`, `md1` are the names of the RAID arrays on the disk partitions.

    5. If step 4 in the `lsblk` output contains RAID arrays, skip this step.If there are no RAID arrays, start assembling the RAID arrays:

       ```bash
       mdadm --assemble --scan
       ```

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

       ```bash
       lsblk -o +FSTYPE
       ```

       The response will contain information about partitions on the volumes and RAID array configurations.For example:

       ```bash
       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 partitions;
       * `sdb` — name of the new disk;
       * `md0`, `md1` are the names of the RAID arrays on the disk partitions.

    7. Identify the partitions to be mounted:

       * root partition `/` — usually located on the largest partition of the disk; in the example in step 6, it is `md1`;
       * boot partition `/boot` — usually has the ext4 file system and a size of 512 MB to 1 GB; in the example in step 6, it is `md0`;
       * EFI partition `/boot/efi` — a partition with the vfat file system, used when booting the OS in UEFI mode; in the example in step 6, these are partitions `sda1` and `sdb1`.

    8. Mount the root file system to the `/mnt` directory:

       ```bash
       mount /dev/<raid_array> /mnt
       ```

       Here, `<system_raid_array>` is the name of the root partition that you identified in step 7; in this example, it is `md1`.

    9. Mount the boot partition:

       ```bash
       mount /dev/<boot_partition> /mnt/boot
       ```

       Specify `<boot_raid_array>` — name of the boot partition `/boot` that you identified in step 7; in this example, it is `md0`.

    10. If the OS uses a UEFI bootloader, mount the EFI partition:

        ```bash
        mount /dev/<efi_partition> /mnt/boot/efi
        ```

        Specify `<efi_partition>` — name of the EFI partition `/boot/efi` on the new disk that you identified in step 7; in this example, it is `sdb1`.

    11. Mount the service file systems:

        ```bash
        mount --bind /sys /mnt/sys
        mount --bind /proc /mnt/proc
        mount --bind /dev /mnt/dev
        mount -t devpts devpts /mnt/dev/pts
        ```

    12. If you identified the OS boot mode as UEFI in step 3, mount the `efivars` file system:

    ```bash
    mount -t efivarfs efivarfs /mnt/sys/firmware/efi/efivars
    ```

    13. Connect to the environment:

        ```bash
        chroot /mnt /bin/bash
        ```

    14. Export the PATH variable:

        ```bash
        export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
        ```

    15. Install the GRUB bootloader.The command for installation depends on the OS boot mode you determined in step 3:

        * UEFI:

        ```bash
        grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB
        ```

        * BIOS:

        ```bash
        grub-install /dev/<new_disk>
        ```

        Specify `<new_disk>` — name of the new disk that you obtained in step 6; in this example, it is `sdb`.

    16. Create the GRUB configuration file:

        ```bash
        /sbin/grub-mkconfig -o /boot/grub/grub.cfg
        ```

    17. After the GRUB installation is finished, exit the environment:

        ```bash
        exit
        ```

    18. Unmount the service file systems:

        ```bash
        mount -t devpts devpts /mnt/dev/pts
        mount --bind /dev /mnt/dev
        mount --bind /proc /mnt/proc
        mount --bind /sys /mnt/sys
        ```

    19. Unmount the file system:

        ```bash
        umount /dev/<system_raid_array> /mnt
        ```

        Specify `<system_raid_array>` — name of the root partition `/` that you mounted in step 8; in this example, it is `md1`.

    20. [Return the previous server boot template](/dedicated/troubleshooting/boot-to-recovery.mdx#restore-server-boot-template) or reboot the server from the OS.When the server is rebooted from the OS, the boot template will automatically change back to the one that was set before booting the server in Rescue mode.
  </TabItem>
</Tabs>

<Formbricks />
