Files
ironic-python-agent/ironic_python_agent/shell/copy_configdrive_to_disk.sh
Jim Rollenhagen 3c1d52cbb1 Use # instead of """ for copyright blocks
Reformats copyright messages to be comments rather than
docstring-style blocks.

Change-Id: I4d863f53b67bb49d03bda0952b9e6179b6d23c59
2014-04-10 07:14:06 -07:00

61 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Copyright 2013 Rackspace, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
log() {
echo "`basename $0`: $@"
}
usage() {
[[ -z "$1" ]] || echo -e "USAGE ERROR: $@\n"
echo "`basename $0`: CONFIGDRIVE_DIR DEVICE"
echo " - This script injects CONFIGDRIVE_DIR contents as an iso9660"
echo " filesystem on a partition at the end of DEVICE."
exit 1
}
CONFIGDRIVE_DIR="$1"
DEVICE="$2"
[[ -d $CONFIGDRIVE_DIR ]] || usage "$CONFIGDRIVE_DIR (CONFIGDRIVE_DIR) is not a directory"
[[ -b $DEVICE ]] || usage "$DEVICE (DEVICE) is not a block 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}'`
# This generates the ISO image of the config drive.
log "Writing Configdrive contents in $CONFIGDRIVE_DIR to $ISO_PARTITION"
genisoimage \
-o ${ISO_PARTITION} \
-ldots \
-input-charset 'utf-8' \
-allow-lowercase \
-allow-multidot \
-l \
-publisher "ironic" \
-J \
-r \
-V 'config-2' \
${CONFIGDRIVE_DIR}
log "${DEVICE} imaged successfully!"