Mettre un raid soft en place sur un système déjà installé

Rédigé par SRay Aucun commentaire
Classé dans : Linux Mots clés : Linux, raid, sfdisk, mdadm

Comment activer un raid logiciel, sans avoir accès à la machine :)

Copier les partitions

sfdisk -d /dev/sda | sfdisk /dev/sdb

 

fdisk -l

Disk /dev/sda: 73.2 GB, 73200476160 bytes

255 heads, 63 sectors/track, 8899 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1               2          25      192780   fd  Linux

/dev/sda2              26         279     2040255   fd  Linux swap / Solaris

/dev/sda3   *         280        8899    69240150   fd  Linux

Disk /dev/sdb: 73.2 GB, 73200476160 bytes

255 heads, 63 sectors/track, 8899 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               2          25      192780   fd  Linux

/dev/sdb2              26         279     2040255   fd  Linux swap / Solaris

/dev/sdb3   *         280        8899    69240150   fd  Linux


Modifier le type des partitions

fdisk /dev/sdb

Command (m for help): t

Partition number (1-4): 1

Hex code (type L to list codes): fd

Command (m for help): t

Partition number (1-4): 2

Hex code (type L to list codes): fd

Command (m for help): t

Partition number (1-4): 3

Hex code (type L to list codes): fd

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

On doit obtenir :

fdisk -l /dev/sdb

Disk /dev/sdb: 73.2 GB, 73200476160 bytes

255 heads, 63 sectors/track, 8899 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               2          25      192780   fd  Linux raid autodetect

/dev/sdb2              26         279     2040255   fd  Linux raid autodetect

/dev/sdb3   *         280        8899    69240150   fd  Linux raid autodetect

 

Création des volumes RAID1

On crée les RAID1 sans /dev/sda :

mdadm --create /dev/md0 --level=1 --raid-disks=2 missing /dev/sdb1

mdadm --create /dev/md1 --level=1 --raid-disks=2 missing /dev/sdb2

mdadm --create /dev/md2 --level=1 --raid-disks=2 missing /dev/sdb3

Si les /dev/md* n'existe pas :

mknod -m 640 /dev/md0 b 9 0

mknod -m 640 /dev/md1 b 9 1

mknod -m 640 /dev/md2 b 9 2

La commande 'cat /proc/mdstat' doit nous donner 3 RAID dégradé :

cat /proc/mdstat

Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10]

md2 : active raid1 sdb3[1]

      4594496 blocks [2/1] [_U]

md1 : active raid1 sdb2[1]

      497920 blocks [2/1] [_U]

md0 : active raid1 sdb1[1]

      144448 blocks [2/1] [_U]

unused devices: <none>

 

Formater les volumes RAID

mke2fs -j /dev/md0

mkswap /dev/md1

mke2fs -j /dev/md2


Modification des fichiers système

/etc/mdadm.conf

cp /usr/share/doc/mdadm-2.5.4/mdadm.conf-example /etc/mdadm.conf

mdadm --examine --scan >> /etc/mdadm.conf

Il doit maintenant y avoir à la fin du fichier les infos concernant les volumes RAID :

ARRAY /dev/md0 level=raid1 num-devices=2 UUID=72d23d35:35d103e3:01b5209e:be9ff10a

ARRAY /dev/md1 level=raid1 num-devices=2 UUID=a50c4299:9e19f9e4:01b5209e:be9ff10a

ARRAY /dev/md2 level=raid1 num-devices=2 UUID=99fee3a5:ae381162:01b5209e:be9ff10a

/etc/fstab & /etc/mtab
On replace les /dev/sda* par les /dev/md* correspondant :

/dev/md2                /                       ext3    defaults        1 1

/dev/md0                /boot                   ext3    defaults        1 2

/dev/md1                swap                    swap    defaults        0 0

none                    /dev/pts                devpts  gid=5,mode=620  0 0

none                    /proc                   proc    defaults        0 0

none                    /dev/shm                tmpfs   defaults        0 0

 

/dev/md2 / ext3 rw 0 0

none /proc proc rw 0 0

none /dev/pts devpts rw,gid=5,mode=620 0 0

/dev/md0 /boot ext3 rw 0 0

