sábado, 14 de noviembre de 2009

Centos 5.x: Creacion de un arreglo Raid-1

Tenemos nuestro sistema trabajando, el tutorial de Centos en su wiki habla sobre hacerlo sobre un sistema arrancado desde el CD en modo de reparacion, pero si oo hago no podre mostrarles la informacion que vaya saliendo segun avance.

Asi que prefiero hacerlo con el sistema en operacion, ya cuando lo hayan perfeccionado podran hacerlo lo otro que es mas seguro, aunque he hecho esto varias veces y nunca he tenido problemas, ademas que siempre tengo respaldo de mis sistemas.

Vamos empezando, tenemos un sistema con LVM sobre el 1er disco IDE de nombre:

dmesg | grep dha
device-mapper: ioctl: 4.11.5-ioctl (2007-12-12) initialised: dm-devel@redhat.com
[root@]# dmesg | grep hda
ide0: BM-DMA at 0x08b0-0x08b7, BIOS settings: hda:DMA, hdb:pio
hda: WDC WD1600SB-01RFA0, ATA DISK drive
hda: max request size: 512KiB
hda: 321672960 sectors (164696 MB) w/8192KiB Cache, CHS=20023/255/63, UDMA(100)
hda: cache flushes supported
hda: hda1 hda2
EXT3 FS on hda1, internal journal


Sobre un sistema LVM con esta informacion:

# lvm pvdisplay
--- Physical volume ---
PV Name /dev/hda2
VG Name VolGroup00
PV Size 153.28 GB / not usable 3.21 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 4905
Free PE 0
Allocated PE 4905
PV UUID xPGYzM-vzei-2mEO-QxkB-NR34-UaLS-nuSv8j


Su parte logica es:

root@ lvm lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID 6kY4pz-N7da-44Oi-7s2C-jWNR-GR7C-tAjHpc
LV Write Access read/write
LV Status available
# open 1
LV Size 152.28 GB
Current LE 4873
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID R9WgZa-QTUx-knYp-bU7f-gf3t-2BSJ-hh9dzm
LV Write Access read/write
LV Status available
# open 1
LV Size 1.00 GB
Current LE 32
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1


Esta particionado de la siguiente manera:

fdisk -l /dev/hda
Disk /dev/hda: 164.6 GB, 164696555520 bytes
255 heads, 63 sectors/track, 20023 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 20023 160730325 8e Linux LVM

Creo que es todo lo que necesitamos saber, vamos ahoar a ver el disco 2 IDE de nonbre como sabran hdc ya que esta en el 2do canal IDE, nunca pongan un RAID-1 sobre el mismo bus o cable IDE, se pueden meter en problemas, ya que el bus se puede saturar, ya que recuerden que cuando se guarda info a los discos se hace a los 2 y el bus tiene que mandar la misma info a los discos, si tienen mucho uso del disco como una base de datos o un samba solo analicen a situacion.

Bien el 2do disco es del mismo tamano, no puede ser menor a el disco que se quiere respaldar:

root@ dmesg | grep hdc
ide1: BM-DMA at 0x08b8-0x08bf, BIOS settings: hdc:DMA, hdd:DMA
hdc: WDC WD1600SB-01RFA0, ATA DISK drive
hdc: max request size: 512KiB
hdc: 321672960 sectors (164696 MB) w/8192KiB Cache, CHS=20023/255/63, UDMA(100)
hdc: cache flushes supported
hdc: hdc1 hdc2

Identico a el 1ro.

fdisk -l /dev/hdc

Disk /dev/hdc: 164.6 GB, 164696555520 bytes
255 heads, 63 sectors/track, 20023 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 1 13 104391 fd Linux raid autodetect
/dev/hdc2 14 9729 78043770 fd Linux raid autodetect

Miren este disco ya fue usado en un arreglo anteriormente, no importa vamos a eliminarlo todo su info para empezar de 0.

Si checo mi comando mount solo para ver que no se esta usando:

# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw,noatime)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

Correcto, nada relacionado a ese disco aparece.

Vamos empezando a eliminar las particiones:

fdisk /dev/hdc

The number of cylinders for this disk is set to 20023.
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: 164.6 GB, 164696555520 bytes
255 heads, 63 sectors/track, 20023 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 1 13 104391 fd Linux raid autodetect
/dev/hdc2 14 9729 78043770 fd Linux raid autodetect

