Aufsetzen von Software RAID1 auf einem bereits installierten LVM System (inkl. GRUB Konfiguration) (Debian Etch)

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>

Diese Anleitung veranschaulicht, wie man Software RAID1 auf einem bereits installierten LVM System (Debian Etch) aufsetzt. Der GRUB Bootloader wird so konfiguriert, dass das System immer noch in der Lage sein wird zu starten, wenn eine der Festplatten ausfällt (ganz gleich welche).

Ich übernehme keine Garantie, dass dies auch bei Dir funktioniert!

1 Vorbemerkung

In dieser Anleitung verwende ich ein Debian Etch System mit zwei Festplatten, /dev/sda und /dev/sdb, die gleich groß sind. /dev/sdb wird derzeit nicht verwendet und /dev/sda hat folgende Partitionen (das ist das Standard Debian Etch LVM Partitionsschema – Du solltest auf Deinem System etwas ähnliches vorfinden, es sei denn Du hast während der Installation Deines Systems die manuelle Partition gewählt):

  • /dev/sda1: /boot Partition, ext3;
  • /dev/sda2: erweitert, enthält /dev/sda5;
  • /dev/sda5: wird für LVM (Volume Group debian) verwendet und enthält / (Volume root) und Swap (Volume swap_1).

Am Ende möchte ich folgende Situation vorfinden:

  • /dev/md0 (bestehend aus /dev/sda1 und /dev/sdb1): /boot Partition, ext3;
  • /dev/md1 (bestehend aus /dev/sda5 und /dev/sdb5): LVM (Volume Group debian), enthält / (Volume root) und Swap (Volume swap_1).

Dies ist die derzeitige Situation:

df -h

server1:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/debian-root
4.5G 708M 3.6G 17% /
tmpfs 126M 0 126M 0% /lib/init/rw
udev 10M 56K 10M 1% /dev
tmpfs 126M 0 126M 0% /dev/shm
/dev/sda1 236M 13M 211M 6% /boot
server1:~#

fdisk -l

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 83 Linux
/dev/sda2 32 652 4988182+ 5 Extended
/dev/sda5 32 652 4988151 8e Linux LVM

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/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:~#

pvdisplay

server1:~# pvdisplay
— Physical volume —
PV Name /dev/sda5
VG Name debian
PV Size 4.75 GB / not usable 0
Allocatable yes (but full)
PE Size (KByte) 4096
Total PE 1217
Free PE 0
Allocated PE 1217
PV UUID l2G0xJ-b9JF-RLsZ-bbcd-yRGd-kHfl-QFSpdg

server1:~#

vgdisplay

server1:~# vgdisplay
— Volume group —
VG Name debian
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
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 254: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 254:1

server1:~#

2 Installation von mdadm

Das wichtigste Tool beim Aufsetzen von RAID ist mdadm. Wir installieren es wie folgt:

apt-get install initramfs-tools mdadm

Folgende Frage wird Dir gestellt werden:

MD arrays needed for the root filesystem: <– all

Danach laden wir einige Kernel Module (um einen Neustart zu verhindern):

modprobe md
modprobe linear
modprobe multipath
modprobe raid0
modprobe raid1
modprobe raid5
modprobe raid6
modprobe raid10

Führe nun dies aus

cat /proc/mdstat

Die Ausgabe sollte wie folgt aussehen:

server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
unused devices: <none>
server1:~#

3 /dev/sdb vorbereiten

Um ein RAID1 Array auf einem bereits installierten System zu erstellen, müssen wir die /dev/sdb Festplatte für RAID1 vorbereiten, dann die Inhalte unserer /dev/sda Festplatte darauf kopieren und schließlich /dev/sda dem RAID1 Array hinzufügen.

Zunächst kopieren wir die Partitionstabelle von /dev/sda nach /dev/sdb so dass beide Festplatten genau das gleiche Layout haben:

sfdisk -d /dev/sda | sfdisk /dev/sdb

Die Ausgabe sollte wie folgt aussehen:

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 83 Linux
/dev/sdb2 498015 10474379 9976365 5 Extended
/dev/sdb3 0 – 0 0 Empty
/dev/sdb4 0 – 0 0 Empty
/dev/sdb5 498078 10474379 9976302 8e Linux LVM
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:~#

