adminForge

free | no tracking | no logging | no advertising

Das ist unser Motto. Mit adminForge bieten wir kostenlose Dienste an. Unser Ziel ist es, eine freie und datensparsame Alternative zu bekannten Diensten bereitzustellen. Seit 2014 betreiben wir adminForge gemeinsam mit Spaß an der Technik und an Open-Source.

mdadm Raid 1 reparieren nach Festplattentausch

Das mdadm Raid war degraded, der Provider hat bereits die defekte Festplatte ausgetauscht.
Die neue Festplatte wieder dem Raid 1 hinzuzufügen ist mit dieser Anleitung spielend einfach.

Sollte das System nicht mehr lauffähig sein, starte den Recovery/Rescue Mode über das Provider Webinterface.

Punkt 1: Raid Status prüfen

Bei den hervorgehobenen Zeilen sehen wir das HDD /dev/sda nicht vorhanden ist, diese wurde ausgetauscht.

# mdadm -As
mdadm: /dev/md/0 has been started with 1 drive (out of 2).
mdadm: /dev/md/1 has been started with 1 drive (out of 2).

# cat /proc/mdstat
Personalities : [raid1] [raid0] [raid6] [raid5] [raid4]
md1 : active raid1 sdb3[1]
1951939452 blocks super 1.1 [2/1] [_U]
bitmap: 8/15 pages [32KB], 65536KB chunk

md0 : active raid1 sdb1[1]
524276 blocks super 1.0 [2/1] [_U]

unused devices:

Punkt 2: Partitionen prüfen

Die neue Festplatte hat keine Partitionstabelle, das prüfen wir mit diesem Befehl.

# fdisk -l

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sda doesn't contain a valid partition table

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x000e9cc3

Device Boot Start End Blocks Id System
/dev/sdb1 * 2048 1050623 524288 fd Linux raid autodetect
/dev/sdb2 1050624 3147775 1048576 82 Linux swap / Solaris
/dev/sdb3 3147776 3907028991 1951940608 fd Linux raid autodetect

Disk /dev/md0: 536 MB, 536858624 bytes
2 heads, 4 sectors/track, 131069 cylinders, total 1048552 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/md0 doesn't contain a valid partition table

Disk /dev/md1: 1998.8 GB, 1998785998848 bytes
2 heads, 4 sectors/track, 487984863 cylinders, total 3903878904 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/md1 doesn't contain a valid partition table

Punkt 3: Kopieren der Partitionstabelle

Mittels sfdisk (MBR) oder gdisk (GPT) kopieren wir die Partitionstabelle auf die neue Festplatte.

MBR

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

GPT

sgdisk --backup=table /dev/sdb
sgdisk --load-backup=table /dev/sda
sgdisk -G /dev/sda

Falls das System die neuen Partitionen nicht erkennt…
Beispiel: /dev/sda hat keine Partitionen.

localhost:~# ls -lah /dev/sd*
brw-rw---- 1 root disk 8, 2. Mai 11:33 /dev/sda
brw-rw---- 1 root disk 8, 2. Mai 11:33 /dev/sdb
brw-rw---- 1 root disk 8, 1. Mai 09:13 /dev/sdb1
brw-rw---- 1 root disk 8, 1. Mai 09:13 /dev/sdb2
brw-rw---- 1 root disk 8, 1. Mai 09:13 /dev/sdb3
brw-rw---- 1 root disk 8, 1. Mai 09:13 /dev/sdb4

…fixen wir dies mit dem Befehl partprobe

localhost:~# ls -lah /dev/sd*
brw-rw---- 1 root disk 8, 2. Mai 11:33 /dev/sda
brw-rw---- 1 root disk 8, 2. Mai 11:33 /dev/sda1
brw-rw---- 1 root disk 8, 1. Mai 09:13 /dev/sda2
brw-rw---- 1 root disk 8, 1. Mai 09:13 /dev/sda3
brw-rw---- 1 root disk 8, 1. Mai 09:13 /dev/sda4
brw-rw---- 1 root disk 8, 2. Mai 11:33 /dev/sdb
brw-rw---- 1 root disk 8, 2. Mai 11:33 /dev/sdb1
brw-rw---- 1 root disk 8, 2. Mai 11:33 /dev/sdb2
brw-rw---- 1 root disk 8, 2. Mai 11:33 /dev/sdb3
brw-rw---- 1 root disk 8, 2. Mai 11:33 /dev/sdb4

Punkt 4: Neue Festplatte dem Raid hinzufügen

Zuerst stellen wir das Raid für /boot wieder her. Wir fügen also /dev/sda1 dem Volume /dev/md0 hinzu.

# mdadm --add /dev/md0 /dev/sda1
mdadm: added /dev/sda1

Nun folgt /, wir fügen /dev/sda3 dem Volume /dev/md1 hinzu.

# mdadm --add /dev/md1 /dev/sda3
mdadm: added /dev/sda3

Sollte keine Bestätigung added /dev/sda3 ausgegeben worden sein, bitte das Raid kurz stoppen und wieder zusammenfügen.

# mdadm --stop /dev/md1
mdadm: stopped /dev/md1

# mdadm -A /dev/md1
mdadm: /dev/md1 has been started with 1 drive (out of 2) and 1 spare.

Punkt 5: Resync Prozess beobachten

# cat /proc/mdstat

Personalities : [raid1] [raid0] [raid6] [raid5] [raid4]
md1 : active raid1 sdb3[1] sda3[2]
1951939452 blocks super 1.1 [2/1] [_U]
[>....................] recovery = 0.0% (91392/1951939452) finish=711.7min speed=45696K/sec
bitmap: 8/15 pages [32KB], 65536KB chunk

md0 : active raid1 sda1[2] sdb1[1]
524276 blocks super 1.0 [2/2] [UU]

unused devices:

TIPP: In der Datei (Debian) /etc/mdadm/mdadm.conf kann eine E-Mail Adresse MAILADDR für Störungsmeldungen hinterlegt werden.

Punkt 6: GRUB Bootloader schreiben

Da es sich um /dev/sda handelt muss der GRUB Bootloader neu in den MBR geschrieben werden. Wir bauen als Erstes eine Chroot-Umgebung auf.

mount /dev/md1 /mnt
mount /dev/md0 /mnt/boot
mount -t proc none /mnt/proc
mount -o bind /dev /mnt/dev
mount -o bind /sys /mnt/sys
chroot /mnt

Den Bootloader schreiben wir mit diesen Befehlen in den MBR. (Befehle sind hervorgehoben)

GRUB 1

# grub
Probing devices to guess BIOS drives. This may take a long time.

GNU GRUB version 0.97 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename.]
grub> root (hd0,0)
root (hd0,0)
Filesystem type is ext2fs, partition type 0xfd
grub> setup (hd0)
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)"... 27 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd0) (hd0)1+27 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.
grub> setup (hd1)
setup (hd1)
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 (hd1)"... 27 sectors are embedded.
succeeded
Running "install /grub/stage1 d (hd1) (hd1)1+27 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.
grub> quit

GRUB 2

# grub-install /dev/sda
# grub-install /dev/sdb

Das war es, der Recovery/Rescue Mode kann beendet werden, insofern es nicht mehr lauffähig war. Das System ist wieder bootfähig.