Valid for: Dedicated Servers with Linux and software RAID

This article explains how to rebuild a software RAID after a defective hard drive has been replaced.

Please Note

These instructions are only valid for Dedicated Servers that use BIOS as the interface between the hardware and the operating system. If you use a Dedicated Server that uses UEFI as the interface between the hardware and the operating system, see the following article for information on rebuilding the software RAID: Rebuilding software RAID (Linux Dedicated Servers and Bare Metal Servers with UEFI)

Checking whether a Dedicated Server uses UEFI or BIOS

To check whether your server uses BIOS or UEFI as the interface between the hardware and the operating system, enter the following command:

[root@localhost ~]# [ -d /sys/firmware/efi ] && echo UEFI || echo BIOS

Important information about partitioning your Dedicated Server

On Dedicated Servers managed in the Cloud Panel, only one partition has been created during setup and when the operating system is reinstalled since October 20, 2021. On Dedicated Servers set up before this date and on Dedicated Servers purchased as part of a Server Deal, the operating system images are equipped with the Logical Volume Manager (LVM). The Logical Volume Manager places a logical layer between the file system and the partitions of the disks used. This makes it possible to create a file system that spans several partitions and/or disks. In this way, for example, the storage space of several partitions or disks can be combined.

Determining the information needed to rebuild the software RAID

Before you begin, you need to understand the structure of the existing system.

Listing existing disks and partitions

  • Log in to the server with your root account.

  • To list the existing disks and partitions, enter the fdisk -l command. fdisk is a command-line program for partitioning disks. You can use it to display, create, or delete partitions.

    [root@localhost ~]# fdisk -l

  • Make a note of the drive names (for example, /dev/sda and /dev/sdb).

Note

After a hot-swap replacement, the new hard drive is often detected as sdc. A reboot is required so that it is addressed correctly as sda or sdb again.

Determining mount points
  • To display the mount points of the devices and partitions you use, enter the following command:

    [root@localhost ~]# lsblk

    The following information, for example, is then displayed:

    root@s20776641:~# lsblk
    NAME            MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
    loop1             7:1    0  54.9M  1 loop  /snap/lxd/12631
    loop2             7:2    0 110.6M  1 loop  /snap/core/12834
    loop3             7:3    0  61.9M  1 loop  /snap/core20/1434
    loop4             7:4    0  80.4M  1 loop  /snap/lxd/23037
    sda               8:0    0 931.5G  0 disk
    ├─sda1            8:1    0     4G  0 part
    │ └─md1           9:1    0     4G  0 raid1 /
    ├─sda2            8:2    0     2G  0 part  [SWAP]
    └─sda3            8:3    0 925.5G  0 part
      └─md3           9:3    0 925.5G  0 raid1
        ├─vg00-usr  253:0    0     5G  0 lvm   /usr
        ├─vg00-var  253:1    0     5G  0 lvm   /var
        └─vg00-home 253:2    0     5G  0 lvm   /home
    sdb               8:16   0 931.5G  0 disk
    ├─sdb1            8:17   0     4G  0 part
    │ └─md1           9:1    0     4G  0 raid1 /
    ├─sdb2            8:18   0     2G  0 part  [SWAP]
    └─sdb3            8:19   0 925.5G  0 part
      └─md3           9:3    0 925.5G  0 raid1
        ├─vg00-usr  253:0    0     5G  0 lvm   /usr
        ├─vg00-var  253:1    0     5G  0 lvm   /var
        └─vg00-home 253:2    0     5G  0 lvm   /home

  • Make a note of the devices and partitions and their mount points. Example:

    • md1 is mounted on / (root).
    • vg00-var is mounted on /var.
    • vg00-usr is mounted on /usr.
    • vg00-home is mounted on /home.
    • sda2 and sdb2 are swap partitions (not part of a RAID).

Determining the RAID status

Check which drive is missing from the RAID. To do this, enter the following command:

[root@localhost ~]# cat /proc/mdstat

If an array is marked [_U] instead of [UU], a drive is missing from this RAID array.

