-
LINUX > gérer un système RAID
RAID-1
Préparation des disques
Avant tout, il font démounter les disques durs.
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 465,8G 0 disk ├─sda1 8:1 0 500M 0 part └─sda2 8:2 0 465,3G 0 part /media/mondisque sdb 8:16 0 465,8G 0 disk ├─sdb1 8:17 0 100M 0 part └─sdb2 8:18 0 465,7G 0 part sdc 8:32 0 119,2G 0 disk ├─sdc1 8:33 0 111,5G 0 part / └─sdc5 8:37 0 7,8G 0 part [SWAP]
Par exemple, si le RAID1 comporte les disque
sdaetsdb, il faut démounter/media/mondisque:sudo umount /media/mondisque
Puis, formater en bas niveau :
sudo dd if=/dev/zero of=/dev/sdb bs=512 count=1
1+0 records in 1+0 records out 512 bytes copied, 0,00108261 s, 473 kB/s
bs=512etcount=1permet de ne supprimer que le premier et dernier blocs, ce qui évite de tout effecer et gagner beaucoup de temps.configuration du RAID1
sudo apt-get install mdadm
Puis :
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda /dev/sdb
mdadm: array /dev/md0 started.
/dev/md0nom du RAID--level=1niveau du RAID.--raid-devices=2nombre de périphériques dans le RAIDPour voir la progression de la création du RAID :
watch cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] md0 : active raid1 sdb[1] sda[0] 488255488 blocks super 1.2 [2/2] [UU] [>....................] resync = 1.2% (6091648/488255488) finish=107.8min speed=74518K/sec bitmap: 4/4 pages [16KB], 65536KB chunk unused devices: <none>
Ensuite, créer un système de fichier sur la nouvelle grappe du RAID créé :
sudo mkfs.ext4 /dev/md0
mke2fs 1.42.13 (17-May-2015) Creating filesystem with 122063872 4k blocks and 30523392 inodes Filesystem UUID: ********-f910-4419-b352-d729a05587d4 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
Créér un point de montage :
sudo mkdir -p /mnt/raid1
Ajouter la configuration du RAID dans
/etc/mdadm/mdadm.conf:sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
Ajouter le montage automatique dans
/etc/fstab:/dev/md0 /mnt/raid1 ext4 defaults 0 2
Le premier zéro : si égal à 1, l’OS will use DUMP utility to make backups of the file system. If set to 0, no backups will be made.
Le second zéro disables fsck utility on the selected volume during reboots. In this field 0, 1 or 2 can be set. 1 should be specified for the root file system, and 2 for other file systems.
Enlever une grappe
désactiver la grappe :
$ sudo mdadm --stop /dev/md0
puis, effacer les superbloc de chaque disque :
sudo mdadm --zero-superblock /dev/sda sudo mdadm --zero-superblock /dev/sdb
Puis enlever la grappe depuis mdadm:
sudo mdadm --remove /dev/md0
Puis, on vérifie :
sudo mdadm --detail /dev/md0
/dev/md0: Version : 1.2 Creation Time : Thu Dec 15 14:55:34 2016 Raid Level : raid1 Array Size : 1047552 (1023.17 MiB 1072.69 MB) Used Dev Size : 1047552 (1023.17 MiB 1072.69 MB) Raid Devices : 2 Total Devices : 1 Persistence : Superblock is persistent Update Time : Mon Dec 19 17:19:31 2016 State : clean, degraded Active Devices : 1 Working Devices : 1 Failed Devices : 0 Spare Devices : 0 Name : LinuxMint18:1 (local to host LinuxMint18) UUID : b16a3861:********:3abd06ba:7346e91d Events : 63 Number Major Minor RaidDevice State 0 8 48 0 active sync /dev/sdd 2 0 0 2 removed
On peut retirer le disque physique.
Pour vérifier si un disque est défaillant :
sudo mdadm /dev/md127 --fail /dev/sde
Pour enlever un disque :
$ sudo mdadm /dev/md127 --remove /dev/sde
ajouter un disque dans une grappe
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 19G 0 part / ├─sda2 8:2 0 1K 0 part └─sda5 8:5 0 1022M 0 part [SWAP] sdb 8:16 0 8G 0 disk └─md126 9:126 0 8G 0 raid1 /mnt/raiddisk1 sdc 8:32 0 8G 0 disk └─md126 9:126 0 8G 0 raid1 /mnt/raiddisk1 sdd 8:48 0 1G 0 disk └─md127 9:127 0 1023M 0 raid1 /mnt/raiddisk2 sde 8:80 0 1G 0 disk
To add this new hard drive to the array:
$ sudo mdadm /dev/md127 --add /dev/sde
The previous command adds the new sde hard disk to the md127 array:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 19G 0 part / ├─sda2 8:2 0 1K 0 part └─sda5 8:5 0 1022M 0 part [SWAP] sdb 8:16 0 8G 0 disk └─md126 9:126 0 8G 0 raid1 /mnt/raiddisk1 sdc 8:32 0 8G 0 disk └─md126 9:126 0 8G 0 raid1 /mnt/raiddisk1 sdd 8:48 0 1G 0 disk └─md127 9:127 0 1023M 0 raid1 /mnt/raiddisk2 sde 8:64 0 1G 0 disk └─md127 9:127 0 1023M 0 raid1 /mnt/raiddisk2
— — —
Setting up Raid 1 sur Linux Mint XFCE :
Effacer les données sur les disques
sudo dd if=/dev/zero of=/dev/sda bs=1048576
sudo dd if=/dev/zero of=/dev/sdb bs=1048576
the DD command will clean the hard drives off of anything.
cfdisk /dev/sda
Create a new 500 MB partition or 1 gig partition at the beginning
Move the selection bar into the Free Space
Create a new partition with the remaining space
Change the type of this partition to FD.
Write the changes
Quit cfdisk
cfdisk /dev/sdb
Create a new 500 MB partition or 1 gig at the beginning
Move the selection bar into the Free Space
Create a new partition with the remaining space
Change the type of this partition to FD.
Write the changes
Quit cfdisk
cfdisk -P s /dev/sda
To get last sector #
mdadm --create /dev/md0 --level=raid1 --raid-devices=2 /dev/sda2 /dev/sdb2
mkfs.ext3 /dev/md0
ln /dev/md0 /dev/sde
mkfs.ext3 /dev/sda1
mkfs.ext3 /dev/sdb1
That command will copy the boot partition over to the sdb drive so if sda goes down, the system will still start up.
Install Debian based Linux
Start the installer, it has an icon on the desktop. When you get to the ‘Allocate drive space’ dialog, choose the ‘Specify partitions manually’ option. Click the /dev/sda1 partition, choose ‘Change…’ and fill out the following options:
Use as: Ext3 journaling file system Format the partition: No (do not check the checkmark) Mount point: /boot
Click the /dev/md0 partition, choose ‘Change’, and fill it out like this:
Use as: Ext3 journaling file system Format the partition: No (do not check the checkmark Mount point: /
There’s also a dropdown for ‘Device for boot loader installation’. Make sure that /dev/sda is selected there. Click the ‘Install Now’ button, and ‘Continue’ on any confirmation dialogs you might get. Fill out the rest of the install questions and sit back while the OS installs itself.
When the installer is done, do*not*reboot the system yet (choose ‘Continue testing’). Go back to your terminal screen and prepare the boot partition:
mkdir /raid
mount /dev/md0 /raid
mount /dev/sda1 /raid/boot
mount --bind /dev /raid/dev
mount -t devpts devpts /raid/dev/pts
mount -t proc proc /raid/proc
mount -t sysfs sysfs /raid/sys
mount -o bind /etc/resolv.conf /raid/etc/resolv.conf
chroot /raid
apt-get install mdadm
nano /etc/mdadm/mdadm.conf and remove the / from between md and the 0
hit control X and save the file
then type mdadm --assemble /dev/md0
puis taper exit:
puis copier the boot partition over to the sdb drive so if sda goes down, the system will still start up.
dd if=/dev/sda of=/dev/sdb count=(last sector # here)
Reboot and it should boot up to the OS with no problem
Checking the RAID
A useful command that will tell you the status of the RAID is*cat /proc/mdstat
It’s output is something like:
md0 : active raid1 sda2[0] sdb2[1] 62468672 blocks [2/2] [UU]
The UU means both RAID1 components are ‘Up’. If one disappears, it’s ‘U’ will change to and underscore (‘_’).
Most of the info was taken from
http://www.michielovertoom.com/linux/ubuntu-software-raid/
With updates/modifications from me (like size of boot partition)
I got this working in a VM setting after toying with it for 2 days and doing loads of research. Figured it might help someone. Even if it’s just to learn how.
PS: Just got this working on a dell optiplex 330 with 2 500 gig hard drives and everything works with linux mint 17 xfce