Ein Versagen einer Festplatte führt in unserer Konfiguration zum sofortigen Ersatz durch den Spare, die dritte Festplatte und eine Mail an root.

Das wollen wir jetzt mal simulieren und die defekte Festplatte wieder durch ein neues Spare ersetzen.

Alle Werkzeuge die wir dafür brauchen bietet uns die Raidverwaltung mdadm sowie das Partionierungstool fdisk.

Zunächst ein Blick in den Bestand:

gateway: ~ # cat /proc/mdstat
Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid1 sdc1[2](S) sda1[0] sdb1[1]
       26194944 blocks super 1.2 [2/2] [UU]
       
 unused devices: <none>

Eine ausführliche Aussicht erteilt:

gateway: ~ # mdadm --detail /dev/md0
/dev/md0:
            Version : 1.2
      Creation Time : Thu Oct 17 14:41:56 2019
         Raid Level : raid1
         Array Size : 26194944 (24.98 GiB 26.82 GB)
      Used Dev Size : 26194944 (24.98 GiB 26.82 GB)
       Raid Devices : 2
      Total Devices : 3
        Persistence : Superblock is persistent
 

        Update Time : Thu Nov 21 14:32:56 2019
              State : clean 
     Active Devices : 2
    Working Devices : 3
     Failed Devices : 0
      Spare Devices : 1
 

Consistency Policy : resync
 

               Name : gateway:0  (local to host gateway)
               UUID : d3594f07:7a5321d2:926eb124:704b6115
             Events : 447
 

     Number   Major   Minor   RaidDevice State
        0       8        1        0      active sync   /dev/sda1
        1       8       17        1      active sync   /dev/sdb1
 

        2       8       33        -      spare   /dev/sdc1

Um es mit Murphy zu halten, hau ich jetzt mal /dev/sda komplett raus:
heisst ich stöpsel sie einfach im laufenden Betrieb aus…

gateway: ~ # mdadm --detail /dev/md0
 /dev/md0:
            Version : 1.2
      Creation Time : Thu Oct 17 14:41:56 2019
         Raid Level : raid1
         Array Size : 26194944 (24.98 GiB 26.82 GB)
      Used Dev Size : 26194944 (24.98 GiB 26.82 GB)
       Raid Devices : 2
      Total Devices : 2
        Persistence : Superblock is persistent
 

        Update Time : Thu Nov 21 14:40:05 2019
              State : clean, degraded, recovering 
     Active Devices : 1
    Working Devices : 2
     Failed Devices : 0
      Spare Devices : 1
 

 Consistency Policy : resync
 

     Rebuild Status : 8% complete
 

               Name : gateway:0  (local to host gateway)
               UUID : d3594f07:7a5321d2:926eb124:704b6115
             Events : 470
 

     Number   Major   Minor   RaidDevice State
        2       8       17        0      spare rebuilding   /dev/sdb1
        1       8        1        1      active sync   /dev/sda1

Das dauert jetzt etwas, währenddessen kann man sich fragen ob das System hotswapable ist, also ob ich eine neue Festplatte im laufenden Betrieb einbauen kann, oder ob die Maschine dazu ausgeschaltet werden muss.
Meine VM muss ausgeschaltet werden, also….Kaffee!
Den Verlauf des Rebuilds kann man mit cat /proc/mdstat beobachten.
Fertig sieht es jetzt so aus:

gateway: ~ # mdadm --detail /dev/md0
 /dev/md0:
            Version : 1.2
      Creation Time : Thu Oct 17 14:41:56 2019
         Raid Level : raid1
         Array Size : 26194944 (24.98 GiB 26.82 GB)
      Used Dev Size : 26194944 (24.98 GiB 26.82 GB)
       Raid Devices : 2
      Total Devices : 2
        Persistence : Superblock is persistent
 

        Update Time : Thu Nov 21 14:42:14 2019
              State : clean 
     Active Devices : 2
    Working Devices : 2
     Failed Devices : 0
      Spare Devices : 0
 

 Consistency Policy : resync
 

               Name : gateway:0  (local to host gateway)
               UUID : d3594f07:7a5321d2:926eb124:704b6115
             Events : 505
 

     Number   Major   Minor   RaidDevice State
        2       8       17        0      active sync   /dev/sdb1
        1       8        1        1      active sync   /dev/sda1

Man beachte, es sind wieder sda und sdb am Start, sdc ist verschwunden, obwohl ich sda gezogen habe.
Es ist jetzt nicht klar, ob sdc – sda ersetzt hat, oder sdb -sda und sdc – sdb…
Deshalb spiele ich jetzt als erstes eine Runde
grub-install /dev/sda
grub-install /dev/sdb
update-grub
um wieder auf der sicheren Seite zu sein.
Nun ausschalten und neue Platte rin. Hochfahren und schauen ob sie da ist:

