Support Centre

Linux RAID setup using mdadm

For this tutorial, we will be using Ubuntu 16.04 Server. I have setup a virtual machine with 5 hard drives. One is used for the main operating system while the rest are to be used in a software RAID array. 

Once you've logged in to Ubuntu, enter the following command:

lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT

This command will display all available disks and partitions in the system with columns for name, size, file system type, whether it is a disk or a partition, and the mount point.

Screen_Shot_2018-04-13_at_2.01.30_PM.jpg

This is the output from my machine. As you can see, I have the first drive allocated for the operating system. Each drive is 20 GB. We will use the rest for the array (sdb, sdc, sdd, sde)

 

Creating the Array

RAID 0

We will use the mdadm command in Linux for managing our RAID configuration. In this case, we'll want to create a RAID array. Enter the following command to create a RAID 0 array:

sudo mdadm --create --verbose /dev/md0 --level=0 --raid-devices=4 /dev/sdb /dev/sdc /dev/sdd /dev/sde

To check if it was created successfully, enter the following command: 

cat /proc/mdstat

Screen_Shot_2018-04-13_at_2.19.10_PM.jpg

We have successfully created the RAID device md0 as seen on the screenshot.

Creating and Mounting the Filesystem

Now we will need to create a filesystem on the array:

sudo mkfs.ext4 -F /dev/md0

We now then create a mount point for the filesystem:

sudo mkdir -p /mnt/md0

Then we mount the filesystem:

sudo mount /dev/md0 /mnt/md0

We can confirm that it is now available by entering the following command:

df -h -x devtmpfs -x tmpfs

Screen_Shot_2018-04-13_at_2.31.44_PM.jpg

We can confirm that is now mounted and accessible.

We need to save the array layout so it is mounted and assembled on boot. Now we have to modify the /etc/mdadm/mdadm.conf file. 

We can check the active array and append the file at the same time by entering the following command:

sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf

Now we need to update the initial RAM file system so the array is available during the early boot process.

sudo update-initramfs -u

We need to mount the new filesystem automatically at boot by adding it to the /etc/fstab file.

echo '/dev/md0 /mnt/md0 ext4 defaults,nofail,discard 0 0' | sudo tee -a /etc/fstab

 

The process is the same for RAID 1, RAID 5, and RAID 6 but before saving the array you need to make sure that the array building has completed.

 

RAID 10

The process for configuring RAID 10 is the same as the others except that you can specify a layout. 

There are 3 layouts we can use:

  • near: The default arrangement. Copies of the data blocks will be written around the same part of multiple disks.
  • far: The first and subsequent copies are written to different parts the storage devices in the array. This can give some read performance gains for traditional spinning disks at the expense of write performance.
  • offset: Each stripe is copied, offset by one drive. This means that the copies are offset from one another, but still close together on the disk. This helps minimize excessive seeking during some workloads.

In my current configuration (4 hard drives for RAID), the following command creates two copies using the near layout: 

sudo mdadm --create --verbose /dev/md0 --level=10 --raid-devices=4 /dev/sdb /dev/sdc /dev/sdd /dev/sde

By default, if you do not specify a layout by using the --layout parameter, it will use the near layout. The structure of this parameter are as follows:

--layoutxy

x is the layout to be used. n for near, o for offset, and f for far. y is the number of copies to be stored.

Once you have created the array and the filesystem for the array, you can save it using the same steps before. But you need to wait for the array building to complete first.

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.