3

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.

Johnny C
  • 1,799
  • 1
  • 16
  • 27

2 Answers2

11

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/

Eric Hammond
  • 22,089
  • 5
  • 66
  • 75
  • 1
    Thanks. I'm not exactly sure why this was closed as bash scripting is certainly programming. Even if it relates more to system administration generally. But thanks for your answer. – Johnny C Jan 08 '12 at 23:55
  • 7
    Or just pass --run or -R to mdadm. – Hannes Apr 25 '15 at 02:08
  • 1
    +1 to Hannes' comment. According to the man page: -R, --run Insist that mdadm run the array, even if some of the components appear to be active in another array or filesystem. Normally mdadm will ask for confirmation before including such components in an array. This option causes that question to be sup‐ pressed. – Loisaida Sam Sandberg Jan 23 '18 at 01:15
  • System administration questions generally belong on Server Fault. – JGurtz Oct 23 '20 at 07:58
1

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

Nishant
  • 54,584
  • 13
  • 112
  • 127