Command (m for help): d
Partition number (1-4): 2

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/hdc: 164.6 GB, 164696555520 bytes
255 heads, 63 sectors/track, 20023 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Command (m for help):

Aqui ya no tenemos nada, solo guardamos lo hecho para que se apliquen los cambios, aun no se han llevado a el disco.

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

Calling ioctl() to re-read partition table.
Syncing disks.

root@

Listo no regreso a el shell. Vamos ahora a crear las particiones como si el disco fuera de paquete, ariba ya vimos que el disco debe quedar particionado como el 1ro, o sea asi:

fdisk -l /dev/hda

Disk /dev/hda: 164.6 GB, 164696555520 bytes
255 heads, 63 sectors/track, 20023 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 20023 160730325 8e Linux LVM

Bien, asi que empezamos:

root@ fdisk /dev/hdc

The number of cylinders for this disk is set to 20023.
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-20023, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-20023, default 20023): 13

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

Command (m for help): p

Disk /dev/hdc: 164.6 GB, 164696555520 bytes
255 heads, 63 sectors/track, 20023 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 1 13 104391 83 Linux
/dev/hdc2 14 20023 160730325 83 Linux

Command (m for help):


Aqui ya tenemos el disco igual que el 1ro, ahora sigue cambiar las particiones por tipo Raid asi:

Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/hdc: 164.6 GB, 164696555520 bytes
255 heads, 63 sectors/track, 20023 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 1 13 104391 fd Linux raid autodetect
/dev/hdc2 14 20023 160730325 fd Linux raid autodetect

Command (m for help):

Ya podemos ver que estan identicas, asi que guardamos los cambios:

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

Calling ioctl() to re-read partition table.
Syncing disks.

Listo ya tenemos nuestro disco para seguir la operacion, ahora lo que sigue es cargar ciertos modulos ya que que cuando generemos el nuevo initrd los va a necesitar a fuercitas si no cuando reiniciemos el equipo no podra cargar los modulos referente a el RAID.

Vamos a ver necesitamos todos estos para no andar buscando cuales si cuales no vamos cargandolos:

root# modprobe linear
root# modprobe multipath
root# modprobe raid0
root# modprobe raid1
root# modprobe raid5

El md ya lo tenia cargado. Si ejecutamos el siguiente comando nos debera sacar una informacion parecida a esta:

root# cat /proc/mdstat
Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4]
unused devices:

Ahi podran ver que si cargo los modulos anteriores. Vamos solo a tener 2 particiones ya que nuestro disco que deseamos respaldar tiene solo 2. Estas van a ser y tiene esta relacion:

md0 ----> /dev/hdc1 === /dev/hda1
md1 ----> /dev/hdc2 === /dev/hda2

Vamos a verficar que el disco hdc no tenga ninguna informacion sobre algun raid,
solo para cerciorarnos:

root@# mdadm --zero-superblock /dev/hdc1
mdadm: Unrecognised md component device - /dev/hdc1
root@ mdadm --zero-superblock /dev/hdc2
mdadm: Unrecognised md component device - /dev/hdc2

Nos debe sacar esta informacion. Sino saca nada, es que si tenia info de arreglos anteriores, pero si lo vuelven a ejecutar les debera la informacion anterior.

Creando las particiones:

root@ mdadm --create /dev/md0 --level=1 --raid-devices=2 missing /dev/hdc1
mdadm: /dev/hdc1 appears to contain an ext2fs file system
size=104320K mtime=Sun Oct 25 22:33:00 2009
Continue creating array? y
mdadm: array /dev/md0 started.
root@ mdadm --create /dev/md1 --level=1 --raid-devices=2 missing /dev/hdc2
mdadm: array /dev/md1 started.

Ya hemos creado las 2 particiones tipo raid-1, este mensaje:

mdadm: /dev/hdc1 appears to contain an ext2fs file system

Me lo saco por que este disco anteriormente lo use en un sistema linux y tenia formato ext3, pero no hay problema es solo informativo, de todos modos vamos a tener que darle formato de nuevo. Ahora vean el siguiente formato:

root@ cat /proc/mdstat
Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4]
md1 : active raid1 hdc2[1]
160730240 blocks [2/1] [_U]

