Configurer un RAID

Voir les RAID déjà existant :

$ cat /proc/mdstat 
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md2 : active raid1 sdb2[1] sda2[0]
      467798976 blocks [2/2] [UU]
      bitmap: 0/4 pages [0KB], 65536KB chunk

unused devices: <none>

Voir les partitions et disques utilisés :

lsblk
NAME    MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda       8:0    0 447.1G  0 disk  
├─sda1    8:1    0   511M  0 part  /boot/efi
├─sda2    8:2    0 446.1G  0 part  
│ └─md2   9:2    0 446.1G  0 raid1 /
├─sda3    8:3    0   511M  0 part  [SWAP]
└─sda4    8:4    0   960K  0 part  
sdb       8:16   0 447.1G  0 disk  
├─sdb1    8:17   0   511M  0 part  
├─sdb2    8:18   0 446.1G  0 part  
│ └─md2   9:2    0 446.1G  0 raid1 /
└─sdb3    8:19   0   511M  0 part  [SWAP]
sdc       8:32   0   1.8T  0 disk  
└─sdc1    8:33   0   511M  0 part  
sdd       8:48   0   1.8T  0 disk  
└─sdd1    8:49   0   511M  0 part  
sde       8:64   0   1.8T  0 disk  
└─sde1    8:65   0   511M  0 part  

Nous voulons créer un RAID sur sdc, sdd, sde. Pour cela, nous allns ajouter 3 partitions ; sdc2, sdd2, sde2.

$ sudo fdisk /dev/sdc

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

Command (m for help): p
Disk /dev/sdc: 1.8 TiB, 1920383410176 bytes, 3750748848 sectors
Disk model: INTEL SSDSC2KB01
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 8AFE7E28-7571-4D15-B133-40C2B464F9AA

Device     Start     End Sectors  Size Type
/dev/sdc1   2048 1048575 1046528  511M EFI System

Command (m for help): n
Partition number (2-128, default 2): 
First sector (1048576-3750748814, default 1048576): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1048576-3750748814, default 3750748814): 

Created a new partition 2 of type 'Linux filesystem' and of size 1.8 TiB.

Command (m for help): t
Partition number (1,2, default 2): 
Partition type (type L to list all types): 29

Changed type of partition 'Linux filesystem' to 'Linux RAID'.

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

Nous répétons cette commande pour /dev/sdd et /dev/sde.

Créons maintenant le RAID 5 sur ces 3 nouvelles partitions :

$ sudo mdadm --create --verbose /dev/md4 --level=5 --raid-devices=3 /dev/sdc2 /dev/sdd2 /dev/sde2
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 1874717696K
mdadm: automatically enabling write-intent bitmap on large array
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md4 started.

Si nous revérifions les RAID configurés, nous devrions avoir quelque chose comme ça :

$ cat /proc/mdstat 
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md4 : active raid5 sde2[3] sdd2[1] sdc2[0]
      3749435392 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]
      [>....................]  recovery =  0.1% (2748380/1874717696) finish=147.5min speed=211413K/sec
      bitmap: 0/14 pages [0KB], 65536KB chunk

md2 : active raid1 sdb2[1] sda2[0]
      467798976 blocks [2/2] [UU]
      bitmap: 1/4 pages [4KB], 65536KB chunk

unused devices: <none>

Persistons ces changements :

$ sudo mdadm --detail --scan /dev/md4 | sudo tee -a /etc/mdadm/mdadm.conf
ARRAY /dev/md4 metadata=1.2 spares=1 name=database-master:4 UUID=ee232d16:3702688b:8a4e46fb:2ed377b9
$ sudo update-initramfs -u
update-initramfs: Generating /boot/initrd.img-4.19.0-6-amd64
I: The initramfs will attempt to resume from /dev/sdb3
I: (UUID=c31b326b-4022-49c1-b24d-7bec928147ba)
I: Set the RESUME variable to override this.

Et redémarrons pour vérififer que le RAID est bien associé au démarrage :

$ sudo reboot 
$ cat /proc/mdstat 
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md2 : active raid1 sda2[0] sdb2[1]
      467798976 blocks [2/2] [UU]
      bitmap: 0/4 pages [0KB], 65536KB chunk

md4 : active (auto-read-only) raid5 sde2[3] sdc2[0] sdd2[1]
      3749435392 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]
      bitmap: 0/14 pages [0KB], 65536KB chunk

unused devices: <none>

Au cas où le RAID est dégradé (présence d'un _) sans reconstruire, difinissez la partition en faulty, retirez-la, puis réajoutez-la :

$ sudo mdadm --manage /dev/md4 -f /dev/sde2
mdadm: set /dev/sde2 faulty in /dev/md4
$ sudo mdadm --manage /dev/md4 -r /dev/sde2
mdadm: hot removed /dev/sde2 from /dev/md4
$ sudo mdadm --manage /dev/md4 -a /dev/sde2
mdadm: re-added /dev/sde2
$ cat /proc/mdstat 
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md2 : active raid1 sda2[0] sdb2[1]
      467798976 blocks [2/2] [UU]
      bitmap: 3/4 pages [12KB], 65536KB chunk

md4 : active raid5 sde2[3] sdc2[0] sdd2[1]
      3749435392 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]
      [>....................]  recovery =  0.1% (2730332/1874717696) finish=148.5min speed=210025K/sec
      bitmap: 0/14 pages [0KB], 65536KB chunk

unused devices: <none>

Source : https://raid.wiki.kernel.org/index.php/RAID_setup