Guía de tecnologías

Crear arreglos RAID y preparar el sistema para RAID1

5 min read Sistemas Actualizado 16 Oct 2025
Configurar RAID1 con mdadm y GRUB
Configurar RAID1 con mdadm y GRUB

4 Crear nuestros arreglos RAID

Ahora crearemos los arreglos RAID /dev/md0, /dev/md1 y /dev/md2. Añadiremos /dev/hdb1 a /dev/md0, /dev/hdb5 a /dev/md1 y /dev/hdb6 a /dev/md2. Las particiones /dev/hda1, /dev/hda5 y /dev/hda6 no pueden añadirse ahora (el sistema está arrancando desde ellas), por lo que usamos el marcador “missing” en los siguientes tres comandos:

mdadm --create /dev/md0 --level=1 --raid-disks=2 missing /dev/hdb1  
mdadm --create /dev/md1 --level=1 --raid-disks=2 missing /dev/hdb5  
mdadm --create /dev/md2 --level=1 --raid-disks=2 missing /dev/hdb6

Nota: “missing” crea el arreglo en modo degradado hasta que se agregue la otra mitad (la partición actualmente en uso).

Verifica el estado con:

cat /proc/mdstat

Deberías ver tres arreglos RAID degradados ([U] o [U] indica que falta un miembro; [UU] indica que el arreglo está OK):

[root@server1 ~]# cat /proc/mdstat  
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]  
md2 : active raid1 hdb6[1]  
      4642688 blocks [2/1] [_U]  
  
md1 : active raid1 hdb5[1]  
      417536 blocks [2/1] [_U]  
  
md0 : active raid1 hdb1[1]  
      176576 blocks [2/1] [_U]  
  
unused devices:   
[root@server1 ~]#

A continuación creamos sistemas de ficheros en los arreglos (ext3 en /dev/md0 y /dev/md2; swap en /dev/md1):

mkfs.ext3 /dev/md0  
mkswap /dev/md1  
mkfs.ext3 /dev/md2

Ahora hay que actualizar /etc/mdadm.conf (todavía no contiene información sobre los nuevos arreglos):

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

Muestra el contenido:

cat /etc/mdadm.conf

En el archivo deberías ver detalles sobre los tres arreglos (aunque estén degradados):

# mdadm configuration file
#
# mdadm will function properly without the use of a configuration file,
# but this file is useful for keeping track of arrays and member disks.
# In general, a mdadm.conf file is created, and updated, after arrays
# are created. This is the opposite behavior of /etc/raidtab which is
# created prior to array construction.
#
#
# the config file takes two types of lines:
#
#       DEVICE lines specify a list of devices of where to look for
#         potential member disks
#
#       ARRAY lines specify information about how to identify arrays so
#         so that they can be activated
#
# You can have more than one device line and use wild cards. The first
# example includes SCSI the first partition of SCSI disks /dev/sdb,
# /dev/sdc, /dev/sdd, /dev/sdj, /dev/sdk, and /dev/sdl. The second
# line looks for array slices on IDE disks.
#
#DEVICE /dev/sd[bcdjkl]1
#DEVICE /dev/hda1 /dev/hdb1
#
# If you mount devfs on /dev, then a suitable way to list all devices is:
#DEVICE /dev/discs/*/*
#
#
#
# ARRAY lines specify an array to assemble and a method of identification.
# Arrays can currently be identified by using a UUID, superblock minor number,
# or a listing of devices.
#
#       super-minor is usually the minor number of the metadevice
#       UUID is the Universally Unique Identifier for the array
# Each can be obtained using
#
#       mdadm -D 
#
#ARRAY /dev/md0 UUID=3aaa0122:29827cfa:5331ad66:ca767371
#ARRAY /dev/md1 super-minor=1
#ARRAY /dev/md2 devices=/dev/hda1,/dev/hdb1
#
# ARRAY lines can also specify a "spare-group" for each array.  mdadm --monitor
# will then move a spare between arrays in a spare-group if one array has a failed
# drive but no spare
#ARRAY /dev/md4 uuid=b23f3c6d:aec43a9f:fd65db85:369432df spare-group=group1
#ARRAY /dev/md5 uuid=19464854:03f71b1b:e0df2edd:246cc977 spare-group=group1
#
# When used in --follow (aka --monitor) mode, mdadm needs a
# mail address and/or a program.  This can be given with "mailaddr"
# and "program" lines to that monitoring can be started using
#    mdadm --follow --scan & echo $! > /var/run/mdadm
# If the lines are not found, mdadm will exit quietly
#MAILADDR [email protected]
#PROGRAM /usr/sbin/handle-mdadm-events
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=6b4f013f:6fe18719:5904a9bd:70e9cee6
ARRAY /dev/md1 level=raid1 num-devices=2 UUID=63194e2e:c656857a:3237a906:0616f49e
ARRAY /dev/md2 level=raid1 num-devices=2 UUID=edec7105:62700dc0:643e9917:176563a7

