vgdisplay
server1:~# vgdisplay
--- Volume group ---
VG Name debian
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 9
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 4.75 GB
PE Size 4.00 MB
Total PE 1217
Alloc PE / Size 1217 / 4.75 GB
Free PE / Size 0 / 0
VG UUID j5BV1u-mQSa-Q0KW-PH4n-VHab-DB92-LyxFIU
server1:~#
lvdisplay
server1:~# lvdisplay
--- Logical volume ---
LV Name /dev/debian/root
VG Name debian
LV UUID BTAfBf-auQQ-wWC5-daFC-3qIe-gJU3-2j0UiG
LV Write Access read/write
LV Status available
# open 1
LV Size 4.50 GB
Current LE 1151
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:0
--- Logical volume ---
LV Name /dev/debian/swap_1
VG Name debian
LV UUID Q3IVee-DhoD-Nd07-v9mR-CmsN-HAt8-1bDcP4
LV Write Access read/write
LV Status available
# open 2
LV Size 264.00 MB
Current LE 66
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:1
server1:~#
Nun müssen wir auch den Partitionstyp von /dev/sda1 auf Linux raid autodetect ändern:
fdisk /dev/sda
server1:~# fdisk /dev/sda
Command (m for help): <- t
Partition number (1-5): <- 1
Hex code (type L to list codes): <- fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): <- w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
server1:~#
Nun können wir /dev/sda1 dem /dev/md0 RAID Array hinzufügen:
mdadm --add /dev/md0 /dev/sda1
Sieh Dir nun Folgendes an
cat /proc/mdstat
server1:~# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sda5[0] sdb5[1]
4988032 blocks [2/2] [UU]
md0 : active raid1 sda1[0] sdb1[1]
248896 blocks [2/2] [UU]
unused devices: <none>
server1:~#
Passe dann /etc/mdadm/mdadm.conf der neuen Situation an:
cp /etc/mdadm/mdadm.conf_orig /etc/mdadm/mdadm.conf
mdadm --examine --scan >> /etc/mdadm/mdadm.conf
/etc/mdadm/mdadm.conf sollte nun in etwa so aussehen:
cat /etc/mdadm/mdadm.conf
# mdadm.conf # # Please refer to mdadm.conf(5) for information about this file. # # by default, scan all partitions (/proc/partitions) for MD superblocks. # alternatively, specify devices to scan, using wildcards if desired. DEVICE partitions # auto-create devices with Debian standard permissions CREATE owner=root group=disk mode=0660 auto=yes # automatically tag new arrays as belonging to the local system HOMEHOST <system> # instruct the monitoring daemon where to send mail alerts MAILADDR root # definitions of existing MD arrays # This file was auto-generated on Tue, 18 Mar 2008 19:28:19 +0100 # by mkconf $Id: mkconf 261 2006-11-09 13:32:35Z madduck $ ARRAY /dev/md0 level=raid1 num-devices=2 UUID=6fe4b95e:4ce1dcef:01b5209e:be9ff10a ARRAY /dev/md1 level=raid1 num-devices=2 UUID=aa4ab7bb:df7ddb72:01b5209e:be9ff10a |
Starte das System neu:
reboot
Es sollte ohne Probleme starten.
Das war’s - Du hast Software RAID1 erfolgreich auf Deinem installierten LVM System aufgesetzt!
8 Test
Lass uns nun den Ausfall einer Festplatte simulieren. Es ist egal ob Du /dev/sda oder /dev/sdb auswählst. In diesem Beispiel gehe ich davon aus, dass /dev/sdb ausgefallen ist.
Um den Ausfall der Festplatte zu simulieren, kannst Du entweder das System runter fahren und /dev/sdb von dem System entfernen oder Du entfernst sie wie folgt:
mdadm --manage /dev/md0 --fail /dev/sdb1
mdadm --manage /dev/md1 --fail /dev/sdb5
mdadm --manage /dev/md0 --remove /dev/sdb1
mdadm --manage /dev/md1 --remove /dev/sdb5
Fahre das System runter:
shutdown -h now
Füge dann eine neue /dev/sdb Festplatte hinzu (wenn Du einen Fehler von /dev/sda simulierst, solltest Du nun /dev/sdb anstelle von /dev/sda verwenden und die neue Festplatte /dev/sdb hinzufügen!) und starte das System. Es sollte immer noch ohne Probleme starten.
Führe nun Folgendes aus
cat /proc/mdstat
und Du müsstest feststellen, dass wir ein degraded Array haben:
server1:~# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sda5[0]
4988032 blocks [2/1] [U_]
md0 : active raid1 sda1[0]
248896 blocks [2/1] [U_]
unused devices: <none>
server1:~#
Die Ausgabe von
fdisk -l
sollte wie folgt aussehen:
server1:~# fdisk -l
Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 31 248976 fd Linux raid autodetect
/dev/sda2 32 652 4988182+ 5 Extended
/dev/sda5 32 652 4988151 fd Linux raid autodetect
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn’t contain a valid partition table
Disk /dev/md0: 254 MB, 254869504 bytes
2 heads, 4 sectors/track, 62224 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Disk /dev/md0 doesn’t contain a valid partition table
Disk /dev/md1: 5107 MB, 5107744768 bytes
2 heads, 4 sectors/track, 1247008 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Disk /dev/md1 doesn’t contain a valid partition table
Disk /dev/dm-0: 4827 MB, 4827643904 bytes
255 heads, 63 sectors/track, 586 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/dm-0 doesn’t contain a valid partition table
Disk /dev/dm-1: 276 MB, 276824064 bytes
255 heads, 63 sectors/track, 33 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/dm-1 doesn’t contain a valid partition table
server1:~#
Nun kopieren wir die Partitionstabelle von /dev/sda nach /dev/sdb:
sfdisk -d /dev/sda | sfdisk /dev/sdb
(Wenn ein Fehler angezeigt wird, kannst Du die --force Option versuchen:
sfdisk -d /dev/sda | sfdisk --force /dev/sdb
)
server1:~# sfdisk -d /dev/sda | sfdisk /dev/sdb
Checking that no-one is using this disk right now …
OK
Disk /dev/sdb: 652 cylinders, 255 heads, 63 sectors/track
sfdisk: ERROR: sector 0 does not have an msdos signature
/dev/sdb: 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/sdb1 * 63 498014 497952 fd Linux raid autodetect
/dev/sdb2 498015 10474379 9976365 5 Extended
/dev/sdb3 0 - 0 0 Empty
/dev/sdb4 0 - 0 0 Empty
/dev/sdb5 498078 10474379 9976302 fd Linux raid autodetect
Successfully wrote the new partition table
Re-reading the partition table …
If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
server1:~#
Danach entfernen wir alle Überreste eines vorherigen RAID Arrays aus /dev/sdb…
mdadm --zero-superblock /dev/sdb1
mdadm --zero-superblock /dev/sdb5
… und fügen /dev/sdb dem RAID Array hinzu:
mdadm -a /dev/md0 /dev/sdb1
mdadm -a /dev/md1 /dev/sdb5
Sieh Dir nun Folgendes an
cat /proc/mdstat
server1:~# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdb5[2] sda5[0]
4988032 blocks [2/1] [U_]
[==================>..] recovery = 91.9% (4586880/4988032) finish=0.1min speed=41410K/sec
md0 : active raid1 sdb1[1] sda1[0]
248896 blocks [2/2] [UU]
unused devices: <none>
server1:~#
Warte bis die Synchronisation abgeschlossen ist:
server1:~# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdb5[1] sda5[0]
4988032 blocks [2/2] [UU]
md0 : active raid1 sdb1[1] sda1[0]
248896 blocks [2/2] [UU]
unused devices: <none>
server1:~#
Führe dann Folgendes aus
grub
und installiere den Bootloader auf beiden Festplatten:
root (hd0,0)
setup (hd0)
root (hd1,0)
setup (hd1)
quit
Das war’s. Du hast soeben eine fehlerhaft Festplatte in Deinem RAID1 Array ersetzt.
9 Links
- The Software-RAID Howto: http://tldp.org/HOWTO/Software-RAID-HOWTO.html
- Debian: http://www.debian.org
- Aufsetzen von Software RAID1 auf einem bereits installierten LVM System (inkl. GRUB Konfiguration) (Debian Etch) - Seite 1
- Aufsetzen von Software RAID1 auf einem bereits installierten LVM System (inkl. GRUB Konfiguration) (Debian Etch) - Seite 2
- Aufsetzen von Software RAID1 auf einem bereits installierten LVM System (inkl. GRUB Konfiguration) (Debian Etch) - Seite 3