Der Befehl

fdisk -l

sollte nun zeigen, dass beide Festplatten das gleiche Layout haben:

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 83 Linux
/dev/sda2 32 652 4988182+ 5 Extended
/dev/sda5 32 652 4988151 8e Linux LVM

Disk /dev/sdb: 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/sdb1 * 1 31 248976 83 Linux
/dev/sdb2 32 652 4988182+ 5 Extended
/dev/sdb5 32 652 4988151 8e Linux LVM

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:~#

Als Nächstes müssen wir den Partitionstyp unserer drei Partitionen auf /dev/sdb zu Linux raid autodetect ändern:

fdisk /dev/sdb

server1:~# fdisk /dev/sdb

Command (m for help): <- m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition’s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): <- t
Partition number (1-5): <- 1
Hex code (type L to list codes): <- L

0 Empty 1e Hidden W95 FAT1 80 Old Minix be Solaris boot
1 FAT12 24 NEC DOS 81 Minix / old Lin bf Solaris
2 XENIX root 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
5 Extended 41 PPC PReP Boot 85 Linux extended c7 Syrinx
6 FAT16 42 SFS 86 NTFS volume set da Non-FS data
7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
8 AIX 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
f W95 Ext’d (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT
10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT
1c Hidden W95 FAT3 75 PC/IX
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-5): <- 5
Hex code (type L to list codes): <- fd
Changed system type of partition 5 to fd (Linux raid autodetect)

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

Calling ioctl() to re-read partition table.
Syncing disks.
server1:~#

Der Befehl

fdisk -l

sollte nun anzeigen, dass /dev/sdb1 und /dev/sdb5 vom Typ Linux raid autodetect sind:

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 83 Linux
/dev/sda2 32 652 4988182+ 5 Extended
/dev/sda5 32 652 4988151 8e Linux LVM

Disk /dev/sdb: 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/sdb1 * 1 31 248976 fd Linux raid autodetect
/dev/sdb2 32 652 4988182+ 5 Extended
/dev/sdb5 32 652 4988151 fd Linux raid autodetect

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:~#

Um sicher zu gehen, dass auf /dev/sdb keine Überreste von vorherigen RAID1 Installationen vorhanden sind, führen wir folgende Befehle aus:

mdadm –zero-superblock /dev/sdb1
mdadm –zero-superblock /dev/sdb5

Wenn keine Überreste früherer RAID Installationen vorhanden sind, wird jeder der obigen Befehle einen ähnlichen Fehler wie diesen anzeigen (worüber Du Dir keine Sorgen machen brauchst):

server1:~# mdadm –zero-superblock /dev/sdb1
mdadm: Unrecognised md component device – /dev/sdb1
server1:~#

Anderenfalls zeigen die Befehle überhaupt nichts an.

4 Unsere RAID Arrays erstellen

Lass uns nun unsere RAID Arrays /dev/md0 und /dev/md1 erstellen. /dev/sdb1 wird /dev/md0 hinzugefügt und dev/sdb5 zu /dev/md1. /dev/sda1 und /dev/sda5 können noch nicht jetzt hinzugefügt werden (da das System derzeit auf ihnen läuft), daher verwenden wir den Platzhalter missing in den folgenden beiden Befehlen:

mdadm –create /dev/md0 –level=1 –raid-disks=2 missing /dev/sdb1
mdadm –create /dev/md1 –level=1 –raid-disks=2 missing /dev/sdb5

Der Befehl

cat /proc/mdstat

sollte nun anzeigen, dass Du zwei degraded RAID Arrays hast ([_U] oder [U_] bedeutet, dass ein Array degraded ist, wohingegen [UU] bedeutet, dass das Array in Ordnung ist):

server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md1 : active raid1 sdb5[1]
4988032 blocks [2/1] [_U]

md0 : active raid1 sdb1[1]
248896 blocks [2/1] [_U]

unused devices: <none>
server1:~#

Als Nächstes erstellen wir das Dateisystem (ext3) auf unserem nicht-LVM RAID Array /dev/md0:

mkfs.ext3 /dev/md0

Nun kommen wir zu unserem LVM RAID Array /dev/md1. Um es für LVM vorzubereiten, führen wir dies aus:

pvcreate /dev/md1

Das könnte dich auch interessieren …