gateway: ~ # ls /dev | grep sd
 sda
 sdb
 sdb1
 sdc
 sdc1
 gateway: ~ # mdadm --detail /dev/md0
 /dev/md0:
            Version : 1.2
      Creation Time : Thu Oct 17 14:41:56 2019
         Raid Level : raid1
         Array Size : 26194944 (24.98 GiB 26.82 GB)
      Used Dev Size : 26194944 (24.98 GiB 26.82 GB)
       Raid Devices : 2
      Total Devices : 2
        Persistence : Superblock is persistent
 

        Update Time : Thu Nov 21 14:51:28 2019
              State : clean 
     Active Devices : 2
    Working Devices : 2
     Failed Devices : 0
      Spare Devices : 0
 

 Consistency Policy : resync
 

               Name : gateway:0  (local to host gateway)
               UUID : d3594f07:7a5321d2:926eb124:704b6115
             Events : 509
 

     Number   Major   Minor   RaidDevice State
        2       8       33        0      active sync   /dev/sdc1
        1       8       17        1      active sync   /dev/sdb1

Kleine Überraschung, Raid ist jetzt auf sdb und sdc, sda ist neu. Manchmal machen die Kisten auch was sie wollen, das muß jetzt nicht so sein, kann auch an der VM liegen. Wichtig ist alleine das man schaut!

sda hat nun offensichtlich keine Partition und muss somit erstmal vorbereitet werden um in den Raidverbund aufgenommen werden zu können.
Dafür nutzen wir fdisk:

gateway: ~ # fdisk /dev/sda
 

 Welcome to fdisk (util-linux 2.33.1).
 Changes will remain in memory only, until you decide to write them.
 Be careful before using the write command.
 

 Device does not contain a recognized partition table.
 Created a new DOS disklabel with disk identifier 0xabca8c50.
 

 Command (m for help): n für neue Partition
 Partition type
    p   primary (0 primary, 0 extended, 4 free)
    e   extended (container for logical partitions)
 Select (default p): enter, p ist ok
 

 Using default response p.
 Partition number (1-4, default 1): enter, 1 ist ok
 First sector (2048-52428799, default 2048): enter
 Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-52428799, default 52428799): enter , ganze Platte
 

 Created a new partition 1 of type 'Linux' and of size 25 GiB. Partitionstabelle type 'Linux' wollen wir nicht
 

 Command (m for help): t für neue Partitionstabelle
 Selected partition 1
 Hex code (type L to list all codes): L ok, zeig
 

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

 Command (m for help): w für schreib das auf die Platte
 The partition table has been altered.
 Calling ioctl() to re-read partition table.
 Syncing disks.
 

 gateway: ~ # 

Jetzt haben wir eine frische Platte mit der Partition Typ Linux Raid die wir wieder als Spare einbinden können. ( INFO: fdisk kann auch Partitionstabellen erstellen, „p“ zeigt den aktuellen Zustand, für unser RAID muss es keine dos Tabelle sein, bzw. ab einer bestimmten Größe geht eine dos Tabelle garnicht mehr ) Test:

gateway: ~ # ls /dev | grep sd
sda
sda1
sdb
sdb1
sdc
sdc1
und jetzt:
gateway: ~ # mdadm --add -a /dev/md0 /dev/sda1
 mdadm: added /dev/sda1
 gateway: ~ # mdadm --detail /dev/md0
 /dev/md0:
            Version : 1.2
      Creation Time : Thu Oct 17 14:41:56 2019
         Raid Level : raid1
         Array Size : 26194944 (24.98 GiB 26.82 GB)
      Used Dev Size : 26194944 (24.98 GiB 26.82 GB)
       Raid Devices : 2
      Total Devices : 3
        Persistence : Superblock is persistent
 

        Update Time : Thu Nov 21 15:10:34 2019
              State : clean 
     Active Devices : 2
    Working Devices : 3
     Failed Devices : 0
      Spare Devices : 1
 

 Consistency Policy : resync
 

               Name : gateway:0  (local to host gateway)
               UUID : d3594f07:7a5321d2:926eb124:704b6115
             Events : 510
 

     Number   Major   Minor   RaidDevice State
        2       8       33        0      active sync   /dev/sdc1
        1       8       17        1      active sync   /dev/sdb1
 

        3       8        1        -      spare   /dev/sda1
 gateway: ~ # 

Entscheidend für dieses Ergebnis ist die Option -a bei mdadm –add. Ohne hätten wir jetzt ein Raid1 mit drei aktiven Platten.


Damit ist das Thema Firewallrouter hier soweit abgehandelt,
– ich hoffe es hat Spaß gemacht.
!