diff --git a/teeth_agent/shell/makefs.sh b/teeth_agent/shell/makefs.sh index c3c8a0981..97ec8e09d 100755 --- a/teeth_agent/shell/makefs.sh +++ b/teeth_agent/shell/makefs.sh @@ -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!"