5 Ajustar el sistema a RAID1

Montamos /dev/md0 y /dev/md2 (no hace falta montar el swap /dev/md1):

mkdir /mnt/md0  
mkdir /mnt/md2
mount /dev/md0 /mnt/md0  
mount /dev/md2 /mnt/md2

Verifica que aparecen en la lista de montajes:

mount

Salida esperada:

[root@server1 ~]# mount  
/dev/hda6 on / type ext3 (rw,relatime)  
none on /proc type proc (rw)  
/dev/hda1 on /boot type ext3 (rw,relatime)  
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)  
/dev/md0 on /mnt/md0 type ext3 (rw)  
/dev/md2 on /mnt/md2 type ext3 (rw)  
[root@server1 ~]#

Edita /etc/fstab: reemplaza /dev/hda1 por /dev/md0, /dev/hda5 por /dev/md1 y /dev/hda6 por /dev/md2. El fichero debería verse así:

vi /etc/fstab
/dev/md2 / ext3 relatime 1 1
/dev/md0 /boot ext3 relatime 1 2
/dev/cdrom /media/cdrom auto umask=0022,users,iocharset=utf8,noauto,ro,exec 0 0
/dev/fd0 /media/floppy auto umask=0022,users,iocharset=utf8,noauto,exec,flush 0 0
none /proc proc defaults 0 0
/dev/md1 swap swap defaults 0 0

A continuación actualiza /etc/mtab (sustituye /dev/hda1 por /dev/md0 y /dev/hda6 por /dev/md2; las líneas /dev/md pueden mantenerse):

vi /etc/mtab
/dev/md2 / ext3 rw,relatime 0 0
none /proc proc rw 0 0
/dev/md0 /boot ext3 rw,relatime 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
/dev/md0 /mnt/md0 ext3 rw 0 0
/dev/md2 /mnt/md2 ext3 rw 0 0

Preparar GRUB para arrancar desde RAID

Edita /boot/grub/menu.lst y añade fallback 1 justo después de default 0:

vi /boot/grub/menu.lst
default 0
fallback 1

Esto configura que, si el primer kernel (0) falla, se intente el fallback (1).

Copia la entrada del kernel existente y pégala como primera entrada, cambiando root=/dev/hda6 por root=/dev/md2 y (hd0,0) por (hd1,0). Si tu stanza contiene resume=/dev/hda5, cámbialo por resume=/dev/md1.

Ejemplo de stanzas modificadas:

[...]
title linux
kernel (hd1,0)/vmlinuz BOOT_IMAGE=linux root=/dev/md2  resume=/dev/md1
initrd (hd1,0)/initrd.img

title linux
kernel (hd0,0)/vmlinuz BOOT_IMAGE=linux root=/dev/hda6  resume=/dev/hda5
initrd (hd0,0)/initrd.img

El archivo completo debería parecerse a:

timeout 10
color black/cyan yellow/cyan
default 0
fallback 1

title linux
kernel (hd1,0)/vmlinuz BOOT_IMAGE=linux root=/dev/md2  resume=/dev/md1
initrd (hd1,0)/initrd.img

title linux
kernel (hd0,0)/vmlinuz BOOT_IMAGE=linux root=/dev/hda6  resume=/dev/hda5
initrd (hd0,0)/initrd.img

title failsafe
kernel (hd0,0)/vmlinuz BOOT_IMAGE=failsafe root=/dev/hda6  failsafe
initrd (hd0,0)/initrd.img

(hd1,0) hace referencia a /dev/hdb, que ya forma parte de los arreglos RAID. Reiniciaremos pronto: el sistema intentará arrancar desde los arreglos degradados y, si no lo consigue, usará /dev/hda como fallback.

Actualiza el ramdisk y genera uno nuevo:

mv /boot/initrd-`uname -r`.img /boot/initrd-`uname -r`.img_orig  
mkinitrd /boot/initrd-`uname -r`.img `uname -r`

Copia los contenidos de /dev/hda1 y /dev/hda6 a /dev/md0 y /dev/md2 (montados en /mnt/md0 y /mnt/md2):

cp -dpRx / /mnt/md2
cd /boot  
cp -dpRx . /mnt/md0

