Zum Inhalt springen

RAID (Redundant Array of Independent Disks) is a storage technology that allows the combination of multiple hard drives to improve performance, redundancy, or both. Debian, a robust and popular Linux distribution, offers flexible management of RAID configurations through the mdadm tool, which is a utility for managing software RAID devices. This article explains how to install and configure RAID on Debian, covering the various necessary steps.

1. Pré-requis

Before you begin, make sure you have:

  • An installed and functional Debian system.
  • Several hard drives or SSDs that you want to combine in RAID.
  • Administrator (root) access to execute the necessary commands.

RAID Types

There are different levels of RAID that you can configure, each having specific advantages:

  • RAID 0 : Stripping (enhanced performance, but no redundancy).
  • RAID 1 : Mirroring (data redundancy, no performance improvement).
  • RAID 5 : Distributed parity (improved performance and redundancy).
  • RAID 10 : Combination of RAID 1 and RAID 0 (good compromise between performance and redundancy).
  • RAID 6 : Double parity (stronger redundancy than RAID 5) ).

2. Préparation du Système

Update of your Debian system

It is always preferable to start by updating your system before proceeding with installations. Run the following command to ensure that all your packages are up to date:

apt update && sudo apt upgrade -y

Installation of necessary tools

Debian does not come with pre-installed RAID tools, so we need to install mdadm, the software RAID utility for Linux.

apt install mdadm

After the installation, you can check that mdadm is installed by using the following command:

mdadm --version

3. Préparer les disques

Identify the disks

Once mdadm is installed, we need to identify the disks we want to use to create the RAID. For this, you can use the lsblk or fdisk command to list the available disks.

lsblk

This will display a list of disks, along with their partitions and sizes. For example, you might have disks named /dev/sda, /dev/sdb, etc. Choose the disks to use in the RAID.

Partition the disks

It is preferable to partition your disks before adding them to the RAID. Use fdisk or parted to create partitions on each disk.

Here is an example with fdisk:

sudo fdisk /dev/sda
  1. Type n to create a new partition.
  2. Select the type of Linux RAID autodetect partition (code fd).
  3. Repeat this process for each disk you want to use in the RAID.

Once the partitions are created, you can check with lsblk or fdisk -l.

4. Créer un volume RAID

With the prepared disks, you can now create the RAID volume.

Create a RAID with mdadm

Suppose you want to create a RAID 1 with two disks (for example /dev/sda1 and /dev/sdb1). You can use the following command:

sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
  • /dev/md0 is the RAID device that you create.
  • --level=1 specifies that you are creating a RAID 1 (mirror).
  • --raid-devices=2 indicates that you are using 2 disks.

Check the status of the RAID​

After creating the RAID, you can check the status of the RAID with the command:

sudo mdadm --detail /dev/md0

This will provide you with detailed information about the status of your RAID volume.

5. Formater le volume RAID

The created RAID volume is still unformatted. You need to format it before you can use it. For example, to format it as ext4, use the following command:

sudo mkfs.ext4 /dev/md0

This will format the RAID volume to ext4, a common file system under Linux.

6. Monter le volume RAID

To mount the RAID volume, you first need to create a mount point:

sudo mkdir /mnt/raid

Then, mount the RAID volume on this mount point:

sudo mount /dev/md0 /mnt/raid

Check that the volume is mounted with the command df -h or lsblk.

7. Ajouter le RAID au fichier /etc/fstab

To have the RAID volume mounted automatically at startup, you need to add an entry in the /etc/fstab file.

Open the file /etc/fstab with a text editor:

sudo nano /etc/fstab

Add the following line at the end of the file:

/dev/md0    /mnt/raid    ext4    defaults    0    2

Save and close the file.

Check the fstab configuration

To test if the entry in fstab works correctly, you can unmount the volume and try to remount it automatically:

sudo umount /mnt/raid
sudo mount -a

This should automatically mount the RAID volume.

8. Configurer le RAID pour démarrer au démarrage

To ensure that your RAID is automatically recognized and started at system boot, you need to save your configuration in the file /etc/mdadm/mdadm.conf.

Generate a configuration file with the following command:

sudo mdadm --detail --scan --verbose > /etc/mdadm/mdadm.conf

This will add the RAID configuration information to this file, allowing mdadm to automatically detect and start the RAID volumes at boot.

9. Surveillance et gestion du RAID

Check the status of the RAID​

You can check the status of the RAID at any time with the command:

sudo mdadm --detail /dev/md0

This will provide you with information about the status of the RAID, including the health of the disks and whether everything is functioning correctly.

Add a disk to the RAID

If you want to add an additional disk to a RAID (for example, for RAID 5 or 10), you can use the following command:

sudo mdadm --add /dev/md0 /dev/sdc1

This will add /dev/sdc1 to the RAID /dev/md0.

Remove a disk from the RAID

To remove a disk from a RAID, use the following command:

sudo mdadm --remove /dev/md0 /dev/sda1

Make sure you have other disks to ensure redundancy before removing a disk.

10. Sauvegarde et récupération

It is always recommended to have regular backups of your data, even with a configured RAID. Although RAID improves fault tolerance, it does not replace a comprehensive backup strategy.

Recovery after a disk failure

If a disk fails, you can replace it and rebuild the RAID. Use the following command to add the new disk:

sudo mdadm --add /dev/md0 /dev/sdX1

This will automatically rebuild the RAID using the new disk.

Conclusion

Configuring a RAID on Debian with mdadm is a fairly simple task, but it requires a good understanding of RAID concepts and the associated commands. Once you have configured your RAID, you can improve the performance or redundancy of the data, depending on your needs. Make sure to regularly monitor your RAID and maintain reliable backups to avoid any data loss.

Bonus

lsblk est une commande puissante qui permet non seulement de lister les périphériques de stockage, mais aussi d'afficher des informations détaillées sur leurs partitions et leur utilisation dans le système.

blkid est un utilitaire puissant qui permet non seulement d'identifier les systèmes de fichiers sur les partitions d'un disque, mais aussi de fournir des détails essentiels tels que les UUID, les types de systèmes de fichiers et d'autres attributs importants pour la gestion des disques.

df -h est un outil très utile qui permet de visualiser l'utilisation de l'espace disque sur votre système, en affichant des informations claires et compréhensibles sur la capacité totale, l'espace utilisé, l'espace libre et le pourcentage d'utilisation de chaque système de fichiers monté.

fdisk -l est une commande puissante utilisée dans les systèmes d'exploitation basés sur Unix et Linux, qui permet non seulement d'afficher la liste complète des disques et partitions disponibles, mais aussi de fournir des informations détaillées sur chaque partition, telles que leur taille, leur type de système de fichiers, et leur état de montage.

l'exécution de la commande sudo update-initramfs -u est cruciale pour garantir que les modifications apportées aux modules du noyau soient correctement intégrées et permettent de