User Tools

This is an old revision of the document!


Easy to expand Linux software RAID 5 with XFS.

Creating the initial 3 drive array

First, create empty partitions to all drives:

fdisk /dev/sdX
n # Create a new partition
p # Primary
1 # First partition
[enter] # Starting point to first sector (default)
[enter] # Ending point to last sector (default)
t # Change partition type
fd # Type: Linux raid autodetect
w # Write changes to disc

When empty RAID partitions have been created to all three discs, I created a RAID5 array:

mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1

Now the RAID5 array is created, and it is being built already. It takes time, but you can proceed with creating a new physical LVM2 volume:

pvcreate /dev/md0

Now let’s create a new volume group:

vgcreate vd_raid /dev/md0

Then we need to create a new logical volume inside that volume group. First we need to figure out the exact size of the created volume group:

vgdisplay vd_raid

The size can be seen from the row which indicates the “Total PE” in physical extents. Let’s imagine it is 509. Now create a new logical volume which takes all available space:

lvcreate -l 509 vd_raid -n lv_raid

Finally we can create a file system on top of that logical volume:

mkfs.xfs /dev/mapper/vd_raid-lv_raid

To be able to use our newly created RAID array, we need to create a directory and mount it:

mkdir -p /mnt/raid
mount /dev/mapper/vd_raid-lv_raid /mnt/raid

Now it is ready to use. But for it to automatically mount after reboot, we need to save RAID geometry to mdadm’s configuration file:

mdadm --detail --scan >> /etc/mdadm/mdadm.conf

Then add the following line to /etc/fstab which mounts the RAID array automatically:

/dev/mapper/vd_raid-lv_raid /mnt/raid auto auto,noatime,nodiratime,logbufs=8 0 1

Now the RAID array is ready to use, and mounted automatically to /raid directory after every boot.