-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mr_replace.sh mr_remove.sh mr_add.sh
- Loading branch information
Showing
3 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [ "$#" -ne "4" ]; then | ||
echo "$0: <MAP> <NAME> <RAIDDEV> <DIMG>" | ||
exit 1 | ||
fi | ||
|
||
MAP="$1" | ||
NAME="$2" | ||
RAIDDEV="$3" | ||
NEWDIMG="$4" | ||
|
||
if [ `id -u` -ne "0" ]; then | ||
echo "Got Root?" | ||
exit 2 | ||
fi | ||
|
||
if [ ! -r ${MAP} ]; then | ||
echo "${MAP} is not readable!" | ||
exit 3 | ||
fi | ||
|
||
if [ ! -b ${RAIDDEV} ]; then | ||
echo "${RAIDDEV} is not a block device!" | ||
exit 4 | ||
fi | ||
|
||
if [ ! -f ${NEWDIMG} ]; then | ||
echo "${NEWDIMG} is not a file!" | ||
exit 5 | ||
fi | ||
|
||
LOBIN=`PATH="/sbin:/usr/sbin:$PATH" which losetup` | ||
if [ "$?" != "0" ]; then | ||
echo "losetup not found!" | ||
exit 6 | ||
fi | ||
|
||
MDBIN=`PATH="/sbin:/usr/sbin:$PATH" which mdadm` | ||
if [ "$?" != "0" ]; then | ||
echo "mdadm not found!" | ||
exit 7 | ||
fi | ||
|
||
echo "Attaching ${NEWDIMG} ..." | ||
NEWLOOP=`${LOBIN} --find --show ${NEWDIMG}` | ||
${MDBIN} ${RAIDDEV} --add-spare ${NEWLOOP} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [ "$#" -ne "4" ]; then | ||
echo "$0: <MAP> <NAME> <RAIDDEV> <LOOP>" | ||
exit 1 | ||
fi | ||
|
||
MAP="$1" | ||
NAME="$2" | ||
RAIDDEV="$3" | ||
FLOOP="$4" | ||
|
||
if [ `id -u` -ne "0" ]; then | ||
echo "Got Root?" | ||
exit 2 | ||
fi | ||
|
||
if [ ! -r ${MAP} ]; then | ||
echo "${MAP} is not readable!" | ||
exit 3 | ||
fi | ||
|
||
if [ ! -b ${RAIDDEV} ]; then | ||
echo "${RAIDDEV} is not a block device!" | ||
exit 4 | ||
fi | ||
|
||
if [ ! -b ${FLOOP} ]; then | ||
echo "${FLOOP} is not a block device!" | ||
exit 5 | ||
fi | ||
|
||
MDBIN=`PATH="/sbin:/usr/sbin:$PATH" which mdadm` | ||
if [ "$?" != "0" ]; then | ||
echo "mdadm not found!" | ||
exit 5 | ||
fi | ||
|
||
LOBIN=`PATH="/sbin:/usr/sbin:$PATH" which losetup` | ||
if [ "$?" != "0" ]; then | ||
echo "losetup not found!" | ||
exit 6 | ||
fi | ||
|
||
# Set faulty and remove from the array | ||
# unless it has already been removed | ||
if ${MDBIN} --detail ${RAIDDEV} | grep -qw ${FLOOP}; then | ||
${MDBIN} ${RAIDDEV} -f ${FLOOP} | ||
${MDBIN} ${RAIDDEV} -r ${FLOOP} | ||
fi | ||
|
||
# Detach the faulty loop | ||
echo "Detaching ${FLOOP} ..." | ||
${LOBIN} -d ${FLOOP} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/bin/bash | ||
|
||
SCRIPTDIR=`dirname $0` | ||
REMOVESCRIPT="${SCRIPTDIR}/mr_remove.sh" | ||
ADDSCRIPT="${SCRIPTDIR}/mr_add.sh" | ||
set -e | ||
|
||
if [ "$#" -ne "4" ]; then | ||
echo "$0: <MAP> <NAME> <RAIDDEV> [FILE|LOOP]" | ||
exit 1 | ||
fi | ||
|
||
MAP="$1" | ||
NAME="$2" | ||
RAIDDEV="$3" | ||
|
||
if [ `id -u` -ne "0" ]; then | ||
echo "Got Root?" | ||
exit 2 | ||
fi | ||
|
||
if [ ! -r ${MAP} ]; then | ||
echo "${MAP} is not readable!" | ||
exit 3 | ||
fi | ||
|
||
if [ ! -b ${RAIDDEV} ]; then | ||
echo "${RAIDDEV} is not a block device!" | ||
exit 4 | ||
fi | ||
|
||
LOBIN=`PATH="/sbin:/usr/sbin:$PATH" which losetup` | ||
if [ "$?" != "0" ]; then | ||
echo "losetup not found!" | ||
exit 5 | ||
fi | ||
|
||
if [ -b "$4" ]; then | ||
LOOP="$4" | ||
FDIMG=`${LOBIN} -a | grep -w ${LOOP} | cut -d\( -f2 | cut -d\) -f1` | ||
elif [ -f "$4" ]; then | ||
FDIMG="$4" | ||
LOOP=`${LOBIN} -a | grep -w ${FDIMG} | cut -d: -f1` | ||
else | ||
echo "I dont know what to do with $4" | ||
exit 6 | ||
fi | ||
|
||
if [ ! -b "${LOOP}" ]; then | ||
echo "${LOOP} is not a block device!" | ||
exit 7 | ||
fi | ||
|
||
if [ ! -r "${FDIMG}" ]; then | ||
echo "${FDIMG} is not readable!" | ||
exit 8 | ||
fi | ||
|
||
echo "Replacing Faulty Disk Image: ${FDIMG} (${LOOP}) ..." | ||
echo "Continue? (y/N)" | ||
read ANS | ||
echo | ||
|
||
# Why can't I use -a here on ubuntu?? | ||
if [ "${ANS}" != "y" ] && [ "${ANS}" != "Y" ]; then | ||
echo "Patiently awaiting your orders." | ||
exit 0 | ||
fi | ||
|
||
${REMOVESCRIPT} ${MAP} ${NAME} ${RAIDDEV} ${LOOP} | ||
|
||
echo | ||
BYTES=`ls -l ${FDIMG} | awk '{print $5}' | sort -u | head -n1` | ||
mv ${FDIMG} ${FDIMG}.bad | ||
#dd if=/dev/zero of=${FDLOC}/${FDIMG} bs=4096 count=0 seek=1024 | ||
#dd if=/dev/zero of=${FDLOC}/${FDIMG} bs=1 count=0 seek=4194304 | ||
echo "Creating new disk image: ${FDIMG}" | ||
dd if=/dev/zero of=${FDIMG} bs=1 count=${BYTES} | ||
echo | ||
|
||
${ADDSCRIPT} ${MAP} ${NAME} ${RAIDDEV} ${FDIMG} |