md0 : active raid1 hdc1[1]
104320 blocks [2/1] [_U]

unused devices:
root@

Ya nos aparecen un raid-1 pero le falta un disco:

160730240 blocks [2/1] [_U]

Es normal, es el disco que deseamos respaldar el que le falta para ser un raid-1 completo.

Ahora lo que sigue es formatear el disco, empezando por la particion /dev/md0 por que es donde va el boot. la 2da(md1) va a ser tipo LVM.

# mkfs.ext3 -L "/boot" /dev/md0

mke2fs 1.39 (29-May-2006)
Filesystem label=/boot
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
26104 inodes, 104320 blocks
5216 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

Como mencione la 2da particion va a tener un tipo LVM asi que primero la creamos y luego formateamos.

Empezamos por crear la particion fisica:

lvm pvcreate /dev/md1
Physical volume "/dev/md1" successfully created

Ahora sigue crear el grupo:

lvm vgcreate RaidSys /dev/md1
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
Attempt to close device '/dev/cdrom' which is not open.
Volume group "RaidSys" successfully created

No me interesa el mensaje del cd-rom.

Algo interesando es que si lees hacerca del PE de los LVM te dicen que por default si valor es de 4MB, pero Centos cuando los instalas el usa el valor de 32MB, chequen el disco 1:

lvm pvdisplay
--- Physical volume ---
PV Name /dev/hda2
VG Name VolGroup00
PV Size 153.28 GB / not usable 3.21 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 4905
Free PE 0
Allocated PE 4905
PV UUID xPGYzM-vzei-2mEO-QxkB-NR34-UaLS-nuSv8j


Vean

PE Size (KByte) 32768

Bueno asi que cuando vayamos a crear el grupo vamos especificar este valor para que sea igual que el disco 1, para ello se usa el parametro "-s", vamos haciendolo:

lvm vgcreate -s 32MB RaidSys /dev/md1
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
Attempt to close device '/dev/cdrom' which is not open.
Volume group "RaidSys" successfully created

Verificamos lo hecho:

root@ lvm pvdisplay
--- Physical volume ---
PV Name /dev/hda2
VG Name VolGroup00
PV Size 153.28 GB / not usable 3.21 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 4905
Free PE 0
Allocated PE 4905
PV UUID xPGYzM-vzei-2mEO-QxkB-NR34-UaLS-nuSv8j

--- Physical volume ---
PV Name /dev/md1
VG Name RaidSys
PV Size 153.28 GB / not usable 3.12 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 4905
Free PE 4905
Allocated PE 0
PV UUID B5wfIK-MUOh-xr1Q-1s3P-FgGs-PQRd-2MZZ0L

Vean el mismo valor del PE, listo. Dentro de este Volumen de grupo vamos a crear nuestras 2 particiones logicas que seran / y swap.

Vamos empezando por el swap de 1G

lvm lvcreate --size 1GB --name swap RaidSys
Logical volume "swap" created

Listo, sigue crear el root:

lvm lvcreate --size 152.28GB --name Root RaidSys
Rounding up size to full physical extent 152.28 GB
Logical volume "Root" created

Nos dice ese mensaje por que casi usamos todo lo permitido, verificamos lo hecho:

# lvm lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID 6kY4pz-N7da-44Oi-7s2C-jWNR-GR7C-tAjHpc
LV Write Access read/write
LV Status available
# open 1
LV Size 152.28 GB
Current LE 4873
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID R9WgZa-QTUx-knYp-bU7f-gf3t-2BSJ-hh9dzm
LV Write Access read/write
LV Status available
# open 1
LV Size 1.00 GB
Current LE 32
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

--- Logical volume ---
LV Name /dev/RaidSys/swap
VG Name RaidSys
LV UUID 1ATXgH-l3KP-eJCX-YKSc-XDfV-QhU8-wQcGi1
LV Write Access read/write
LV Status available
# open 0
LV Size 1.00 GB
Current LE 32
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2

--- Logical volume ---
LV Name /dev/RaidSys/Root
VG Name RaidSys
LV UUID Sg0lp7-xZNs-vH39-f4Wn-oYR0-S7hz-l0DFFq
LV Write Access read/write
LV Status available
# open 0
LV Size 152.28 GB
Current LE 4873
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3

