linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Can Jeuleers <can.jeuleers@gmail.com>
To: "linux-raid@vger.kernel.org" <linux-raid@vger.kernel.org>
Subject: Automatically adding spares on boot
Date: Wed, 09 Jan 2013 18:09:05 +0100	[thread overview]
Message-ID: <50EDA431.1090905@gmail.com> (raw)

[-- 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

             reply	other threads:[~2013-01-09 17:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-09 17:09 Can Jeuleers [this message]
2013-01-19  8:23 ` Automatically adding spares on boot 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50EDA431.1090905@gmail.com \
    --to=can.jeuleers@gmail.com \
    --cc=linux-raid@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).