MDADM RAID 0 (Striping)
Install Dependencies
Install mdadm if it is not already installed
sudo apt update && sudo apt install mdadm
Identify Disks
Make absolutely sure you are selecting the right disk as proceeding with the incorrect disk will result in data loss
List the block devices available on your systems
lsblk
From the output I have identified sda
and sdb
as the disks I want to use for my RAID 0 setup.
Prep Disks
Be certain to perform these actions only on the disks you plan to use for the array
Existing partitions should be removed. This can be done with fdisk
sudo fdisk /dev/<DEVICE>
Press d
to delete the partition, then ENTER
to select the first applicable parition. Repeat until all partitions are removed. Type w
to write the changes and exit.
Create the Array
Execute the mdadm command to create the array
sudo mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sda /dev/sdb
This command tells mdadm to create the array the /dev/md0 location using RAID level 0, with 2 RAID devices which consist of /dev/sda
and /dev/sdb
.
You will want to make sure that you update the number of raid-devices
and the actual device locations to represent your system's configuration.
Format the Array
I will be using ext4 as the file system for my array
sudo mkfs.ext4 -m 0 /dev/md0
This simple command formats the /dev/md0
array we created in the previous command. The -m 0
will set the reserve space to 0 which is fine for a non-root partition.
Mount the Drive
Create a mount point for the drive. I will mount to /media/raid0
but you can mount where it makes the most sense for you.
mkdir /media/raid0
Then mount the drive
sudo mount /dev/md0 /media/raid0
Check the Status
To see the status of your RAID array, run
cat /proc/mdstat
Automatically Mount on Boot
If you want the drive to automatically be mounted when you boot, you need to create an FSTAB entry. First, identify the UUID of your raid array
sudo blkid /dev/md0
Copy the UUID listed. Then open up your FSTAB file
sudo nano /etc/fstab
Then add the following entry at the bottom of your FSTAB file
UUID=<UUID> /media/raid0 ext4 defaults,nofail 0 0
This mounts the drive with the specified UUID to the /media/raid0
mount point with the ext4
file system using the default
mount options + nofail
which allows the system to still
boot if the device is not available. 0 0
means do not dump the file system and do not perform a file system check, which is fine for a non-root filesystem.
To save and exit, press CTRL + x
then y
.
Speed Test (Optional)
If you want to test out the performance of you new RAID array, you can perform some benchmarks with fio
. Check out the wiki for testing drive performance for instructions on how to do it.