Ahi esta igualito que el disco 1. Ahora si como ya tenemos nuestras 2 particiones vamos a necesitar darles el sistema de archivos a cada una, empezamo por el swap:

mkswap /dev/RaidSys/swap
Setting up swapspace version 1, size = 1073737 kB

Ahor vamos por el root:

mkfs.ext3 -L "/" /dev/RaidSys/Root
mke2fs 1.39 (29-May-2006)
Filesystem label=/
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
19972096 inodes, 39919616 blocks
1995980 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
1219 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

Ahor lo que sigue
es copear la informacion del disco 1 a l disco 2 con arreglo, para ello necesitamos montar las particiones del arreglo para hacer esto, vamos creando las entradas en mnt:

mkdir /mnt/root
mkdir /mnt/boot

mount /dev/RaidSy/Root /mnt/root
mount/dev/md0 /mnt/boot

Necesitamos hacerle unos ajustes a nuestro ramdisk:

mv /boot/initrd-`uname -r`.img /boot/initrd-`uname -r`.img.ori
[root@mbx-pervasive ~]# mkinitrd /boot/initrd-`uname -r`.img `uname -r`

Ahora copeamos la informacion a cada particion:

rsync -avHX /boot/* /mnt/boot/
cp -dpRx / /mnt/root/

Para lo referente a selinux:

touch /mnt/root/.autorelabel

Ya tenemos nuestras particiones nuevas con los datos, ahora seguimos con grub:

grub> root (hd1)
Filesystem type unknown, using whole disk

grub> root (hd1,0)
Filesystem type is ext2fs, partition type 0xfd

grub> setup (hd1)
Checking if "/boot/grub/stage1" exists... no
Checking if "/grub/stage1" exists... yes
Checking if "/grub/stage2" exists... yes
Checking if "/grub/e2fs_stage1_5" exists... yes
Running "embed /grub/e2fs_stage1_5 (hd1)"... 15 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd1) (hd1)1+15 p (hd1,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.
quit

Listo ya tenemos nuestro 2do disco con lo necesario para botear, seguimos con editar lo archivos importantes de arranque como grub, mi grub original es este:

#boot=/dev/hda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-164.6.1.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.6.1.el5 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.18-164.6.1.el5.img
title CentOS (2.6.18-164.2.1.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.2.1.el5 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.18-164.2.1.el5.img

Como ya tenemos la info en el arreglo vamos a editar todos los archvos de ahi mismo, asi que abrimos:

vim /mnt/boot/grub/menu.lst

#boot=/dev/hda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS Raid-1 (2.6.18-164.6.1.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.6.1.el5 ro root=/dev/RaidSys/Root
initrd /initrd-2.6.18-164.6.1.el5.img
title CentOS (2.6.18-164.2.1.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.2.1.el5 ro root=/dev/RaidSys/Root
initrd /initrd-2.6.18-164.2.1.el5.img

Solo necesitamos cambiar la ruta de "/" por la nueva y salvamos.

Seguimos por el sistema de archivos"fstab", el original esta asi:

/dev/VolGroup00/LogVol00 / ext3 defaults,noatime 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0

Abrimos /mnt/root/etc/fstab y va a quedar asi:

/dev/RaidSys/Root / ext3 defaults,noatime 1 1
LABEL=/dev/md0 /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/RaidSys/swap swap swap defaults 0 0

Salvamos y salimos.

Por ultimo ya solo nos falta crear el archivo mdadm.conf asi:

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

Listo ya solo desmontamos nuestras particiones nuevas, apagamos el equipo, cambiamos el 2do disco a la pocision del 1ro y retiramos el 1ro por el momento, prendemos el equipo y debera arrancar del nuevo disco creado.

2 comentarios:

Unknown dijo...

Buen Dia

Interesante tu articulo amigo, ando buscando ayuda sobre /dev/md1 ya que lo tengo al 100% y me interesa aumentar el tamaño en un disco de 1TB SATA.

No se si usted sepa como realizarlo y si me pueda proporcionar un correo para entrar en contacto.

Saludos Cordiales
ivan.jl84@hotmail.com

Pedro Moreno dijo...

Si tu particion es lvm es cosa de agregar los discos extras, configurarlos e incrementar tus particiones lvm, por lo regular donde hago esto es en un servidor de correos, cada cierto tiempo tenemos que incrementar espacios, perikillo arroba gmail punto com.