Installation d'une debian avec raid1 software et lvm

Installation d'une distribution debian sur le premier des deux disques

Tout d'abord installé de manière traditionnelle la distribution Debian GNU/Linux sur l'un des deux disques.

Préparation du deuxième disque en mode md + lvm



Création d'une partition root (hdc1)

256Mo me parrait une valeur amplement suffisante :

obelix:/boot# fdisk /dev/hdc
       
The number of cylinders for this disk is set to 79656.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
          e   extended
          p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-79656, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-79656, default 79656): +128M
       
Command (m for help): w
The partition table has been altered!
       
Calling ioctl() to re-read partition table.
Syncing disks.
obelix:/boot#
Création de la partition qui intégrera notre groupe raid (hdc2)

Attention s'assurer que vous pourrez créer une partition sur notre disque 1 faisant exactement la même taille. Ensuite créer cette partition de manière traditionnel avec fdisk par exemple.

obelix:/boot# fdisk /dev/hdc

The number of cylinders for this disk is set to 79656.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
          
Command (m for help): p
          
Disk /dev/hdc: 41.1 GB, 41110142976 bytes
16 heads, 63 sectors/track, 79656 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
  
Device Boot      Start         End      Blocks   Id  System
/dev/hdc1               1         249      125464+  83  Linux

Command (m for help): n
Command action
          e   extended
          p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (250-79656, default 250):
Using default value 250
Last cylinder or +size or +sizeM or +sizeK (250-79656, default 79656):
Using default value 79656

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
obelix:/boot#
Mise en place du groupe raid à l'aide de mdadm

Nous allons commencer par créer un group raid dégradé avec seulement un disque.

obelix:/boot# mdadm --create /dev/md1 --level 1 --raid-devices=2 /dev/hdc2 missing
mdadm: array /dev/md1 started.
obelix:/boot# cat /proc/mdstat 
Personalities : [raid1] 
md1 : active raid1 hdc2[0]
40021056 blocks [2/1] [U_]
                   
md0 : active raid1 hda1[0] hdf1[1]
156288256 blocks [2/2] [UU]
     
unused devices: <none>
obelix:/boot#
Mise en place des volumes logiques sur notre disque md1

-> Installer lvm

obelix:~# apt-get install lvm2

-> Créer le volume physique LVM

obelix:~# pvcreate /dev/md1
  Physical volume "/dev/md1" successfully created

-> Créer le volume groupe LVM vg01 et y affecter le disque /dev/md1

obelix:~# vgcreate -A n vg01 /dev/md1
 Volume group "vg01" successfully created

-> Créer les volumes logiques LVM

obelix:/boot# lvcreate -A n -L 200M -n backup vg01
 Logical volume "backup" created
obelix:/boot# lvcreate -A n -L 5G -n usr vg01
 Logical volume "usr" created
obelix:/boot# lvcreate -A n -L 3G -n var vg01
 Logical volume "var" created
obelix:/boot# lvcreate -A n -L 10G -n home vg01
 Logical volume "home" created
obelix:/boot# lvcreate -A n -L 19G -n goinfre vg01
 Logical volume "goinfre" created
obelix:/boot#

-> Informations à propos de vg01 et des volumes logiques

obelix:~# vgdisplay -v vg00

Initialisation de la partition de boot hdc1

Initialisation de la partition de boot hde1

Copie des données depuis hde vers les différents volumes logiques

Rebooter avec une knoppix ou autre live cd

# mkfs.ext3 /dev/md1
# mount /dev/md1 /mnt/new_root
# cd /mnt/new_root
# tar -C / -clspf - . | tar -xlspvf -

Faire la même chose pour :

  • usr (/dev/vg01/usr)
  • var (/dev/vg01/var)

Création du disque hde2 et insertion dans le groupe raid

-> Création de la partition qui doit être exactement de la même dimension que la première

obelix:/mnt# sfdisk -d /dev/hdc | sfdisk /dev/hde
obelix:/mnt#

-> Ajout de la nouvelle partition à l'intérieur du group raid

obelix:/mnt# mdadm -a /dev/md1 /dev/hde2
mdadm: hot added /dev/hde2
obelix:/mnt#

-> La phase de reconstruction démarre

obelix:/mnt# cat /proc/mdstat 
Personalities : [raid1] 
md0 : active raid1 hdf1[2] hda1[0]
      156288256 blocks [2/1] [U_]
      [>....................]  recovery =  0.4% (759040/156288256) finish=44.3min speed=58387K/sec
      
unused devices: <none>
obelix:/mnt#

-> La phase de reconstruction se termine

obelix:/mnt# cat /proc/mdstat 
Personalities : [raid1] 
md0 : active raid1 hdf1[1] hda1[0]
      156288256 blocks [2/2] [UU]
      
unused devices: <none>
obelix:/mnt#

mdadm.conf

Ce fichier permet de définir les différents groupes raid à activer.

Ci-dessous les différents scripts qui permettent d'activer les daemons mdadm et activer le raid :

  • /etc/init.d/mdadm : start the RAID monitor daemon
  • /etc/init.d/mdadm-raid : start any arrays from mdadm.conf
obelix:~# cat /etc/mdadm/mdadm.conf  
DEVICE /dev/hda1 /dev/hdf1
ARRAY /dev/md0 devices=/dev/hda1,/dev/hdf1
obelix:~#

You can also only declare your devices with the field DEVICE and type this command :

obelix:~# mdadm --detail --scan >> /etc/mdadm/mdadm.conf
obelix:~#
obelix:~# cat /etc/mdadm/mdadm.conf
DEVICE /dev/hda1 /dev/hdc1
ARRAY /dev/md0 devices=/dev/hda1,/dev/hdc1
DEVICE /dev/hde* /dev/hdf*
ARRAY /dev/md1 devices=/dev/hde1,/dev/hdf1
ARRAY /dev/md2 devices=/dev/hde2,/dev/hdf2
ARRAY /dev/md3 devices=/dev/hde3,/dev/hdf3
ARRAY /dev/md4 devices=/dev/hde4,/dev/hdf4
obelix:~#