I want to script the striping of the two ephemeral storage devices on m1.large EC2 instances using mdadm (apparently amis don't always include device information, so i can't just create a new ami once the array is started).
The problem is, ephemeral storage on EC2 instances generally comes preformatted with a file system, causing mdadm to say:
mdadm: /dev/sdb appears to contain an ext2fs file system
size=440366080K mtime=Mon Jan 2 20:32:06 2012
mdadm: /dev/sdc appears to contain an ext2fs file system
size=440366080K mtime=Wed Dec 31 19:00:00 1969
Continue creating array?
And wait for input. I'm sure there's a way to auto answer yes for these types of prompts in mdadm for non interactive situations (like in fsck -y for example) but I can't seem to figure it out (it's not --force). I know I could just zero out the devices using dd but that seems a rather sledgehammer-ey solution to something I'm sure is easily done.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With