How to Configure Raid 6 on Ubuntu 21.04

To Configure Raid 6 On Ubuntu 21.04

Introduction:

A redundant array of independent disks, or RAID 6 (double-parity RAID), is a kind of RAID level that makes use of block-level striping and distributes two parity blocks per disk within the array. Prerequisite: Mdadm package

Installation Procedure :

Step 1: Check the installed OS version by using the following command

root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 21.04
Release:	21.04
Codename:	hirsute

Step 2: List the available block storage by using the below command

root@linuxhelp:~# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0    7:0    0     4K  1 loop /snap/bare/5
loop1    7:1    0  55.5M  1 loop /snap/core18/2253
loop2    7:2    0  55.4M  1 loop /snap/core18/1997
loop3    7:3    0  61.8M  1 loop /snap/core20/1242
loop4    7:4    0   219M  1 loop /snap/gnome-3-34-1804/77
loop5    7:5    0   219M  1 loop /snap/gnome-3-34-1804/72
loop6    7:6    0 247.9M  1 loop /snap/gnome-3-38-2004/87
loop7    7:7    0  64.8M  1 loop /snap/gtk-common-themes/1514

loop8    7:8    0    51M  1 loop /snap/snap-store/547
loop9    7:9    0  65.2M  1 loop /snap/gtk-common-themes/1519
loop10   7:10   0  54.2M  1 loop /snap/snap-store/558
loop11   7:11   0  32.4M  1 loop /snap/snapd/13640
loop12   7:12   0  42.2M  1 loop /snap/snapd/14066
loop13   7:13   0  61.9M  1 loop /snap/core20/1270
sda      8:0    0    40G  0 disk 
├─sda1   8:1    0     1M  0 part 
├─sda2   8:2    0   513M  0 part /boot/efi
└─sda3   8:3    0  39.5G  0 part /
sdb      8:16   0    10G  0 disk 
sdc      8:32   0    10G  0 disk 
sdd      8:48   0    10G  0 disk 
sde      8:64   0    10G  0 disk 
sr0     11:0    1  1024M  0 rom  

Step 3: Open fdisk to create partions on /dev/sdb disk by using the below command

root@linuxhelp:~# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xdce532c1.

Creating New Partition
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)

   e   extended (container for logical partitions)
Select (default p): 

Using default response p.

Using default partition number and using entire disk space partition by pressing enter for all
Partition number (1-4, default 1): 
First sector (2048-20971519, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519): 

Created a new partition 1 of type 'Linux' and of size 10 GiB.

Changing the partition type to Linux raid autodetect 
Command (m for help): t

Selected partition 1
Hex code or alias (type L to list all): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'.

Saving the all changes made to the disks
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Step 4: Open fdisk to create partions on /dev/sdc disk by using the below command

root@linuxhelp:~# fdisk /dev/sdc

Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.


Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x5d9a4358.

Creating New Partition
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.

Using default partition number and using entire disk space partition by pressing enter for all
Partition number (1-4, default 1): 
First sector (2048-20971519, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519): 

Created a new partition 1 of type 'Linux' and of size 10 GiB.

Changing the partition type to Linux raid autodetect 
Command (m for help): t

Selected partition 1
Hex code or alias (type L to list all): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'.




Saving the all changes made to the disks
Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Step 5: Open fdisk to create partions on /dev/sdd disk by using the below command

root@linuxhelp:~# fdisk /dev/sdd

Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x8d954387.

Creating New Partition
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.

Using default partition number and using entire disk space partition by pressing enter for all
Partition number (1-4, default 1): 
First sector (2048-20971519, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519): 

Created a new partition 1 of type 'Linux' and of size 10 GiB.



Changing the partition type to Linux raid autodetect 
Command (m for help): t

Selected partition 1
Hex code or alias (type L to list all): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'.

Saving the all changes made to the disks
Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Step 6: Open fdisk to create partions on /dev/sde disk by us

root@linuxhelp:~# fdisk /dev/sde

Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xdfd97276.

Creating New Partition
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 
Using default response p.


Using default partition number and using entire disk space partition by pressing enter for all
Partition number (1-4, default 1): 
First sector (2048-20971519, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519): 

Created a new partition 1 of type 'Linux' and of size 10 GiB.

Changing the partition type to Linux raid autodetect 
Command (m for help): t

Selected partition 1
Hex code or alias (type L to list all): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'.

Saving the all changes made to the disks
Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Step 7: List the available block storage by using the below command

root@linuxhelp:~# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0    7:0    0     4K  1 loop /snap/bare/5
loop1    7:1    0  55.5M  1 loop /snap/core18/2253
loop2    7:2    0  55.4M  1 loop /snap/core18/1997
loop3    7:3    0  61.8M  1 loop /snap/core20/1242
loop4    7:4    0   219M  1 loop /snap/gnome-3-34-1804/77
loop5    7:5    0   219M  1 loop /snap/gnome-3-34-1804/72
loop6    7:6    0 247.9M  1 loop /snap/gnome-3-38-2004/87

