Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How can I pause execution of my shell script after calling the following command until the raid array has been assembled? From what I understand, this is an asynchronous process and status of the raid array needs to be polled.

mdadm --create -l10 -n4 /dev/md0 /dev/xvdh*

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Since you're creating a new RAID 10, you can begin using the array immediately. The initial resync will continue in the background. You only need to wait for it to complete if building a RAID 5 array (and it's a good idea for a RAID 6, too).

See Initial Array Creation in the Linux RAID Wiki for further details.

share|improve this answer
add comment

Edit Sat Oct 27 17:03:42 CDT 2012:

While it's true that you can work with the RAID 10 array before it's finished re syncing, I figured that I would answer the question about how to pause during the re-sync process anyway.

This is how you pause the script for the re-syncing process (IMO/AFAIK/etc.):

# Add this where you want to pause...
while [ -n "$(mdadm --detail /dev/md0 | grep -ioE 'State :.*resyncing')" ]; do
    sleep 1
done

To use the example above, the whole script would be:

mdadm --create -l10 -n4 /dev/md0 /dev/xvdh*

while [ -n "$(mdadm --detail /dev/md0 | grep -ioE 'State :.*resyncing')" ]; do
    sleep 1
done

mke2fs -t ext4 -F /dev/md0

Please note that the above script is not tested and may contain bugs.

share|improve this answer
    
thanks. that works for the mke2fs command. but the raid array being built is an asynchronous process. the command "mdadm --detail /dev/md0" is used to query the status. –  VinnyD Oct 27 '12 at 19:26
    
i updated my question to clarify what I'm asking. –  VinnyD Oct 27 '12 at 21:44
    
@VinnyD Oh, then this becomes a bit more complex. Please post an example of what mdadm --detail /dev/md0 says while you want it paused. –  Soviero Oct 27 '12 at 21:52
    
thanks for your help :) the response below answers my question. –  VinnyD Oct 27 '12 at 22:10
    
@VinnyD See latest edit... –  Soviero Oct 27 '12 at 22:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.