Am 15.09.2008 um 12:41 Uhr
Ausgezeichnetes HowTo!
Allerdings hat Dir der Editor offensichtlich gelegentlich Streiche gespielt. Die zwei -- vor einigen Optionen stehen als – im Text. Ich habe erst nach einigem Grübeln herausbekommen warum das Copy und Past der Befehle nicht funktioniert.
Noch ein Vorschlag:
Ich weiß zwar, dass die vorgestellte Situation nur beispielhaft ist, aber besser wäre es vielleicht, das Beispiel mit /dev/sda und /dev/sdc vorzustellen und darauf hinzuweisen, dass ein Raid1 mit beiden Platten an einem Controller ausfällt wenn dieser kaputt geht, aber nicht wenn die Platten auf die Controller aufgeteilt sind!
Grüße, Klaus
Am 15.09.2008 um 12:43 Uhr
Tja, es ist wirklich der Editor! Der verbindet zwei Minus automatisch! Wie kann man das abschalten?
Klaus
Am 16.09.2008 um 13:07 Uhr
Hi,
ich habe das Problem auch erst vor kurzem entdeckt, habe dafür leider noch keine Lösung gefunden. Der Editor im Wordpress ersetzt -- durch einen HTML Code. Ich werde in den nächsten tagen mal das Wordpress updaten und mich dann mal durch den Code des HTML Editors lesen, um zu sehen wo er das ändert.
Grüße,
Till
Am 17.03.2009 um 15:59 Uhr
Festplattenausfall bei Software Raid…
Gestern abend viel eine Platte in einem unserer bei Hetzner gehosteten Servern aus. Die md devices landeten alle nach und nach im Fehlerzustand. Grund genug ein Support Ticket bei Hetzner aufzumachen und um einen Plattentausch zu bitten.
Heute morgen …