How to configure and rebuild software RAID
Learn how to configure your server’s RAID array if it needs to be rebuilt due to corruption or disk failure.
Redundant Array of Independent Disks (RAID) is a technology that mitigates data loss on a server by replicating data across two or more disks.
The default RAID level for OVHcloud server installations is RAID 1, which doubles the space taken up by your data, effectively halving the usable disk space.
Requirements
- A dedicated server with a software RAID configuration
- Administrative (sudo) access to the server via SSH
Instructions
Removing the disk
In a command line session, type the following code to determine the current RAID status:
This command shows us that we have two RAID arrays currently set up, with md4 being the largest partition. The partition consists of two disks known as sda4 and sdb4. The [UU] means that all the disks are working normally. A _ would indicate a failed disk.
Although this command returns our RAID volumes, it doesn't tell us the size of the partitions themselves. We can find this information with the following command:
The fdisk -l command also allows you to identify your partition type. This is important information when it comes to rebuilding your RAID in case of a disk failure.
For GPT partitions, the command will return: Disklabel type: gpt.
For MBR partitions, the command will return: Disklabel type: dos.
We can see that /dev/md2 consists of 888.8GB and /dev/md4 contains 973.5GB. If we were to run the mount command we can also find out the layout of the disk.
Alternatively, the lsblk command offers a different view of the partitions:
As the disks are currently mounted by default, to remove a disk from the RAID, we first need to unmount the disk, then simulate a failure, and finally remove it. We will remove /dev/sda4 from the RAID with the following command:
NOTE: Please note that if you are connected as the user root, you may get the following message when you try to unmount the partition (in our case, where our md4 partition is mounted in /home):
In this case, you must log out as the user root and connect as a local user (in our case debian), and use the following command:
If you do not have a local user, you need to create one.
This will provide us with the following output:
As we can see, the entry of /dev/md4 is no longer mounted. However, the RAID is still active, so we need to simulate a failure to remove the disk. We can do this with the following command:
We have now simulated a failure of the RAID. The next step is to remove the partition from the RAID array with the following command:
You can verify that the partition has been removed with the following command:
The following command will verify that the partition has been removed:
Rebuilding the RAID
Once the disk has been replaced, we need to copy the partition table from a healthy disk (in this example, sdb) to the new one (sda) with the following commands.
For GPT partitions
The command should be in this format: sgdisk -R /dev/newdisk /dev/healthydisk
Once this is done, the next step is to randomize the GUID of the new disk to prevent GUID conflicts with other disks:
For MBR partitions
Once the disk has been replaced, we need to copy the partition table from a healthy disk (in this example, sdb) to the new one (sda) with the following command:
The command should be in this format: sfdisk -d /dev/healthydisk | sfdisk /dev/newdisk
We can now rebuild the RAID array. The following code snippet shows how we can rebulid the /dev/md4 partition layout with the recently-copied sda partition table:
We can verify the RAID details with the following command:
The RAID has now been rebuilt, but we still need to mount the partition (/dev/md4 in this example) with the following command:
Go further
Browse all the Dedicated Servers guides.
Browse the rest of the OVHcloud US documentation for guides on our other products and services.
Learn more about Dedicated Servers on the OVHcloud US website.