Displaying the contents of the fstab file and determining the device files

  • On some server configurations, system directories such as /usr, /var, or /home are stored on separate partitions. These must also be mounted so that commands work in the system. To check this, view the fstab file. To display the contents of the fstab file and determine the associated device files, enter the following command:

    [root@localhost ~]# cat /etc/fstab

  • Analyse the output:

    Case A (flat file system, for example, Debian 13): If /usr, /var, and /home are not listed as separate entries, you do not need to mount any further partitions. In this case, skip the steps in the Restoring the RAID section that apply only to Dedicated Servers with a partitioned system with LVM.

    Case B (partitioned system/LVM): If /usr, /var, and /home are listed as separate entries, you must mount them when you restore the RAID. This is described in the Restoring the RAID section.

Restoring the RAID

The rest of the procedure depends on which disk was replaced.

Caution

The Disk 1 (sda) was replaced section assumes that disk 1, named sda, was replaced. The Disk 2 (sdb) was replaced section assumes that disk 2, named sdb, was replaced. Always adapt the commands in these instructions before you enter them, and replace the drive names with the information you determined.

Disk 1 (sda) was replaced

If disk 1 (sda) was replaced, check whether it was detected correctly. You may need to perform a reboot. Then boot the server into the Rescue System and complete the steps below.

Note

The following articles describe how to boot your Dedicated Server into the Rescue System:

Dedicated Servers managed in the Cloud Panel:

Booting Dedicated Servers and Bare Metal Servers into the Linux rescue system

Dedicated Servers managed in the server administration:

Booting a Linux Server into the Rescue System

  • Copy the partition tables of disk 2 (sdb) to the new (empty) disk (sda):

    rescue:~# sfdisk -d /dev/sdb | sfdisk /dev/sda

    If necessary, use the --force option.

  • Add the partitions to the corresponding RAID array:

    rescue:~# mdadm /dev/md1 -a /dev/sda1

    rescue:~# mdadm /dev/md3 -a /dev/sda3

  • To monitor the rebuild, enter the following command:

    rescue:~# cat /proc/mdstat

  • Mount the root partition:

    rescue:~# mount /dev/md1 /mnt

  • Applies only to Dedicated Servers with a partitioned system with LVM: Create the following mount points:

    rescue:~# mkdir /mnt/var
    rescue:~# mkdir /mnt/usr
    rescue:~# mkdir /mnt/home

  • Applies only to Dedicated Servers with a partitioned system with LVM: Mount the var, usr, and home partitions:

    rescue:~# mount /dev/mapper/vg00-var /mnt/var
    rescue:~# mount /dev/mapper/vg00-usr /mnt/usr
    rescue:~# mount /dev/mapper/vg00-home /mnt/home

  • Applies only to Dedicated Servers with a partitioned system with LVM: Create the following mount points:

    rescue:~# mkdir /mnt/proc
    rescue:~# mkdir /mnt/sys
    rescue:~# mkdir /mnt/dev

  • To ensure that GRUB can be installed without errors later, mount proc, sys, and dev:

    rescue:~# mount -o bind /proc /mnt/proc
    rescue:~# mount -o bind /sys /mnt/sys
    rescue:~# mount -o bind /dev /mnt/dev

  • Required for Debian 13, Ubuntu 24.04, Ubuntu 26.04, AlmaLinux 9, AlmaLinux 10, Rocky Linux 9, and Rocky Linux 10: To use the GRUB tools, mount /run:

    rescue:~# mount -o bind /run /mnt/run

  • After you have mounted the partitions, switch to the chroot environment:

    rescue:~# chroot /mnt

  • Install the GRUB boot loader:

    Debian 11, 12, and 13, and Ubuntu 24.04 and 26.04:

    rescue:/# grub-install /dev/sda

    AlmaLinux, Rocky Linux (9 and 10), and CentOS:

    rescue:/# grub2-install /dev/sda

  • To update the configuration, enter the following command:

    Debian 11, 12, and 13, and Ubuntu 24.04 and 26.04:

    rescue:/# update-grub

    AlmaLinux 9 and 10, and Rocky Linux 9 and 10:

    rescue:/# grub2-mkconfig -o /boot/grub2/grub.cfg

  • Exit the chroot environment with exit:

    rescue:/# exit

  • Unmount all partitions:

    rescue:~# umount -R /mnt

    Wait until the rebuild is complete, and then boot the server back into the normal system.

  • After the restart, log in again.

  • Make sure that the swap partition is not part of a RAID. To do this, enter the following command:

    [root@host ~]# cat /proc/mdstat

  • To set up the partition as a Linux swap area, adapt the following command and then enter it. In this example, the Linux swap area is /dev/sda2.

    [root@host ~]# mkswap /dev/sda2

