Skip to content

Instantly share code, notes, and snippets.

@darkpixel
Created June 25, 2016 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darkpixel/989dc8978f9c5b09bc8c678b7b148275 to your computer and use it in GitHub Desktop.
Save darkpixel/989dc8978f9c5b09bc8c678b7b148275 to your computer and use it in GitHub Desktop.
iterdrives.py
import probstat, os, sys, popen2
# List of partitions possibly used in the array
li = ['/dev/hde1', '/dev/hdg1', '/dev/hdi1', '/dev/hdk1', '/dev/sdc1', '/dev/sdd1', '/dev/sde1', '/dev/sdf1']
# Assemble = Number of Devices in Array - Number of Parity Drives
# RAID 6 uses 2 parity drives. So for an array of 10 partitions in RAID 6
# you would set assemble to 8
assemble = 5
# Number of drives used for pairty. RAID 5 uses 1, RAID 6 uses 2
parity = 2
# The total number of devices in the raid array
devices = assemble + parity
total = 0
count = 0
for combo in probstat.Permutation(li,assemble):
total = total + 1
for combo in probstat.Permutation(li,assemble):
print "Combo %s/%s" %(count,total)
count = count + 1
drivelist = ""
for drive in combo:
drivelist = drivelist + drive + " "
mdcmd = "mdadm --create --raid-devices=%s --level=6 --assume-clean /dev/md0 %s missing missing" %(devices,drivelist)
mdproc = os.popen(mdcmd, 'w')
mdproc.write("yes\n")
print mdproc.close()
print "cmd: %s return:" %(mdcmd)
mntcmd = "mount -t ext3 -o ro /dev/md0 /mnt"
mntproc = os.popen(mntcmd)
if mntproc.close() == 0:
print "WE GOT IT: %s" %(mdcmd)
sys.exit()
else:
print "Nope!"
mdcmd = "mdadm --stop /dev/md0"
mdproc = os.popen(mdcmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment