Skip to content

Instantly share code, notes, and snippets.

@nuriel77
Last active December 9, 2016 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nuriel77/c88538f69ee3f37e7398c62ef0f4ac13 to your computer and use it in GitHub Desktop.
Save nuriel77/c88538f69ee3f37e7398c62ef0f4ac13 to your computer and use it in GitHub Desktop.
heat_template_version: 2014-10-16
description: >
Wipe and convert all disks to GPT (except the disk containing the root file system)
resources:
userdata:
type: OS::Heat::MultipartMime
properties:
parts:
- config: {get_resource: wipe_disk}
wipe_disk:
type: OS::Heat::SoftwareConfig
properties:
config: {get_file: wipe-disk.sh}
outputs:
OS::stack_id:
value: {get_resource: userdata}
#!/bin/bash
NRDISKS=$(lsblk -no NAME,TYPE,MOUNTPOINT | grep "disk" | awk '{print $1}' | wc -l)
/bin/logger -t DISKWIPE "Number of disks detected: $NRDISKS"
for DEVICE in $(lsblk -no NAME,TYPE,MOUNTPOINT | grep "disk" | awk '{print $1}')
do
ROOTFOUND=0
/bin/logger -t DISKWIPE "Checking /dev/$DEVICE..."
NRPARTITIONS=$(expr $(lsblk -n /dev/$DEVICE | awk '{print $7}' | wc -l) - 1)
/bin/logger -t DISKWIPE "Number of partitions on /dev/${DEVICE}: $NRPARTITIONS"
for MOUNTS in $(lsblk -n /dev/$DEVICE | awk '{print $7}')
do
if [ "$MOUNTS" = "/" ]
then
ROOTFOUND=1
fi
done
if [ $ROOTFOUND = 0 ]
then
/bin/logger -t DISKWIPE "Root not found in /dev/${DEVICE}"
/bin/logger -t DISKWIPE "Wiping disk /dev/${DEVICE}"
sgdisk -Z /dev/${DEVICE}
sgdisk -g /dev/${DEVICE}
else
/bin/logger -t DISKWIPE "Root found in /dev/${DEVICE}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment