How to Configure and Test RAID 1 on Ubuntu 20.4.1
To Configure and Test RAID 1 on Ubuntu 20.4.1
Introduction:
RAID (Redundant Array of Independent Disks) is a data storage virtualization technology that connects multiple physical disk drive components into one or more logical units for the purposes of data redundancy and performance improvement that was in contrast to the early concept of highly reliable mainframe disk drives referred to as "single large expensive disk". This video will cover the configuration process of Raid 1.
Configuration Procedure:
Check the OS version by using the below command:
root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
Install Prerequisites by using the following command:
root@linuxhelp:~# apt-get install mdadm
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
finalrd
Suggested packages:
default-mta | mail-transport-agent dracut-core
The following NEW packages will be installed:
finalrd mdadm
0 upgraded, 2 newly installed, 0 to remove and 277 not upgraded.
Need to get 424 kB of archives.
After this operation, 1,285 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 finalrd all 6~ubuntu20.04.1 [6,852 B]
.
.
.
Check the disk whether there is already raid is configured or not:
root@linuxhelp:~# mdadm -E /dev/sd[b-c]
mdadm: No md superblock detected on /dev/sdb.
mdadm: No md superblock detected on /dev/sdc.
Drive partitioning for Raid:
root@linuxhelp:~# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.34).
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 0x4471dc9f.
**Press ‘n‘ for creating new partition.**
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Then choose ‘P‘ for Primary partition.
Select (default p): p
Next select the partition number as 1.
Partition number (1-4, default 1): 1
Give the default full size by just pressing two times Enter key.
First sector (2048-41943039, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943039, default 41943039):
Created a new partition 1 of type 'Linux' and of size 20 GiB.
Next press ‘p‘ to print the defined partition.
Command (m for help): p
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x4471dc9f
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 41943039 41940992 20G 83 Linux
Press ‘L‘ to list all available types.
Command (m for help): l
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi ea Rufus alignment
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT
10 OPUS 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fb VMware VMFS
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fc VMware VMKCORE
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fd Linux raid auto
1c Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fe LANstep
1e Hidden W95 FAT1 80 Old Minix be Solaris boot ff BBT
Type ‘t‘to choose the partitions.
Command (m for help): t
Selected partition 1
Choose ‘fd‘ for Linux raid auto and press Enter to apply.
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'.
Then again use ‘p‘ to print the changes what we have made.
Command (m for help): p
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x4471dc9f
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 41943039 41940992 20G fd Linux raid autodetect
Use ‘w‘ to write the changes.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
Create another disk :
root@linuxhelp:~# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.34).
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 0xbc2a1a89.
Press ‘n‘ for creating new partition.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Then choose ‘P‘ for Primary partition.
Select (default p): p
Next select the partition number as 1.
Partition number (1-4, default 1): 1
Give the default full size by just pressing two times Enter key.
First sector (2048-41943039, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943039, default 41943039):
Created a new partition 1 of type 'Linux' and of size 20 GiB.
Next press ‘p‘ to print the defined partition.
Command (m for help): p
Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xbc2a1a89
Device Boot Start End Sectors Size Id Type
/dev/sdc1 2048 41943039 41940992 20G 83 Linux
Press ‘L‘ to list all available types.
Command (m for help): l
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi ea Rufus alignment
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT
10 OPUS 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fb VMware VMFS
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fc VMware VMKCORE
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fd Linux raid auto
1c Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fe LANstep
1e Hidden W95 FAT1 80 Old Minix be Solaris boot ff BBT
Type ‘t‘to choose the partitions.
Command (m for help): t
Selected partition 1
Choose ‘fd‘ for Linux raid auto and press Enter to apply.
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'.
Then again use ‘p‘ to print the changes what we have made.
Command (m for help): p
Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xbc2a1a89
Device Boot Start End Sectors Size Id Type
/dev/sdc1 2048 41943039 41940992 20G fd Linux raid autodetect
Use ‘w‘ to write the changes.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
verify the changes on both drive using the same ‘mdadm‘ command:
root@linuxhelp:~# mdadm -E /dev/sd[b-c]
/dev/sdb:
MBR Magic : aa55
Partition[0] : 41940992 sectors at 2048 (type fd)
/dev/sdc:
MBR Magic : aa55
Partition[0] : 41940992 sectors at 2048 (type fd)
Create RAID 1 devices:
root@linuxhelp:~# mdadm -C /dev/md0 -l 1 -n 2 /dev/sd[b-c]1
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
Check the status of raid1 device:
root@linuxhelp:~# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
20953088 blocks super 1.2 [2/2] [UU]
[=>...................] resync = 7.6% (1606464/20953088) finish=4.8min speed=66936K/sec
unused devices: <none>
Check the details of raid1 devices:
root@linuxhelp:~# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Jan 21 10:04:00 2021
Raid Level : raid1
Array Size : 20953088 (19.98 GiB 21.46 GB)
Used Dev Size : 20953088 (19.98 GiB 21.46 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Jan 21 10:05:04 2021
State : clean, resyncing
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Consistency Policy : resync
Resync Status : 21% complete
Name : linuxhelp:0 (local to host linuxhelp)
UUID : 913406e8:c22d009a:9aaead9b:b808aae1
Events : 3
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
Create the File system on Raid device:
root@linuxhelp:~# mkfs.ext4 /dev/md0
mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 5238272 4k blocks and 1310720 inodes
Filesystem UUID: 4f7aa4f9-f7e0-4ca4-8865-8a3e340fce73
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
Mount the newly created filesystem under ‘/mnt/raid1‘ and create some files and verify the contents under mount point.
root@linuxhelp:~# mkdir /mnt/raid1
root@linuxhelp:~# mount /dev/md0 /mnt/raid1
root@linuxhelp:~# touch /mnt/raid1/linux.txt
root@linuxhelp:~# echo "Welcome to linuxhelp" > /mnt/raid1/linux.txt
Check the status of raid1 device:
root@linuxhelp:~# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
20953088 blocks super 1.2 [2/2] [UU]
unused devices: <none>
Open “fstab” file and add the following line:
root@linuxhelp:~# vim /etc/fstab
/dev/md0 /mnt/raid1 ext4 defaults 0 0
Check the details of raid1 devices:
root@linuxhelp:~# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Jan 21 10:04:00 2021
Raid Level : raid1
Array Size : 20953088 (19.98 GiB 21.46 GB)
Used Dev Size : 20953088 (19.98 GiB 21.46 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Jan 21 10:15:10 2021
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Consistency Policy : resync
Name : linuxhelp:0 (local to host linuxhelp)
UUID : 913406e8:c22d009a:9aaead9b:b808aae1
Events : 21
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
Before removing a disk we have to mark the disk as failed one, then only we can able to remove it. Remove the disk by using following command:
root@linuxhelp:~# mdadm -f /dev/md0 /dev/sdc1
mdadm: set /dev/sdc1 faulty in /dev/md0
check the details:
root@linuxhelp:~# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Jan 21 10:04:00 2021
Raid Level : raid1
Array Size : 20953088 (19.98 GiB 21.46 GB)
Used Dev Size : 20953088 (19.98 GiB 21.46 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Jan 21 10:17:42 2021
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 1
Spare Devices : 0
Consistency Policy : resync
Name : linuxhelp:0 (local to host linuxhelp)
UUID : 913406e8:c22d009a:9aaead9b:b808aae1
Events : 23
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
- 0 0 1 removed
1 8 33 - faulty /dev/sdc1
Now, remove the disk “sdc1”:
root@linuxhelp:~# mdadm --remove /dev/md0 /dev/sdc1
mdadm: hot removed /dev/sdc1 from /dev/md0
check the details:
root@linuxhelp:~# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Jan 21 10:04:00 2021
Raid Level : raid1
Array Size : 20953088 (19.98 GiB 21.46 GB)
Used Dev Size : 20953088 (19.98 GiB 21.46 GB)
Raid Devices : 2
Total Devices : 1
Persistence : Superblock is persistent
Update Time : Thu Jan 21 10:18:34 2021
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 0
Spare Devices : 0
Consistency Policy : resync
Name : linuxhelp:0 (local to host linuxhelp)
UUID : 913406e8:c22d009a:9aaead9b:b808aae1
Events : 24
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
- 0 0 1 removed
Verify the data after disk failure:
root@linuxhelp:~# cd /mnt/raid1/
root@linuxhelp:/mnt/raid1# du -sh linux.txt
4.0K linux.txt
Now, add the disk to replace the failure disk:
root@linuxhelp:/mnt/raid1# mdadm --manage /dev/md0 --add /dev/sdc1
mdadm: added /dev/sdc1
check the details:
root@linuxhelp:/mnt/raid1# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Jan 21 10:04:00 2021
Raid Level : raid1
Array Size : 20953088 (19.98 GiB 21.46 GB)
Used Dev Size : 20953088 (19.98 GiB 21.46 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Jan 21 10:24:13 2021
State : clean, degraded, recovering
Active Devices : 1
Working Devices : 2
Failed Devices : 0
Spare Devices : 1
Consistency Policy : resync
Rebuild Status : 21% complete
Name : linuxhelp:0 (local to host linuxhelp)
UUID : 913406e8:c22d009a:9aaead9b:b808aae1
Events : 33
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
2 8 33 1 spare rebuilding /dev/sdc1
With, this method configuration of raid 1 on Ubuntu comes to an end.
This RAID configuration is considered the most common secure RAID level.
A RAID 6 configuration is very similar to RAID 5 except that it has parity data written on two drives.
RAID 1 (Mirroring)
RAID 5/6 (Striping + Distributed Parity)
RAID 10 (Mirroring + Striping)
Software RAID.
Hardware RAID.