loop7    7:7    0  64.8M  1 loop /snap/gtk-common-themes/1514
loop8    7:8    0    51M  1 loop /snap/snap-store/547
loop9    7:9    0  65.2M  1 loop /snap/gtk-common-themes/1519
loop10   7:10   0  54.2M  1 loop /snap/snap-store/558
loop11   7:11   0  32.4M  1 loop /snap/snapd/13640
loop12   7:12   0  42.2M  1 loop /snap/snapd/14066
loop13   7:13   0  61.9M  1 loop /snap/core20/1270
sda      8:0    0    40G  0 disk 
├─sda1   8:1    0     1M  0 part 
├─sda2   8:2    0   513M  0 part /boot/efi
└─sda3   8:3    0  39.5G  0 part /
sdb      8:16   0    10G  0 disk 
└─sdb1   8:17   0    10G  0 part 
sdc      8:32   0    10G  0 disk 
└─sdc1   8:33   0    10G  0 part 
sdd      8:48   0    10G  0 disk 
└─sdd1   8:49   0    10G  0 part 
sde      8:64   0    10G  0 disk 
└─sde1   8:65   0    10G  0 part 
sr0     11:0    1  1024M  0 rom

Step 8: Create Raid device in Raid level 6 with four block devices by using the below command

root@linuxhelp:~# mdadm -C /dev/md0 -l 6 -n 4 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

Step 9: Format Raid partition to ext4 file system by using the below command

root@linuxhelp:~# mkfs.ext4 /dev/md0
mke2fs 1.45.7 (28-Jan-2021)
Creating filesystem with 5237760 4k blocks and 1310720 inodes
Filesystem UUID: 3a757d58-7ba9-4ade-9dc5-3e2cbb1bc6df

Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

Step 10: View the details of Raid device by using the below command

root@linuxhelp:~# mdadm --detail /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Fri Dec 10 06:54:13 2021
        Raid Level : raid6
        Array Size : 20951040 (19.98 GiB 21.45 GB)
     Used Dev Size : 10475520 (9.99 GiB 10.73 GB)
      Raid Devices : 4
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Fri Dec 10 06:55:21 2021
             State : clean, resyncing 
    Active Devices : 4
   Working Devices : 4
    Failed Devices : 0
     Spare Devices : 0

            Layout : left-symmetric
        Chunk Size : 512K

Consistency Policy : resync

     Resync Status : 69% complete

              Name : linuxhelp:0  (local to host linuxhelp)
              UUID : e4c2556d:a955ac14:21c94178:2aad2c37
            Events : 13

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       33        1      active sync   /dev/sdc1
       2       8       49        2      active sync   /dev/sdd1
       3       8       65        3      active sync   /dev/sde1

Step 11: Create directory to mount Raid partition by using the below command

root@linuxhelp:~# mkdir /test

Step 12: Mount Raid partition on /test directory by using the below command

root@linuxhelp:~# mount /dev/md0 /test

Step 13:List the all mounted devices by using the below command

root@linuxhelp:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           259M  1.6M  258M   1% /run
/dev/sda3        39G   11G   27G  28% /
tmpfs           1.3G     0  1.3G   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
/dev/sda2       512M  5.3M  507M   2% /boot/efi
tmpfs           259M  120K  259M   1% /run/user/1000
/dev/md0         20G   45M   19G   1% /test

Step 14: Create a file in Raid storage device by using the below command

root@linuxhelp:~# vi /test/file..

Step 15: Make two block device fault out of four then only able to remove it by using the below command

root@linuxhelp:~# mdadm /dev/md0 -f /dev/sdb1 /dev/sdc1
mdadm: set /dev/sdb1 faulty in /dev/md0
mdadm: set /dev/sdc1 faulty in /dev/md0

Step 16:View the devices details by using the below command

root@linuxhelp:~# mdadm --detail /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Fri Dec 10 06:54:13 2021
        Raid Level : raid6
        Array Size : 20951040 (19.98 GiB 21.45 GB)
     Used Dev Size : 10475520 (9.99 GiB 10.73 GB)
      Raid Devices : 4
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Fri Dec 10 06:58:22 2021
             State : clean, degraded 
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 2
     Spare Devices : 0

            Layout : left-symmetric
        Chunk Size : 512K

Consistency Policy : resync

              Name : linuxhelp:0  (local to host linuxhelp)
              UUID : e4c2556d:a955ac14:21c94178:2aad2c37
            Events : 22

    Number   Major   Minor   RaidDevice State
       -       0        0        0      removed
       -       0        0        1      removed
       2       8       49        2      active sync   /dev/sdd1
      
 3       8       65        3      active sync   /dev/sde1

       0       8       17        -      faulty   /dev/sdb1
       1       8       33        -      faulty   /dev/sdc1

Step 17:Remove two block device out of four by using the below command

root@linuxhelp:~# mdadm /dev/md0 -r /dev/sdb1 /dev/sdc1
mdadm: hot removed /dev/sdb1 from /dev/md0
mdadm: hot removed /dev/sdc1 from /dev/md0

Step 18: Now view the file created before removing two block device by using the below command

root@linuxhelp:~# ls /test/
file  lost+found

By this Configuration of Raid 6 on Ubuntu 21.04 have been completed

Tag : RAID Ubuntu Linux
FAQ
Q
How to remove a block device from Raid partition ?
A
Remove a block device from Raid partition by using following command "mdadm /dev/md0 -r "
Q
How to fail a block device from the Raid partition?
A
Fail a block device from Raid partition by using the following command "mdadm /dev/md0 -f "
Q
What to do before removing block devices from Raid partitions?
A
Before removing block devices from the Raid partition must need to fail that device.
Q
How many block devices are required for the Raid 6 partition?
A
Four block devices must be needed for the Raid 6 partition.
Q
What is an acronym for RAID?
A
RAID is an acronym for "Redundant Array of Inexpensive Disks".