Caution

The mkswap command changes the UUID of the partition. If the swap partition is referenced by UUID in your /etc/fstab file (the default on AlmaLinux, Rocky Linux, and Debian), you must edit /etc/fstab after the restart and enter the new UUID. Otherwise, the swap partition is not activated automatically.

  • To determine the UUID, adapt the following command and then enter it:

    [root@host ~]# lsblk -f | grep sda2

  • Applies only if the swap partition is referenced by UUID: To edit /etc/fstab, enter the following command:

    [root@host ~]# vi /etc/fstab

Note

The vi editor has an insert mode and a command mode. To switch to insert mode, press the i key. In this mode, the characters you type are inserted into the text immediately. To switch to command mode, press Esc. In command mode, your keyboard input is interpreted as commands.

  • Navigate to the line containing swap and replace the old UUID with the new UUID in /etc/fstab.

  • To exit vi and save the file, enter :wq and then press Enter.

  • Activate the swap partition. To do this, enter the following command:

    [root@host ~]# swapon -a

  • To check whether the swap space is active, enter the following command:

    [root@host ~]# cat /proc/swaps

Disk 2 (sdb) was replaced

If disk 2 (sdb) was replaced, complete the following steps:

  • Perform a reboot so that disk 2 is displayed.

  • On the local system, copy the partition tables of disk 1 (sda) to the new (empty) disk (sdb):

    [root@host ~]# sfdisk -d /dev/sda | sfdisk /dev/sdb

    If necessary, use the --force option.

  • Add the partitions to the RAID:

    [root@host ~]# mdadm /dev/md1 -a /dev/sdb1

    [root@host ~]# mdadm /dev/md3 -a /dev/sdb3

  • To monitor the rebuild, enter the following command:

    [root@host ~]# cat /proc/mdstat

  • Install the GRUB boot loader:

    Debian 11, 12, and 13, and Ubuntu 24.04 and 26.04:

    [root@host ~]# grub-install /dev/sdb

    AlmaLinux, Rocky Linux (9 and 10), and CentOS:

    [root@host ~]# grub2-install /dev/sdb

  • To update the configuration, enter the following command:

    Debian 11, 12, and 13, and Ubuntu 24.04 and 26.04:

    [root@host ~]# update-grub

    AlmaLinux 9 and 10, and Rocky Linux 9 and 10:

    [root@host ~]# grub2-mkconfig -o /boot/grub2/grub.cfg

  • Make sure that the swap partition is not part of a RAID. To do this, enter the following command:

    [root@host ~]# cat /proc/mdstat

  • To set up the partition as a Linux swap area, adapt the following command and then enter it. In this example, the Linux swap area is /dev/sdb2.

    [root@host ~]# mkswap /dev/sdb2

Caution

The mkswap command changes the UUID of the partition. If the swap partition is referenced by UUID in your /etc/fstab file (the default on AlmaLinux, Rocky Linux, and Debian), you must edit /etc/fstab after the restart and enter the new UUID. Otherwise, the swap partition is not activated automatically. If the swap partition of your server is not referenced by UUID, you only need to activate the swap partition. In this case, skip editing the fstab file.

  • To determine the UUID, adapt the following command and then enter it:

    [root@host ~]# lsblk -f | grep sdb2

  • Applies only if the swap partition is referenced by UUID: To edit /etc/fstab, enter the following command:

    [root@host ~]# vi /etc/fstab

Note

The vi editor has an insert mode and a command mode. To switch to insert mode, press the i key. In this mode, the characters you type are inserted into the text immediately. To switch to command mode, press Esc. In command mode, your keyboard input is interpreted as commands.

  • Replace the UUID in /etc/fstab.

  • To exit vi and save the file, enter :wq and then press Enter.

  • Activate the swap partition. To do this, enter the following command:

    [root@host ~]# swapon -a

  • To check whether the swap space is active, enter the following command:

    [root@host ~]# cat /proc/swaps