Skip to content

Commit a7d6865

Browse files
committed
Allow configdrive partition to be precreated
This adds support for copying configdrives to disks that already have partitions enabled and labeled for configdrives. This is neccessary for supporting configdrives on partitioning schemes we don't support yet (like GPT) or for some future agent iteration where we create partitions separately. Change-Id: Iee5b87d82be08febc495aaef3272ced4f2f32235
1 parent 59d6523 commit a7d6865

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

ironic_python_agent/shell/copy_configdrive_to_disk.sh

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,21 @@ DEVICE="$2"
3434
[[ -f $CONFIGDRIVE ]] || usage "$CONFIGDRIVE (CONFIGDRIVE) is not a regular file"
3535
[[ -b $DEVICE ]] || usage "$DEVICE (DEVICE) is not a block device"
3636

37-
# Create small partition at the end of the device
38-
log "Adding configdrive partition to $DEVICE"
39-
parted -a optimal -s -- $DEVICE mkpart primary ext2 -64MiB -0
40-
41-
# Find partition we just created
42-
# Dump all partitions, ignore empty ones, then get the last partition ID
43-
ISO_PARTITION=`sfdisk --dump $DEVICE | grep -v ' 0,' | tail -n1 | awk '{print $1}'`
44-
45-
# This generates the ISO image of the config drive.
37+
# Check for preexisting partition for configdrive
38+
EXISTING_PARTITION=`/sbin/blkid -l -o device $DEVICE -t LABEL=config-2`
39+
if [[ $? == 0 ]]; then
40+
ISO_PARTITION=$EXISTING_PARTITION
41+
else
42+
# Create small partition at the end of the device
43+
log "Adding configdrive partition to $DEVICE"
44+
parted -a optimal -s -- $DEVICE mkpart primary ext2 -64MiB -0
45+
46+
# Find partition we just created
47+
# Dump all partitions, ignore empty ones, then get the last partition ID
48+
ISO_PARTITION=`sfdisk --dump $DEVICE | grep -v ' 0,' | tail -n1 | awk '{print $1}'`
49+
fi
50+
51+
# This writes the ISO image to the config drive.
4652
log "Writing Configdrive contents in $CONFIGDRIVE to $ISO_PARTITION"
4753
dd if=$CONFIGDRIVE of=$ISO_PARTITION bs=64K oflag=direct
4854

0 commit comments

Comments
 (0)