Raid

Aus crazylinux.de
Zur Navigation springen Zur Suche springen

Hier geht es eigentlich um Software-Raid unter Linux. Unser Server hat zwei IDE-Platten (hda und hdb), die jeweils gespiegelt werden (raid1-Mirroring). Insgesamt hat jede Platte fünf 'Partitionen'. Für jede Partition gibt es ein 'virtuelles' Device, das man mountet. Über eine Konfiguration werden die Raid-Optionen eingestellt. Z.B. welches Raid-Level, wieviele Platten/Partitionen hängen am Raid, gibt es eine Not/Reserve-Platte usw.. Raid schützt 'NUR' gegen Hardwareauffall. Bei Datenverlust hilft nur ein Backup. Ein Backup sollte(muß) zusätzlich gemacht werden!

Besonders sollte noch beachtet werden, dass bei Sarge die md-Module nicht fest im Kernel enthalten sind, sondern als Modul. Das hat zur Folge, dass wenn man von einer Raid-Partition booten will, es erstmal kracht, da der Kernel keine Treiber fürs Raid hat. Lösung ist hier, die md-Module in die Initrd zu packen.

Wenn man nicht schon bei der Linux-Installation die Raid-Arrays erstellt hat, muss man die Einrichtung im Nachhinein machen. D.h. das System ist z. B. bereits auf der ersten Platte installiert und eine zweite(möglichst baugleich) fürs Raid kommt neu hinzu. Dann kann man sogar die Umstellung sogar fast unter laufenden Betrieb machen. Jedenfalls geht es remote über eine ssh-session ;-).

Dazu kopiert man die erste auf die zweite Platte:

  • Partitionstabelle (also die ersten 512 Blöcke der Festplatte) kopieren, z.b. mit

dd if=/dev/hda of=/dev/hdb count=512 bs=1 (OHNE GEWÄHR!!)

dann die Partitionen kopieren, hier hat sich rsync bewährt rsync -ax /usr/ /mnt/md0/usr/

Commands

Proc/Status

Einen Schnellstatus bekommt man übers Proc-FS.

servername:/home# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sda1[0] sdb1[1]
      1951744 blocks [2/2] [UU]

md1 : active raid1 sda2[0] sdb2[1]
      128448 blocks [2/2] [UU]

md2 : active raid1 sda3[0] sdb3[1]
      5855616 blocks [2/2] [UU]

md3 : active raid1 sda5[0] sdb5[1]
      7815488 blocks [2/2] [UU]

md4 : active raid1 sda6[0] sdb6[1]
      140536512 blocks [2/2] [UU]

unused devices: <none>


Create Device

fs ~ # mknod /dev/md0 b 9 1
fs ~ # mknod /dev/md1 b 9 1
fs ~ # mknod /dev/md2 b 9 1
fs ~ # mknod /dev/md3 b 9 1
fs ~ # mknod /dev/md4 b 9 1
fs ~ # mknod /dev/md5 b 9 1

Create Raid-Array

Create Raid: device will be md2, raidlevel is 1, overall 2 devices for this raiddevice, first (hda2) will come later, second is hdb2 mdadm --create /dev/md2 --level 1 --raid-devices=2 missing /dev/hdb2

After creating, save the information about the just created array(s) echo 'DEVICE /dev/hd*' > /etc/mdadm/mdadm.conf mdadm --detail --scan >> /etc/mdadm/mdadm.conf

#cat /etc/mdadm/mdadm.conf
DEVICE /dev/sda* /dev/sdb*
ARRAY /dev/md4 level=raid1 num-devices=2 UUID=30d84aac:8a052176:bfc9a7a4:58e55a65
   devices=/dev/sda6,/dev/sdb6
ARRAY /dev/md3 level=raid1 num-devices=2 UUID=e56a47d3:018c181f:13b17b8d:3928b638
   devices=/dev/sda5,/dev/sdb5
ARRAY /dev/md2 level=raid1 num-devices=2 UUID=ac1fb5f2:ad1191b7:2d01b490:4da0457b
   devices=/dev/sda3,/dev/sdb3
ARRAY /dev/md1 level=raid1 num-devices=2 UUID=7bb95c6a:4a2c1876:dea25f1f:889cc085
   devices=/dev/sda2,/dev/sdb2
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=b21bfc50:7d0881bb:4befd765:22d79364
   devices=/dev/sda1,/dev/sdb1
MAILADDR root


attach the new partitions

attach the new partitions to the existing (degraded) RAID arrays: mdadm /dev/md2 -a /dev/hda2


Print Info about raid-devices

This will find out if a given device is a raid array, or is part of one, and will provide brief information about the device.

gretchen:/home/jonathan# mdadm --query /dev/md2 /dev/md2: 94.06MiB raid1 2 devices, 0 spares. Use mdadm --detail for more detail. /dev/md2: No md super block found, not an md component.

More information about an Array.

gretchen:/home/jonathan# mdadm --detail /dev/md2
/dev/md2:
Version : 00.90.01
Creation Time : Mon Oct 24 23:13:40 2005
Raid Level : raid1
Array Size : 96320 (94.06 MiB 98.63 MB)
Device Size : 96320 (94.06 MiB 98.63 MB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 2
Persistence : Superblock is persistent

Update Time : Fri Jan 20 00:00:43 2006
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

UUID : 281866a2:081c9b2f:5ee8cab6:12345678
Events : 0.2297

Number   Major   Minor   RaidDevice State
0       3        2        0      active sync   /dev/hda2
1       3       66        1      active sync   /dev/hdb2

Links

Linux Software RAID1 defekte Platte tauschen
Replacing A Failed Hard Drive In A Software RAID1 Array
Root System to Bootable Software RAID1 (Debian)
a guide to Linux software RAID under the 2.4 and 2.6 kernels
Software Raid (little bit outdated)
PA-RISC Linux RAID1 Root HOWTO
Root on LVM on software RAID micro howto