none /dev/shm tmpfs rw 0 0

none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0

/boot/grub/grub.conf

default=0

fallback=1

timeout=5

hiddenmenu

title CentOS (Default)

        root (hd1,0)

        kernel /vmlinuz ro root=/dev/md2

        initrd /initrd-raid1

title CentOS (Default)

        root (hd0,0)

        kernel /vmlinuz ro root=/dev/sda3

La ligne 'initrd /initrd-raid1' est nécessaire si /dev/md2 n'est pas trouvé au démarrage. Si besoin du initrd, il faut le générer :

uname -a

Linux mamachine.lan2wan.fr 2.6.18-prep #1 SMP Tue Mar 4 15:02:47 CET 2008 x86_64 x86_64 x86_64 GNU/Linux

cd /boot

mkinitrd --with=raid1 initrd-raid1 2.6.18-prep

 

Copie du système

mkdir /mnt/md0

mkdir /mnt/md2

mount /dev/md0 /mnt/md0

mount /dev/md2 /mnt/md2

cp -dpRx / /mnt/md2/

cd /boot

cp -dpRx . /mnt/md0/

 

Mise à jour du chargeur de démarrage (GRUB)

grub

  root (hd0,0)

  setup (hd0)

  root (hd1,0)

  setup (hd1)

  quit

Ensuite on reboot.

 

Modification des partitions de /dev/sda

fdisk /dev/sda

Command (m for help): t

Partition number (1-4): 1

Hex code (type L to list codes): fd

Command (m for help): t

Partition number (1-4): 2

Hex code (type L to list codes): fd

Command (m for help): t

Partition number (1-4): 3

Hex code (type L to list codes): fd

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

 

fdisk -l /dev/sda

[...]

/dev/sda1               2          25      192780   fd  Linux raid autodetect

/dev/sda2              26         279     2040255   fd  Linux raid autodetect

/dev/sda3   *         280        8899    69240150   fd  Linux raid autodetect

 

Ajout des disques dans les RAIDs

mdadm --add /dev/md0 /dev/sda1

mdadm --add /dev/md1 /dev/sda2

mdadm --add /dev/md2 /dev/sda3

Si une erreur se produit (ex: /dev/sda3 ressource busy)
Modifier /boot/grub/grub.conf, remplacer hd1 par hd0

title CentOS (Default)

        root (hd0,0)

        kernel /vmlinuz ro root=/dev/md2

        initrd /initrd-raid1

Rebooter.
'fuser -mv /dev/sda3' ne doit plus rien renvoyer.
Ensuite relancer 'mdadm –add /dev/md2 /dev/sda3'
Les RAIDs vont se reconstruire :

cat /proc/mdstat

Personalities : [raid1]

md2 : active raid1 sda3[2] sdb3[1]

      4594496 blocks [2/1] [_U]

      [=====>...............]  recovery = 29.7% (1367040/4594496) finish=0.6min speed=85440K/sec

 

md1 : active raid1 sda2[0] sdb2[1]

      497920 blocks [2/2] [UU]

 

md0 : active raid1 sda1[0] sdb1[1]

      144448 blocks [2/2] [UU]

 

unused devices: <none>

 

Dernière modification GRUB

Modifier le '/boot/grub/grub.conf'
Permettra de démarrer si le premier disque est cassé :

default=0

fallback=1

timeout=5

hiddenmenu

title CentOS (Default)

        root (hd0,0)

        kernel /vmlinuz ro root=/dev/md2

        initrd /initrd-raid1

title CentOS (Default)

        root (hd1,0)

        kernel /vmlinuz ro root=/dev/md2

        initrd /initrd-raid1

Normalement pas besoin, mais juste pour être sûr que grub est bien installé sur les 2 disques :

grub

  root (hd0,0)

  setup (hd0)

  root (hd1,0)

  setup (hd1)

  quit

Si lors de cette étape, une erreur du type 'Checking if “/boot/grub/stage1” exists… no' se produit, il faut réinstaller grub dans la partition '/boot' d'un des disques en RAID :

grub-install /dev/hdX

Ou 'hdX' est votre disque (à remplacer par hda voir sda).

Les commentaires sont fermés.