Sollte aus irgendwelchen Gründen in unserem mdadm Software-Raid nur noch eine Festplatte aktiv sein und diese wird auch noch als Spare erkannt – hilft euch dieses Tutorial weiter.
Punkt 1: Aktive Festplatte herausfinden
Das System bootet nicht mehr, bei der Überprüfung in einem Recovery/Rescue System schaut /dev/md2 in etwa so aus?
# cat /proc/mdstat
Personalities : [raid1] [raid0] [raid6] [raid5] [raid4]
md2 : active raid1 sda4[0](S)
968258424 blocks super 1.2 [2/1] [U_]
md1 : active raid1 sda3[0] sdb3[1]
7999476 blocks super 1.2 [2/2] [UU]
md0 : active raid1 sda2[0] sdb2[1]
499700 blocks super 1.2 [2/2] [UU]
unused devices: <none>
Dann hilft am schnellsten das Raid neu zu erstellen.
Punkt 2: Raid Device neu erstellen
Wir führen folgenden Befehl auf das noch aktive Device /dev/sda4 aus.
# mdadm --examine /dev/sda4
/dev/sda4:
Magic : a92b4efc
Version : 1.2
Feature Map : 0x0
Array UUID : 99b62f02:a94a4449:638761b0:f61843fd
Name : zebra777:2
Creation Time : Thu Jan 9 06:15:42 2014
Raid Level : raid1
Raid Devices : 2
Avail Dev Size : 1936517120 (923.40 GiB 991.50 GB)
Array Size : 1936516848 (923.40 GiB 991.50 GB)
Used Dev Size : 1936516848 (923.40 GiB 991.50 GB)
Data Offset : 2048 sectors
Super Offset : 8 sectors
State : clean
Device UUID : c8ff7993:7e7ce073:c360cf66:9910dedb
Update Time : Sun Feb 16 02:18:37 2014
Checksum : 228ee4c8 - correct
Events : 108
Device Role : Active device 0
Array State : AA ('A' == active, '.' == missing)
Den markierten Wert Used Dev Size 1936516848 teilen wir durch 2 und kommen somit auf eine Size von 968258424. Mehr zu diesem Thema unter raid.wiki.kernel.org.
Mit dem soeben errechneten Wert erstellen wir unser neues /dev/md2 Device mit nur einer Partition + einer „missing“.
# mdadm --create /dev/md2 --metadata=1.2 --assume-clean --level=1 --size=968258424 --raid-devices=2 /dev/sda4 missing
mdadm: /dev/sda4 appears to be part of a raid array:
level=raid1 devices=2 ctime=Thu Jan 9 06:15:42 2014
Continue creating array? y
mdadm: array /dev/md2 started.
Das Ergebnis schaut wie folgt aus.
# cat /proc/mdstat
Personalities : [raid1] [raid0] [raid6] [raid5] [raid4]
md2 : active raid1 sda4[0]
968258424 blocks super 1.2 [2/1] [U_]
md1 : active raid1 sda3[0] sdb3[1]
7999476 blocks super 1.2 [2/2] [UU]
md0 : active raid1 sda2[0] sdb2[1]
499700 blocks super 1.2 [2/2] [UU]
unused devices: <none>
Wir prüfen ob unsere Daten noch vorhanden sind.
# mount /dev/md2 /mnt
# ls -lah /mnt
total 132K
drwxr-xr-x 22 root root 4.0K Feb 11 09:04 .
drwxrwxrwt 27 root root 220 Feb 16 08:24 ..
-rw------- 1 root root 10K Feb 16 02:18 aquota.group
-rw------- 1 root root 16K Feb 16 02:18 aquota.user
drwxr-xr-x 2 root root 4.0K Jan 9 06:58 bin
drwxr-xr-x 2 root root 4.0K Jan 9 06:18 boot
drwxr-xr-x 5 root root 4.0K Jan 9 06:23 dev
drwxr-xr-x 100 root root 4.0K Feb 12 21:40 etc
drwxr-xr-x 3 root root 4.0K Jan 9 10:52 home
lrwxrwxrwx 1 root root 30 Jan 9 06:26 initrd.img -> boot/initrd.img-2.6.32-5-amd64
drwxr-xr-x 11 root root 12K Jan 9 07:02 lib
drwxr-xr-x 2 root root 4.0K Jan 9 06:29 lib32
lrwxrwxrwx 1 root root 4 Jan 9 06:18 lib64 -> /lib
drwx------ 2 root root 16K Jan 9 06:17 lost+found
drwxr-xr-x 2 root root 4.0K Jan 9 06:18 media
drwxr-xr-x 2 root root 4.0K Sep 22 22:30 mnt
drwxr-xr-x 2 root root 4.0K Jan 9 06:18 opt
drwxr-xr-x 2 root root 4.0K Sep 22 22:30 proc
drwx------ 8 root root 4.0K Jan 13 15:38 root
drwxr-xr-x 2 root root 4.0K Jan 9 07:17 sbin
drwxr-xr-x 2 root root 4.0K Jul 21 2010 selinux
drwxr-xr-x 2 root root 4.0K Jan 9 06:18 srv
drwxr-xr-x 2 root root 4.0K Mar 27 2012 sys
drwxrwxrwt 5 root root 4.0K Feb 16 02:18 tmp
drwxr-xr-x 11 root root 4.0K Jan 9 07:46 usr
drwxr-xr-x 16 root root 4.0K Jan 9 07:36 var
lrwxrwxrwx 1 root root 27 Jan 9 06:26 vmlinuz -> boot/vmlinuz-2.6.32-5-amd64
Punkt 3: Zweite Partition dem Raid hinzufügen
Nun können wir auch unsere andere Partition /dev/sdb4 hinzufügen.
# mdadm --add /dev/md2 /dev/sdb4
mdadm: added /dev/sdb4
Das Raid führt anschließend einen Resync durch.
# cat /proc/mdstat
Personalities : [raid1] [raid0] [raid6] [raid5] [raid4]
md2 : active raid1 sdb4[2] sda4[0]
968258424 blocks super 1.2 [2/1] [U_]
[>....................] recovery = 0.0% (823936/968258424) finish=156.5min speed=102992K/sec
md1 : active raid1 sda3[0] sdb3[1]
7999476 blocks super 1.2 [2/2] [UU]
md0 : active raid1 sda2[0] sdb2[1]
499700 blocks super 1.2 [2/2] [UU]
unused devices: <none>
Sollte der Resync Prozess zu langsam sein, können wir diesen beschleunigen.
echo 100000 > /proc/sys/dev/raid/speed_limit_min
Punkt 4: mdadm.conf anpassen und Initrd neu erstellen
Wir bauen eine Chroot-Umgebung auf.
mount /dev/md2 /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
Und tauschen unsere neue /dev/md2 Array Zeile in /etc/mdadm/mdadm.conf aus.
# mdadm --examine --scan
ARRAY /dev/md0 UUID=b84a5825:1ccdb221:0db498df:97b8183d
ARRAY /dev/md1 UUID=703be351:3143332c:5b6d88b1:6bd98140
ARRAY /dev/md2 UUID=22d67abd:fe0cc6a8:5b6d88b1:6bd98140
Damit der Kernel das neue Array automatisch beim Booten erkennt, müssen wir die Initrd noch neu erstellen.
# update-initramfs -u
update-initramfs: Generating /boot/initrd.img-2.6.32-5-amd64
Unser System kann nun wieder im produktiv Betrieb gebootet werden.