Skip to content

Instantly share code, notes, and snippets.

@agarstang
Created February 27, 2017 15:26
Show Gist options
  • Save agarstang/ad1a9ad296f6a533db1c3cd22559dd81 to your computer and use it in GitHub Desktop.
Save agarstang/ad1a9ad296f6a533db1c3cd22559dd81 to your computer and use it in GitHub Desktop.
Bash UserData format additional disks
for device in $(lsblk -ln -o NAME | grep -Ev '^xvda\d*')
do
blkdevice="/dev/$device"
echo "Removing any pre-existing mount points for $blkdevice"
umount -f $blkdevice
sed -i "/^\/dev\/$device/d" /etc/fstab
echo "Checking if $blkdevice is formatted.."
/sbin/blkid -t TYPE=ext4 $blkdevice || (echo "Formatting $blkdevice" && /sbin/mkfs.ext4 $blkdevice)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment