Merge pull request #30 from rackerlabs/jay/FixMakefsScript

Fixes and logging for makefs script
This commit is contained in:
Jason Faulkner 2014-01-22 15:26:45 -08:00
commit e25f5dd4ce

View File

@ -5,6 +5,10 @@
set -e
log() {
echo "`basename $0`: $@"
}
usage() {
[[ -z "$1" ]] || echo -e "USAGE ERROR: $@\n"
echo "`basename $0`: CONFIGDRIVE_DIR IMAGEFILE DEVICE"
@ -24,18 +28,23 @@ DEVICE="$3"
# In production this will be replaced with secure erasing the drives
# For now we need to ensure there aren't any old (GPT) partitions on the drive
log "Erasing existing mbr from ${DEVICE}"
dd if=/dev/zero of=$DEVICE bs=512 count=10
# Converts image to raw and writes to device
log "Imaging $IMAGEFILE onto $DEVICE"
qemu-img convert -O raw $IMAGEFILE $DEVICE
# Create small partition at the end of the device
log "Adding configdrive partition to $DEVICE"
parted -a optimal -s -- $DEVICE mkpart primary ext2 -16MiB -0
# Find partition we just created
# Dump all partitions, ignore empty ones, then get the last partition ID
ISO_PARTITION=`sfdisk --dump $DEVICE | grep -v '0,' | tail -n1 | awk '{print $1}'`
ISO_PARTITION=`sfdisk --dump $DEVICE | grep -v ' 0,' | tail -n1 | awk '{print $1}'`
# This generates the ISO image of the config drive.
log "Writing Configdrive contents in $CONFIGDRIVE_DIR to $ISO_PARTITION"
genisoimage \
-o ${ISO_PARTITION} \
-ldots \
@ -48,3 +57,5 @@ genisoimage \
-r \
-V 'config-2' \
${CONFIGDRIVE_DIR}
log "${DEVICE} imaged successfully!"