How To Raid In Linux With mdadm? – POFTUT

How To Raid In Linux With mdadm?

Hi, today I am gonna show you how to make raid ( redundant array of inexpensive disks ). Why wee need it? Think about what you have customer data stored in a server. Say one day disk is dead and then all of your data about the customer are gone. This is a very bad new.  What if disk dies but the data remains the same. This will be very good. You can think that will disk dies frequently. No, but it is not impossible, especially in the enterprise side or in personal use at home. RAID is a technology to backup disks with extra disks. Say we have 3 disks which are used separate projects. And we want to backup them with high availability in particular working hours. RAID can be done with separate hardware, firmware or software. Making raid with hardware is the best, fast and reliable way but it may be expensive or too much for the project. Firmware raid is generally provided by motherboard manufacturers as a cheap option for hardware raid. Software raid is the cheapest and least reliable way to mail raid. But it can be suitable for home or unprofessional usage. I will not delve into details of raid levels. But you can find more about in wikipedia. In Linux software raid consist of a kernel module and user-space programs.

List Disk Drives

3 disks are used actively to store data but 4. disk the or spare disk is used to backup for 3 disks. It doesn’t store all data of the 3 disks as it is impossible if 3 disks are near to full.

First list disks. We will make an array with vdb,vdc,vdd and vde disks. I make this in my VM so your disk names are maybe different like sda, sdb etc. All disk has 1 GB.

Install mdadm

Install mdadm in Ubuntu, Debian, Mint, Kali with the following apt command.

Install mdadm For Ubuntu, Debian, Mint, Kali

Install mdadm For Ubuntu, Debian, Mint, Kali

Load mdadm Kernel Module

mdadm provides services via low-level drivers. It has a kernel module named raid456 and can be loaded with the following command. In order to load a Linux kernel module, we need root privileges which can be provided with the sudo command like below.

We can check if the raid456 kernel module is loaded properly with the lsmod command which will list all currently loaded kernel modules.

Load mdadm Kernel Module

Load mdadm Kernel Module

Create RAID

We should give the count of the disk with raid-devices level with level and the disk to be used in the raid. Here metadata is optional it sets raid metadata version After the command is executed we got a message that says our new disk which we named md0 is created. If you want to create raid0 use level=stripe and raid1 level=mirror

LEARN MORE  Windows Chkdsk Utility Tutorial with Examples To Fix File System Errors

Print mdadm Information

To see raid devices status we will print the /proc/mdstat file like below. Shows total disk count and total usable size which is 3/4 of the total disk size. As you can see the version is 1.2 where we set it while creating the array

Save/Backup mdadm Configuration

In order to save or backup mdadm with the --detail and --scan options like below.

LEARN MORE  What Is Linux LVM (Logical Volume Management)?

List Disk Status and Array

We can list disk and array status with the -E option by providing the disk name.

Create File System For New Disk

We will use mkfs.ext4 command in order to create a file system to the /dev/md0 disk drive.

LEARN MORE  Linux Mount Command Tutorial With Examples

Mount Disk

Mount the disk and create some files. Also, show the status of mounted disks.

Remove Disk From Array

Say disk vdd is corrupted. And we need to remove it.

Add Disk To Disk Array

We will use --add option disk vdf to the mdm drive md0 .

Restart or Initialize New Disk

To use raid after the restart. Raid devices must be reassembled every time to use.

1 Response

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)