6 Preparar GRUB (Parte 1)

Instala el cargador GRUB en el segundo disco /dev/hdb:

grub

En el shell de GRUB, ejecuta:

root (hd0,0)

Salida esperada:

grub> root (hd0,0)  
 Filesystem type is ext2fs, partition type 0x83  
  
grub>

Luego:

setup (hd0)

Salida esperada (ejemplo):

grub> setup (hd0)  
 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 (hd0)"...  15 sectors are embedded.  
succeeded  
 Running "install /grub/stage1 (hd0) (hd0)1+15 p (hd0,0)/grub/stage2 /grub/menu.lst"... succeeded  
 Done.  
  
grub>

Repite para el otro disco:

root (hd1,0)
setup (hd1)

Ejemplo de salida:

grub> root (hd1,0)  
 Filesystem type is ext2fs, partition type 0xfd  
  
grub> setup (hd1)  
 ... (mensajes similares) ...  
 Done.  
  
grub>

Sal del shell de GRUB:

quit

De vuelta en la shell normal, reinicia y comprueba que el sistema arranca desde el RAID degradado (o que usa el fallback si falla):

reboot

Notas importantes

  • Importante: antes de manipular particiones y sistemas de ficheros, haz una copia de seguridad completa.
  • Nota: trabajar con arreglos degradados es una operación temporal; añade las particiones faltantes tan pronto como sea posible para reconstruir el RAID.

Criterios de aceptación

  • El sistema arranca sin errores desde /dev/md2 (root) y /dev/md0 (/boot) o, al menos, usa el fallback de GRUB para arrancar.
  • /etc/fstab y /etc/mtab referencian los dispositivos md correspondientes.
  • /proc/mdstat muestra los arreglos y el progreso de cualquier reconstrucción.
  • /etc/mdadm.conf contiene entradas ARRAY para los md creados.

Checklist para el administrador

  • Hacer backup completo antes de empezar.
  • Crear md0, md1, md2 con “missing” como placeholder.
  • Crear sistemas de ficheros (mkfs/mkswap).
  • Actualizar /etc/mdadm.conf con mdadm –examine –scan.
  • Montar los md en /mnt/md0 y /mnt/md2.
  • Copiar datos de / y /boot a los md correspondientes.
  • Editar /etc/fstab y /etc/mtab.
  • Actualizar /boot/grub/menu.lst y generar initrd.
  • Instalar GRUB en /dev/hda y /dev/hdb.
  • Reiniciar y verificar arranque y estado de md.

Alternativas y consideraciones

  • Alternativa: usar UUIDs en /etc/fstab en lugar de /dev/mdX para mayor resiliencia frente a renumeración de dispositivos.
  • Alternativa: si el sistema ya usa LVM, considera crear volúmenes lógicos sobre RAID en lugar de particiones directas.
  • Cuando falla: si GRUB no arranca desde md, verifica que el stage1/stage2 existen en /boot y que setup se ejecutó sobre el disco correcto.

Mini-metodología (pasos rápidos)

  1. Crear arreglos con mdadm (placeholder missing).
  2. Formatear y activar swap.
  3. Añadir entradas a /etc/mdadm.conf.
  4. Montar arreglos y copiar datos.
  5. Editar fstab/mtab y menu.lst.
  6. Regenerar initrd y reinstalar GRUB en ambos discos.
  7. Reiniciar y monitorizar /proc/mdstat.

Glosario de una línea

  • mdadm: herramienta de administración de arreglos RAID en Linux.
  • RAID1: espejo de discos (duplicación de datos para redundancia).
  • initrd/mkinitrd: imagen de ramdisk usada durante el arranque.

Resumen final: siguiendo estos pasos crearás arreglos RAID1 degradados, prepararás el sistema para arrancar desde ellos y reinstalarás GRUB en ambos discos para tolerancia a fallos. Después, agrega las particiones faltantes al RAID para completar la reconstrucción.

Autor
Edición

Materiales similares

Podman en Debian 11: instalación y uso
DevOps

Podman en Debian 11: instalación y uso

Apt-pinning en Debian: guía práctica
Sistemas

Apt-pinning en Debian: guía práctica

OptiScaler: inyectar FSR 4 en casi cualquier juego
Guía técnica

OptiScaler: inyectar FSR 4 en casi cualquier juego

Dansguardian + Squid NTLM en Debian Etch
Redes

Dansguardian + Squid NTLM en Debian Etch

Arreglar error de instalación Android en SD
Android

Arreglar error de instalación Android en SD

Conectar carpetas de red con KNetAttach
Redes

Conectar carpetas de red con KNetAttach