Skip to content

Instantly share code, notes, and snippets.

@dictvm
Created October 13, 2017 16:11
Show Gist options
  • Save dictvm/d291403b84bb601c3af8d4711344aa61 to your computer and use it in GitHub Desktop.
Save dictvm/d291403b84bb601c3af8d4711344aa61 to your computer and use it in GitHub Desktop.
dirty auto-format/-mount for EBS blockdevices, useful for Terraform-users
#!/bin/sh
fstab_string='/dev/xvdh /mnt/data ext4 defaults,nofail,nobootwait 0 2'
configure()
{
echo "Start a service in here, fix permissions or whatever"
}
# Wait for EBS volume to appear
while [ ! -e /dev/xvdh ]; do sleep 1; done
# Check if device is formatted already
lsblk --output FSTYPE,KNAME | grep "ext4 xvdh"
if [ $? -eq 0 ]
then
echo "Device already formatted."
else
mkfs.ext4 /dev/xvdh >&2
fi
while [ ! -d /mnt/data ]; do configure; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment