terça-feira, 16 de novembro de 2010

Linux - Raid 1 + LVM

Esses dias deparei-me com a necessidade de implementar um Raid1 em um servidor antigo, onde a controladora não suportava Raid com SATA (tá OK, fica ruim - mas era necessário).

Criando Raid 1 via linha de comando

# yum install raidutils

Fdisk

[root@localhost ~]# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 2550 20482843+ 83 Linux
/dev/sda2 2551 60801 467901157+ fd Linux raid autodetect

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 1275 10241406 83 Linux
/dev/sdb2 1276 1340 522112+ 82 Linux swap / Solaris
/dev/sdb3 1341 60801 477620482+ fd Linux raid autodetect

Criando as Partições:

fdisk /dev/sda
n
2
t
fd
w

fdisk /dev/sdb
n
3
t
fd
w

# partprobe /dev/sda
# partprobe /dev/sdb

# mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda2 /dev/sdb3
mdadm: size set to 467901056K
mdadm: largest drive (/dev/sdb3) exceed size (467901056K) by more than 1%
Continue creating array? yes

# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb3[1] sda2[0]
467901056 blocks [2/2] [UU]
[>....................] resync = 0.8% (3954496/467901056) finish=58.6min speed=131816K/sec

unused devices:

OBS: tenha paciência isso demora

# mke2fs -j /dev/md0

ou formate com o Filesystem que você preferir (ou crie LVM).

LVM (básico):

# pvcreate /dev/md0

# vgcreate VG0 /dev/md0

# lvcreate -L 40G -n virtual0 VG0

Feito, criada a LVM. (normalmente eu uso system-config-lvm)