linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Automatically adding spares on boot
@ 2013-01-09 17:09 Can Jeuleers
  2013-01-19  8:23 ` Can Jeuleers
  2013-01-19 18:27 ` Roy Sigurd Karlsbakk
  0 siblings, 2 replies; 8+ messages in thread
From: Can Jeuleers @ 2013-01-09 17:09 UTC (permalink / raw)
  To: linux-raid@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 537 bytes --]

Hi,

Over the years I've had various problems with the degree to which the
adding of spares on boot is automatic. There have been times when this
has just worked, and other times (such as now) where it only works very
occasionally (or not at all). Google is full of stories like this.

I have no clue why it's not working automatically, I just know that it
isn't.

So I wrote a little script that automates this, and hooked it up to
mdmon as an event handler.

It can probably do with an elegance upgrade, but it works for me.

HTH, Jan

[-- Attachment #2: mdmon_eventhandler --]
[-- Type: text/plain, Size: 1455 bytes --]

#!/bin/bash
# mdadm --monitor event handler, by Jan Ceuleers
# Licence: GPL v2
# Handles SparesMissing event. Uses blkid output to find devices that have
# the same UUID as the RAID device, but which are not yet members of the array.
# Have this script executed by mdadm by passing its name to the mdadm --monitor
# daemon using the --program parameter.
# On Debian-like systems this can be accomplished like so:
#   echo "DAEMON_OPTIONS=\"\$DAEMON_OPTIONS --program /pathto/script\"" >> /etc/default/mdadm

BLKID="/sbin/blkid"
MDADM="/sbin/mdadm"

(
  case $1 in
    SparesMissing)
      COMPUUID=`$MDADM  -D $2 | grep UUID | cut -f 2 -d 'D' | cut -f 3 -d ' '`
      COMPUUID2=${COMPUUID//:/}
      COMPUUID3=${COMPUUID2:0:8}-${COMPUUID2:8:4}-${COMPUUID2:12:4}-${COMPUUID2:16:4}-${COMPUUID2:20}
      echo The UUID of component devices is $COMPUUID \($COMPUUID3\)
      blkid | grep $COMPUUID3 | grep linux_raid_member | (
        while read l; do
          COMPDEV=`echo $l | cut -f 1 -d ':'`
          $MDADM -D $2 | grep $COMPDEV > /dev/null
          if [ $? -eq 0 ] ; then
            echo Device $COMPDEV is already a member of the array
          else
            echo Found device $COMPDEV with the same UUID but not yet a component device.
            $MDADM $2 --add $COMPDEV 2>&1
          fi
        done
      )
      ;;
    *)
      echo "Unknown event type; can't handle."
      ;;
  esac

) | mail -s "Handling $1 mdadm event on $2" root

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-01-20 12:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-09 17:09 Automatically adding spares on boot Can Jeuleers
2013-01-19  8:23 ` Can Jeuleers
2013-01-19 18:27 ` Roy Sigurd Karlsbakk
2013-01-19 18:41   ` Can Jeuleers
2013-01-20 11:51     ` Roy Sigurd Karlsbakk
2013-01-20 12:00       ` Can Jeuleers
2013-01-20 12:21         ` Roy Sigurd Karlsbakk
2013-01-20 12:29           ` Can Jeuleers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).