General Topics

Create RAID Arrays with mdadm on Ubuntu

What is mdadm?

The mdadm utility can be used to create and manage storage arrays using Linux’s software RAID capabilities.
Administrators have great flexibility in coordinating their individual storage devices and creating logical storage devices that have greater performance or redundancy characteristics.

Creating a RAID 0 Array

The RAID 0 array works by breaking up data into chunks and striping it across the available disks. This means that each disk contains a portion of the data and that multiple disks will be referenced when retrieving information. This option Require minimum of 2 storage devices

In the following examples we are simulate 4 storage devices

To get started, find full informations for the raw disks that you will be using for the raid:

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

    
   
Output looks like:
    
     NAME SIZE FSTYPE TYPE MOUNTPOINT
sdc 500G disk
sdd 500G disk
sde 500G disk
sdf 500G disk
vda 20G disk
├─vda1 200G ext4 part /
└─vdb1 100G part

    
   

As above, we have 4 disks without a filesystem, each 500G in size. In this example, these devices have been given the /dev/sdc and /dev/sdd /dev/sde /dev/sdf identifiers for this session. These will be the raw components we will use to build the array.

Create the Array

To create a RAID 0 array ,we need to pass them in to the mdadm –create command. You will have to specify the device name you wish to create (/dev/md0 in our exmaple), the RAID level, and the number of devices:

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

Create and Mount the Filesystem

create a filesystem on the array:
    
     sudo mkfs.ext4 -F /dev/md0
    
   
Create a mount point to attach the new filesystem:
    
     sudo mkdir -p /mnt/md0
    
   
Mount the filesystem
    
     sudo mount /dev/md0 /mnt/md0
    
   

Save the Array Layout

To make sure that the array is reassembled automatically at boot, we will have to adjust the /etc/mdadm/mdadm.conf by executing the following commad:

    
     sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
    
   
update the initramfs, or initial RAM file system, so that the array will be available during the early boot process:
    
     sudo update-initramfs -u
    
   
And Finlay add the new filesystem mount options to the /etc/fstab file for automatic mounting at boot:
    
     echo ‘/dev/md0 /mnt/md0 ext4 defaults,nofail,discard 0 0’ | sudo tee -a /etc/fstab
    
   

Creating a RAID 1 Array

The RAID 1 array type is implemented by mirroring data across all available disks. Each disk in a RAID 1 array gets a full copy of the data, providing redundancy in the event of a device failure. This option Require minimum of 2 storage devices

In the following examples we are simulate 4 storage devices

To get started, find full informations for the raw disks that you will be using for the raid:

    
     lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT
    
   
Output looks like
    
     NAME SIZE FSTYPE TYPE MOUNTPOINT
sdc 500G disk
sdd 500G disk
sde 500G disk
sdf 500G disk
vda 20G disk
├─vda1 200G ext4 part /
└─vdb1 100G part
    
   

As above, we have 4 disks without a filesystem, each 500G in size. In this example, these devices have been given the /dev/sdc and /dev/sdd /dev/sde /dev/sdf identifiers for this session. These will be the raw components we will use to build the array.

Create the Array

To create a RAID 0 array ,we need to pass them in to the mdadm –create shell command. You will have to specify the device name you wish to create (/dev/md0 in our exmaple), the RAID level, and the number of devices:

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

Create and Mount the Filesystem

create a filesystem on the array:
    
     sudo mkfs.ext4 -F /dev/md0
    
   
Create a mount point to attach the new filesystem:
    
     sudo mkdir -p /mnt/md0
    
   
Mount the filesystem
    
     sudo mount /dev/md0 /mnt/md0
    
   

Save the Mdadm RAID Arrays Layout

To make sure that the array is reassembled automatically at boot, we will have to adjust the /etc/mdadm/mdadm.conf by executing the following commad:
    
     sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
    
   
update the initramfs, or initial RAM file system, so that the array will be available during the early boot process:
    
     sudo update-initramfs -u
    
   
And Finlay add the new filesystem mount options to the /etc/fstab file for automatic mounting at boot:
    
     echo ‘/dev/md0 /mnt/md0 ext4 defaults,nofail,discard 0 0’ | sudo tee -a /etc/fstab
    
   

Creating a RAID 10 Array

The RAID 10 array type is traditionally implemented by creating a striped RAID 0 array composed of sets of RAID 1 arrays. This nested array type gives both redundancy and high performance, at the expense of large amounts of disk space. The mdadm utility has its own RAID 10 type that provides the same type of benefits with increased flexibility. It is not created by nesting arrays, but has many of the same characteristics and guarantees. 

We will be using the mdadm RAID 10 here. This option Require minimum of 3 storage devices

In the following examples we are simulate 4 storage devices.

To get started, find full informations for the raw disks that you will be using for the raid:

    
     lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT
    
   
Output looks like
    
     NAME SIZE FSTYPE TYPE MOUNTPOINT
sdc 500G disk
sdd 500G disk
sde 500G disk
sdf 500G disk
vda 20G disk
├─vda1 200G ext4 part /
└─vdb1 100G part
    
   
As above, we have 4 disks without a filesystem, each 500G in size. In this example, these devices have been given the /dev/sdc and /dev/sdd /dev/sde /dev/sdf identifiers for this session. These will be the raw components we will use to build the array.

Create Mdadm RAID Arrays

To create a RAID 0 array ,we need to pass them in to the mdadm –create command. You will have to specify the device name you wish to create (/dev/md0 in our exmaple), the RAID level, and the number of devices:

If you want to use a different layout, or change the number of copies, you will have to use the –layout= option, which takes a layout and copy identifier. The layouts are n for near, f for far, and o for offset. The number of copies to store is appended afterwards.

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

Create and Mount the Filesystem

create a filesystem on the array:
    
     sudo mkfs.ext4 -F /dev/md0
    
   
Create a mount point to attach the new filesystem:
    
     sudo mkdir -p /mnt/md0
    
   
Mount the filesystem
    
     sudo mount /dev/md0 /mnt/md0
    
   

Save the Array Layout

To make sure that the array is reassembled automatically at boot, we will have to adjust the /etc/mdadm/mdadm.conf by executing the following commad:
    
     sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
    
   
update the initramfs, or initial RAM file system, so that the array will be available during the early boot process:
    
     sudo update-initramfs -u
    
   
And Finlay add the new filesystem mount options to the /etc/fstab file for automatic mounting at boot:
    
     echo ‘/dev/md0 /mnt/md0 ext4 defaults,nofail,discard 0 0’ | sudo tee -a /etc/fstab
    
   
XsoftHost Support

Share

Recent Posts

Add Extra IP addresses to server configuration On Ubuntu 17.10 and later

Each failover IP address will need its own line in the configuration file. The configuration…

4 years ago

How to change the maximum upload file size for PHP

There are several scenarios that you might need to increase or decrease your php maximum…

6 years ago

How to install Let’s Encrypt Plugin in WHM/cPanel

What is Let’s Encrypt? Let’s Encrypt is a free certificate authority provided by the Internet…

6 years ago

How to install python in my cPanel and add py extension

Python normally installed on all cPanel hosting server because most of Centos/red hat update system…

6 years ago

How to install and enable GUI GNOME Desktop on centos 7

Usually CentOS 7 comes in a numbers of variants, For most users, there are two…

6 years ago

How to Uninstall cloudlinux and covert back to centos cpanel server

CloudLinux supports all the hardware supported by RHEL/CentOS, with few exceptions. Exceptions are usually hardware…

6 years ago