Setting up an Ubuntu 22.04 Server with RAID1 and LVM
Voici toutes les étapes nécessaires à la construction d'un RAID1 logiciel sur Ubuntu 22.
Source
Création du RAID logiciel
Although setting up a simple single-drive Ubuntu server is a good start for building your self-hosted cloud, adding a second drive as a RAID array to the system from the start will give you far improved reliability and a greater sense of security for your data. Even if you have a drive fail, you have a redundant mirrored drive to keep your data safe and operational until you can replace the failed drive.
Additionally, LVM affords you the ability to somewhat future-proof your storage by essentially creating a virtual disk that you can migrate between physical disks and expand without needing to worry about the underlying storage configuration being a limiting factor.
Here's how to set up a RAID1 mirrored system with LVM from the start.
I dismiss simple easy first steps
- Under Guided storage configuration, select Custom storage layout and hit the space bar
- Select Done and hit enter
- Storage configuration
- Clear all partitions from your drives (if existing partitions/RAID exist)
You should now have 2 identically-sized drives with all free space under AVAILABLE DEVICES
For each of your drives under AVAILABLE DEVICES :
- Tab to select the local disk and hit enter
- Tab to select Use As Boot Device (or Add As Another Boot Device) and hit enter
- Tab- to select free space under that drive and hit enter
- Tab- to select Add GPT Partition and hit enter
- Tab, then hit enter
- Tab to select Leave unformatted, then hit enter
- Tab to select Create then hit enter
- Select Create software RAID (md) and hit enter
- Leave Name as md0 and tab
- Leave RAID Level as 1 (mirrored) and tab
- Tab to the first of you drives' partitions labeled as partition 2 and hit Space to choose it
- Tab to the second of you drives' partitions labeled as partition 2 and hit Space to choose it
- Tab to Create and hit enter
- Under md0 select free space and hit enter
- Select Add GPT Partition and hit enter
- Set the Size to 2G and hit tab
- Tab again, leaving Format set to ext4
- On Mount, hit enter, then select /boot, then hit enter
- Tab to select Create then hit enter
- Under md0 select free space again and hit enter
- Select Add GPT Partition and hit enter
- Leave the Size blank and hit tab
- Hit enter on Format, select Leave unformatted, and hit enter
- Tab to select Create then hit enter
- Select Create volume group (LVM) and hit enter
- Leave Name set to vg0 and hit tab
- Under md0 select partition 2 and hit space to choose it
- Tab to Create and hit enter
- Under vg0 (new) select free space and hit enter
- Select Create Logical Volume and hit enter
- Leave the Name set to lv-0
- Select Create and hit enter
- Select Done and hit enter
- On the Confirm destructive action screen, select Continue and hit enter
Congrats! You made it past the most complicated part of the installation!
Extension du volume pour qu'il utilise l'intégralité du volume
Il arrive que le volume logique (VL) créé n'utilise pas tout l'espace disponible dans le volume group (VG). Pour s'en assurer, utiliser les commandes vgdisplay
pour obtenir les infos du VG et lvdisplay
pour le VL.
Si LV Size
est inférieur à VG Size
, utiliser la commande suivante pour étendre le volume logique :
Check of RAID construction
Here are some commands in order to check RAID existence and replication :
cat /proc/mdstat
Sample output :
md0 : active raid1 nvme1n1p2[1] nvme0n1[0]
975526912 blocks super 1.2 [2/2] [UU]
bitmap: 4/8 pages [16KB], 65536KB chunk
sudo mdadm --detail /dev/md0
Sample output :
/dev/md0:
Version : 1.2
Creation Time : Tue Feb 20 08:27:49 2024
Raid Level : raid1
Array Size : 975526912 (930.33 GiB 998.94 GB)
Used Dev Size : 975526912 (930.33 GiB 998.94 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Intent Bitmap : Internal
Update Time : Tue Feb 20 12:18:55 2024
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Consistency Policy : bitmap
Name : ubuntu-server:0
UUID : a1a4a38d:bbda50c1:0316aea9:6c666b28
Events : 1876
Number Major Minor RaidDevice State
0 259 0 0 active sync /dev/nvme0n1
1 259 3 1 active sync /dev/nvme1n1p2
watch cat /proc/mdstat
Permet de suivre en direct la réplication des disques