2

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*

2 Answers 2

1

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.

3

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.

5
  • 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, 2012 at 19:26
  • i updated my question to clarify what I'm asking.
    – VinnyD
    Oct 27, 2012 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, 2012 at 21:52
  • thanks for your help :) the response below answers my question.
    – VinnyD
    Oct 27, 2012 at 22:10
  • @VinnyD See latest edit...
    – Soviero
    Oct 27, 2012 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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