Creación de RAID 1 en Linux
Como crear un RAID 1 en Linux (Red Hat y SLES)
Habiendo introducido los tipos de RAID , vamos a cerrar el tema con la creacion de uno .
Vamos a crear un SW RAID 1 en Red Hat. En SUSE el proceso seria el mismo pero recomiendo user el YaSt.
#Tener en cuenta que las particiones/discos deben tener el mismo tamaño!
Tenemos 2 disco /dev/sda y /dev/sdb ambos discos de 40Gigas. Ambos formaran el RAID 1 /dev/md0
1)Deberan user el fdisk para particionar /dev/sdb y crear /dev/sdb1
#fdisk /dev/sdb
Las opciones que usaran son :
a)n #Para nueva particion
b)P #Particion primeria
c)Dejamos el default para que use todo el disco
d)t # Para poner el tipo de particion q sera
e)fd #Para indicar que sera una particion de RAID
g)w #Para guardar al tabla de particiones
Ex:
DA1:~ # fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklab el
Building a new DOS disklabel with disk identifier 0x9083f83c.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
The number of cylinders for this disk is set to 1305.
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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):
Using default value 1305
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x9083f83c
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
DA1:~ #
#Nos quedara algo asi
DA1:~ # fdisk -l /dev/sdb
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x9083f83c
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 fd Linux raid autodetect
#Quiza tengamos que ejecutar el comando "partprobe" para que el kernel relea toda las tablas de particiones de los discos del server y actualize.
3)Clonaremos la table de particion al otro disco para que queden identicos
sfdisk -d /dev/sdb >/dev/sda
DA1:~ # sfdisk -d /dev/sdb >/dev/sda
Checking that no-one is using this disk right now ...
OK
Disk /dev/sda: 1305 cylinders, 255 heads, 63 sectors/track
sfdisk: ERROR: sector 0 does not have an msdos signature
/dev/sda: unrecognized partition table type
Old situation:
No partitions found
New situation:
Units = sectors of 512 bytes, counting from 0
Device Boot Start End #sectors Id System
/dev/sda1 63 20964824 20964762 fd Linux raid autodetect
/dev/sda2 0 - 0 0 Empty
/dev/sda3 0 - 0 0 Empty
/dev/sda4 0 - 0 0 Empty
Warning: no primary partition is marked bootable (active)
This does not matter for LILO, but the DOS MBR will not boot this disk.
Successfully wrote the new partition table
Re-reading the partition table ...
4)Veremos que /dev/sda esta igual
DA1:~ # fdisk -l /dev/sda
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sda1 1 1305 10482381 fd Linux raid autodetect
5)Hora de crear el RAID
# mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
mdadm: array /dev/md/0 started.
6) Podemos ver en tiempo real como se crea
DA1:~ # watch cat /proc/mdstat
Every 2.0s: cat /proc/mdstat Sat Aug 18 12:40:56 2012
Personalities : [raid1]
md0 : active raid1 sdb1[1] sdb1[0]
5229056 blocks [2/2] [UU]
[===================>.] resync = 98.1% (5131520/5229056) finish=0.0min speed=160360K/sec
unused devices: <none>
7)Terminado el proceso el fdisk mostrara esto:
Disk /dev/md0: 5354 MB, 5354553344 bytes
2 heads, 4 sectors/track, 1307264 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Disk identifier: 0x00000000
Disk /dev/md0 doesn't contain a valid partition table
8)El RAID debera ser tratado como cualquier disco normal . Podemos user LVM , etc...
9)Podemos verificar su estado asi:
DA1:~ # mdadm --query --detail /dev/md0
/dev/md0:
Version : 0.90
Creation Time : Sat Aug 18 12:40:23 2012
Raid Level : raid1
Array Size : 5229056 (4.99 GiB 5.35 GB)
Used Dev Size : 5229056 (4.99 GiB 5.35 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Sat Aug 18 12:40:57 2012
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
UUID : 2e7da95c:003edb89:513b4353:6ad4b630 (local to host DA1)
Events : 0.4
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 18 1 active sync /dev/sda1
10) Creamos el archivos de configuracion estatico
mdadm --detail --scan > /etc/mdadm.conf
11)Si quisieramos eliminarlo hay q hacer lo siguiente
A1:~ # man mdadm.conf
DA1:~ # mdadm --stop /dev/md0
mdadm: stopped /dev/md0
DA1:~ # mdadm --remove /dev/md0
#Si ejecutamos el fdisk veremos que no existe mas
12)Si quisieramos reemplazar un disco fallido del RIAD.
#mdadm /dev/md0 --fail /dev/sda1 --remove /dev/sda1 #Remueve
#mdadm --add /dev/md0 /dev/sda1 #Reemplazamos . Recordar que deberemos copiar la tabla de pariciones #sfdisk -d /dev/sdb >/dev/sda
#Siempre despues de cualquier modificacion ejecutar:
mdadm --detail --scan > /etc/mdadm.conf