scripting mdadm when a component device may contain ext2 file system already

Have you tried piping in the output of the standard Unix/Linux "yes" command?

yes | sudo mdadm ...options and arguments...

Only use this if you know that you want to answer "yes" to any question mdadm might ask you.

The above is the approach I used in my sample mdadm commands to set up a 40 TB file system using RAID-0 EBS volumes: https://alestic.com/2009/06/ec2-ebs-raid/


I run a script on start-up of a m1.large and m1.xlarge instances that performs the disc-stripping (RAID-0). Here is a simplified version (assuming it's m1.large):

echo "Unmounting /mnt..."
/bin/umount /mnt

echo "Creating RAID0 volume..."
/usr/bin/yes|/sbin/mdadm --create /dev/md0 --level=0 -c256 --raid-devices=2 /dev/sdb /dev/sdc
echo 'DEVICE /dev/sdb /dev/sdc' > /etc/mdadm.conf
/sbin/mdadm --detail --scan >> /etc/mdadm.conf

echo "Creating file-system..."
/sbin/blockdev --setra 65536 /dev/md0
mkfs.xfs -f /dev/md0

echo "Mounting the device /dev/md0 to /mnt..."
/bin/mount -t xfs -o noatime /dev/md0 /mnt

echo "Registering in fstab.."
/bin/mv /etc/fstab /etc/fstab.orig
/bin/sed '/\/mnt/ c /dev/md0  /mnt  xfs    defaults 0 0' < /etc/fstab.orig > /etc/fstab

To answer your question, as already mentioned, you can just pipe yes