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
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:
Create and Mount the Filesystem
sudo mkfs.ext4 -F /dev/md0
sudo mkdir -p /mnt/md0
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
sudo update-initramfs -u
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
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
sudo mkfs.ext4 -F /dev/md0
sudo mkdir -p /mnt/md0
sudo mount /dev/md0 /mnt/md0
Save the Mdadm RAID Arrays Layout
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -u
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
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
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
sudo mkfs.ext4 -F /dev/md0
sudo mkdir -p /mnt/md0
sudo mount /dev/md0 /mnt/md0
Save the Array Layout
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -u
echo ‘/dev/md0 /mnt/md0 ext4 defaults,nofail,discard 0 0’ | sudo tee -a /etc/fstab