How to Setup Software RAID 0 on Linux Server

RAID 0 allows you to combine multiple disks into one large disk. Only use RAID 0 if the data is not important to you, for example, a backup server. If one disk fails in a RAID 0 array, all the data will be lost.

To create a software RAID 0 with 2 or more disks, first, we need to prepare the disks to be used as RAID members. Run the following commands on each of the disks we will be adding to the RAID 0 array.

parted /dev/sdX mklabel gpt
parted /dev/sdX mkpart primary ext4 0% 100%
parted /dev/sdX set 1 raid on

Replace /dev/sdX with actual device names and run the commands for all devices you will be adding to the RAID 0.

Create RAID 0

To create RAID 0, run the following command

mdadm --create --verbose /dev/md0 --raid-devices=2 --level=0 /dev/sdc1 /dev/sdd1

In the above command,

–raid-devices=2 = number of disks in the RAID. In this case, we have 2 disks. If you have more than 2 disks, change the number accordingly.

/dev/sdc1 /dev/sdd1 = device names, change it with your actual device names. If you have more devices, add them.

/dev/md0 = raid device name, it can be md0, md1, md2 etc..

Format RAID device

Before you can use RAID device, you need to format it.

mkfs.ext4 /dev/mdX

Replace /dev/mdX with your actual device name.

Updating mdadm.conf

Run

mdadm --detail --scan

It will print RAID definitions like the following example

root@grml ~ # mdadm --detail --scan
ARRAY /dev/md0 metadata=1.2 name=grml:0 UUID=44f0ec6b:f8311a0c:382295f8:d41fa0fe
root@grml ~ #  

You need to edit the file

vi /etc/mdadm/mdadm.conf 

Add the ARRAY definitions at end of the file. If any definitions are already there, don’t repeat them.

Mounting New RAID Device

Before you can mount RAID device, you need to find UUID for the raid device, this can be done with command

blkid

Example

root@grml ~ # blkid
/dev/loop0: TYPE="squashfs"
/dev/sda2: UUID="feacd62e-d23f-483d-8971-aa3f110fea05" TYPE="swap" PARTUUID="3019f70f-516a-493f-97cf-2aa001e1c574"
/dev/sda3: UUID="f162656d-bde9-4b14-8823-21e2a1618a2d" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="1fd4e63f-33a4-4c52-bc00-915c9d7965b8"
/dev/sda4: UUID="52ceb7c4-f065-4cc7-9c19-276a98be29a8" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="b8f92699-2892-482c-8abe-b90ca91b5fc0"
/dev/sdb1: UUID="44f0ec6b-f831-1a0c-3822-95f8d41fa0fe" UUID_SUB="65fd2c84-1217-2df7-2a2c-83046458805a" LABEL="grml:0" TYPE="linux_raid_member" PARTLABEL="primary" PARTUUID="b197077b-4a34-4459-8230-5c2a3b1c7085"
/dev/sdc1: UUID="44f0ec6b-f831-1a0c-3822-95f8d41fa0fe" UUID_SUB="fedb9e98-dd9f-daed-fc63-4f6a86ebfc9e" LABEL="grml:0" TYPE="linux_raid_member" PARTLABEL="primary" PARTUUID="807fda4f-d22b-4fa7-8810-839e68ae917e"
/dev/sdd1: UUID="44f0ec6b-f831-1a0c-3822-95f8d41fa0fe" UUID_SUB="071de57a-6d12-70e8-ed6d-cefe8371e915" LABEL="grml:0" TYPE="linux_raid_member" PARTLABEL="primary" PARTUUID="76f0cbbe-858a-4153-87dd-5665d1ac9939"
/dev/sda1: PARTUUID="9034a389-a6b2-424e-bd19-ce7e55561eba"
/dev/md0: UUID="9bd3d3ee-cc6b-43d5-91ed-627440cc9154" BLOCK_SIZE="4096" TYPE="ext4"
root@grml ~ # 

In this cause UUID for /dev/md0 is

UUID="9bd3d3ee-cc6b-43d5-91ed-627440cc9154"

Edit /etc/fstab

vi /etc/fstab

Add

UUID="9bd3d3ee-cc6b-43d5-91ed-627440cc9154"   /home  ext4    defaults  0       1

In the above

/home = is the mount point. If you need to mount the new RAID device as another folder, you need to create an empty directory first.

UUID=”9bd3d3ee-cc6b-43d5-91ed-627440cc9154″ = replace with your actual UUID.

Check status of raid

To see the status of the RAID, use the command

cat /proc/mdstat

Find RAID details

To find RAID details, use the following command

mdadm --detail /dev/mdX
Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *