MD software raid & multiple disk failure recovery help script
Hi all,
I just wrote a script runs a brute force attack against a raid5 array
that has had multiple drives removed from an active array.
Yep, that's what I did, and the last resort was (from everywhere I could
find with google) was to use the old mkraid tool if I had a raidtab. I
have been using mdadm for a while now and was not looking forward to
working with the old tools, and modifying the array manually.
This script will take two arguments, the md device, and then a space
separated list of devices that are within the array.
Then it will create a new array (make sure you have one missing drive so
that it doesn't try syncing the disks) with the old disks. What you're
trying to do is find the original disk order, and if you fail multiple
disks, that ordering info is lost AFAIK.
Here[1] are the combinations that would be tried for a four drive raid
array. That's 24 combinations for 4 drives, 120 for 5 drives and a
whopping 720 for 6 drives. I have four drives, but even running the
commands and keeping track of the combinations on paper 24 times is enough.
I developed against ash since I need to be able to run this under
busybox. It just outputs combinations like[1], and doesn't call any
commands in this version. I just need some review of the code for logic
errors and bashisms (which is what I usually write shell scripts against).
I have attached, and pasted[2] the code.
Thanks,
Mike
[1]
sda3 sdb3 sdc3 sdd3
sda3 sdb3 sdd3 sdc3
sda3 sdc3 sdd3 sdb3
sda3 sdc3 sdb3 sdd3
sda3 sdd3 sdb3 sdc3
sda3 sdd3 sdc3 sdb3
sdb3 sdc3 sdd3 sda3
sdb3 sdc3 sda3 sdd3
sdb3 sdd3 sda3 sdc3
sdb3 sdd3 sdc3 sda3
sdb3 sda3 sdc3 sdd3
sdb3 sda3 sdd3 sdc3
sdc3 sdd3 sda3 sdb3
sdc3 sdd3 sdb3 sda3
sdc3 sda3 sdb3 sdd3
sdc3 sda3 sdd3 sdb3
sdc3 sdb3 sdd3 sda3
sdc3 sdb3 sda3 sdd3
sdd3 sda3 sdb3 sdc3
sdd3 sda3 sdc3 sdb3
sdd3 sdb3 sdc3 sda3
sdd3 sdb3 sda3 sdc3
sdd3 sdc3 sda3 sdb3
sdd3 sdc3 sdb3 sda3
[2]
#!/bin/ash
set -e
#set -x
rotate() {
local last_var=$1
shift
echo $@ $last_var
}
rotate_part() {
local no_rotate=""
local r_to_shift=$1
shift
while [ $r_to_shift -gt 0 ]; do
no_rotate="${no_rotate# }$1 "
shift
r_to_shift=$(( $r_to_shift - 1 ))
done
echo "$no_rotate$(rotate $@)"
}
do_it() {
local shift_factor="$1"
shift
local my_partitions="$@"
local d_shift=$(( $num_drives - $shift_factor ))
if [ $shift_factor -lt $(( $num_drives - 1 )) ]; then
while [ 0 -lt $d_shift ]; do
do_it $(( $shift_factor + 1 )) "$my_partitions"
my_partitions=$(rotate_part $shift_factor $my_partitions)
d_shift=$(( $d_shift - 1 ))
done
else
echo "$my_partitions"
fi
}
#partitions="missing disc0/part2 disc2/part2 disc3/part2"
array_dev=$1
shift
partitions=$@
num_drives=0
for i in $partitions; do
num_drives=$(( $num_drives + 1 ))
done
do_it 0 "$partitions"
Reply to: