Skip to content

Commit 2d341c7

Browse files
stendulkerjimrollenhagen
authored andcommitted
Fixes config drive creation failure in UEFI boot mode
This fix enables creation of config drive for UEFI only whole disk images. It will not work with the hybrid images that support booting in BIOS and UEFI boot mode. Change-Id: Ib4dd8c082a50e1dbaf0df91477b062716cb780ff Closes-Bug: #1486887 Depends-On: I81400305f166d62aa4612aab54602abb8178b64c
1 parent 19d21eb commit 2d341c7

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN echo 'APT::Default-Release "jessie";' > /etc/apt/apt.conf.d/10default && \
1313
# image on disk
1414
RUN apt-get update && \
1515
apt-get -y upgrade && \
16-
apt-get install -y --no-install-recommends python2.7 python2.7-dev \
16+
apt-get install -y --no-install-recommends gdisk python2.7 python2.7-dev \
1717
python-pip qemu-utils parted hdparm util-linux genisoimage git gcc \
1818
bash coreutils tgt dmidecode ipmitool && \
1919
apt-get --only-upgrade -t testing install -y qemu-utils

ironic_python_agent/shell/copy_configdrive_to_disk.sh

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ usage() {
3535
exit 1
3636
}
3737

38+
MAX_DISK_PARTITIONS=128
39+
3840
CONFIGDRIVE="$1"
3941
DEVICE="$2"
4042

@@ -57,13 +59,41 @@ if [[ $? == 0 ]]; then
5759
log "Existing configdrive found on ${DEVICE} at ${EXISTING_PARTITION}"
5860
ISO_PARTITION=$EXISTING_PARTITION
5961
else
60-
# Create small partition at the end of the device
61-
log "Adding configdrive partition to $DEVICE"
62-
parted -a optimal -s -- $DEVICE mkpart primary ext2 -64MiB -0 || fail "creating configdrive on ${DEVICE}"
6362

64-
# Find partition we just created
65-
# Dump all partitions, ignore empty ones, then get the last partition ID
66-
ISO_PARTITION=`sfdisk --dump $DEVICE | grep -v ' 0,' | tail -n1 | awk '{print $1}'` || fail "finding ISO partition created on ${DEVICE}"
63+
# Check if it is GPT partition and needs to be re-sized
64+
partprobe $DEVICE print 2>&1 | grep "fix the GPT to use all of the space"
65+
if [[ $? == 0 ]]; then
66+
log "Fixing GPT to use all of the space on device $DEVICE"
67+
sgdisk -e $DEVICE || fail "move backup GPT data structures to the end of ${DEVICE}"
68+
69+
# Need to create new partition for config drive
70+
# Not all images have partion numbers in a sequential numbers. There are holes.
71+
# These holes get filled up when a new partition is created.
72+
TEMP_DIR="$(mktemp -d)"
73+
EXISTING_PARTITION_LIST=$TEMP_DIR/existing_partitions
74+
UPDATED_PARTITION_LIST=$TEMP_DIR/updated_partitions
75+
76+
gdisk -l $DEVICE | grep -A$MAX_DISK_PARTITIONS "Number Start" | grep -v "Number Start" > $EXISTING_PARTITION_LIST
77+
78+
# Create small partition at the end of the device
79+
log "Adding configdrive partition to $DEVICE"
80+
sgdisk -n 0:-64MB:0 $DEVICE || fail "creating configdrive on ${DEVICE}"
81+
82+
gdisk -l $DEVICE | grep -A$MAX_DISK_PARTITIONS "Number Start" | grep -v "Number Start" > $UPDATED_PARTITION_LIST
83+
84+
CONFIG_PARTITION_ID=`diff $EXISTING_PARTITION_LIST $UPDATED_PARTITION_LIST | tail -n1 |awk '{print $2}'`
85+
ISO_PARTITION="${DEVICE}${CONFIG_PARTITION_ID}"
86+
else
87+
log "Working on MBR only device $DEVICE"
88+
89+
# Create small partition at the end of the device
90+
log "Adding configdrive partition to $DEVICE"
91+
parted -a optimal -s -- $DEVICE mkpart primary ext2 -64MiB -0 || fail "creating configdrive on ${DEVICE}"
92+
93+
# Find partition we just created
94+
# Dump all partitions, ignore empty ones, then get the last partition ID
95+
ISO_PARTITION=`sfdisk --dump $DEVICE | grep -v ' 0,' | tail -n1 | awk '{print $1}'` || fail "finding ISO partition created on ${DEVICE}"
96+
fi
6797
fi
6898

6999
# This writes the ISO image to the config drive.

0 commit comments

Comments
 (0)