Merge "miniboot: Support persistent_size install value in debian"

This commit is contained in:
Zuul 2022-09-08 19:01:55 +00:00 committed by Gerrit Code Review
commit e62739ed7f

View File

@ -136,12 +136,22 @@ function elog()
echo "\$dt kickstart \${HOOK_LABEL} error: \$1" >>\${LOGFILE} echo "\$dt kickstart \${HOOK_LABEL} error: \$1" >>\${LOGFILE}
} }
########################################################################
# Name : report_failure_with_msg
# Purpose : Report installation error, offer a console and
# reboot on exit.
# Parameters: \$1 is the failure message string
# Return : Does not return
########################################################################
function report_failure_with_msg() function report_failure_with_msg()
{ {
local msg=\${1} local msg=\${1}
echo -e '\n\nInstallation failed.\n' echo -e '\n\nInstallation failed.\n'
wlog "Installation Failed: ERROR: \${msg}" wlog "Installation Failed: ERROR: \${msg}"
exit 1 echo "... dropping to shell ; exit to reboot ..."
sleep 1
bash
reboot -f
} }
######################################################################## ########################################################################
@ -616,7 +626,8 @@ function setup_ip_addr()
ip \${ipver} link set dev \${bootif} up ip \${ipver} link set dev \${bootif} up
echo ip \${ipver} route add default \${route_options} dev \${bootif} \${metric} echo ip \${ipver} route add default \${route_options} dev \${bootif} \${metric}
ip \${ipver} route add default \${route_options} dev \${bootif} \${metric} ip \${ipver} route add default \${route_options} dev \${bootif} \${metric}
ilog "Wait 10s to settle interface..."
sleep 10
ilog "ip addr:" ilog "ip addr:"
ip addr show ip addr show
ilog "ip route:" ilog "ip route:"
@ -719,8 +730,7 @@ export debug=0
export PLATFORM_BACKUP_SIZE=${DEFAULT_PERSISTENT_SIZE} export PLATFORM_BACKUP_SIZE=${DEFAULT_PERSISTENT_SIZE}
# Assume there is no Platform Backup (persistent) Partition # Assume there is no Platform Backup (persistent) Partition
export BACKUP_CREATED=0 export BACKUP_PARTITION_EXISTS=0
export BACKUP_PERSISTED=0
# Platform Backup Partition Info # Platform Backup Partition Info
export BACKUP_PART_FIRST=0 export BACKUP_PART_FIRST=0
@ -728,6 +738,7 @@ export BACKUP_PART_END=0
export BACKUP_PART_SIZE=0 export BACKUP_PART_SIZE=0
export BACKUP_PART_FLAGS=0 export BACKUP_PART_FLAGS=0
export BACKUP_PART_NAME="" export BACKUP_PART_NAME=""
export CURRENT_BACKUP_PARTITION_SIZE=0
export STOR_DEV_FDS="$(ls -1 /proc/$$/fd | egrep -v "^(0|1|2|255)$" | xargs)" export STOR_DEV_FDS="$(ls -1 /proc/$$/fd | egrep -v "^(0|1|2|255)$" | xargs)"
@ -1158,11 +1169,21 @@ do
# ISSUE: ERIK: These are never the same when the by-path INSTDEV is used. # ISSUE: ERIK: These are never the same when the by-path INSTDEV is used.
# dev = /dev/sda INSTDEV = by path string # dev = /dev/sda INSTDEV = by path string
ilog "Checking platform-backup partition ... $dev : ${INSTDEV} ${by_dev}" ilog "Checking platform-backup partition, dev:$dev INSTDEV:${INSTDEV} by_dev:${by_dev}"
sgdisk_part_info=$(sgdisk -i $part_number $dev) sgdisk_part_info=$(sgdisk -i $part_number $dev)
# Example output:
# sysadmin@localhost:~$ sudo sgdisk -i 6 /dev/sda
# Partition GUID code: BA5EBA11-0000-1111-2222-000000000002 (Unknown)
# Partition unique GUID: AECCE1DD-2946-4ED7-9125-94E2D78EA8D8
# First sector: 85004288 (at 40.5 GiB)
# Last sector: 150540287 (at 71.8 GiB)
# Partition size: 65536000 sectors (31.3 GiB)
# Attribute flags: 0000000000000000
# Partition name: 'platform_backup'
part_type_guid=$(echo "$sgdisk_part_info" | grep "$part_type_guid_str" | awk '{print $4;}') part_type_guid=$(echo "$sgdisk_part_info" | grep "$part_type_guid_str" | awk '{print $4;}')
if [ "$dev" == "${by_dev}" -a "$part_type_guid" == $BACKUP_PART_GUID ] ; then if [ "$dev" == "${by_dev}" -a "$part_type_guid" == $BACKUP_PART_GUID ] ; then
part_type_name=$(echo "$sgdisk_part_info" | grep "$part_type_name_str" | awk '{print $3,$4;}') part_type_name=$(echo "$sgdisk_part_info" | grep "$part_type_name_str" | awk '{print $3;}')
BACKUP_PART_NAME=${part_type_name:1:-1} BACKUP_PART_NAME=${part_type_name:1:-1}
part_type_first=$(echo "$sgdisk_part_info" | grep "$part_type_first_str" | awk '{print $3;}') part_type_first=$(echo "$sgdisk_part_info" | grep "$part_type_first_str" | awk '{print $3;}')
@ -1177,14 +1198,19 @@ do
part_type_flags=$(echo "$sgdisk_part_info" | grep "$part_type_flags_str" | awk '{print $3;}') part_type_flags=$(echo "$sgdisk_part_info" | grep "$part_type_flags_str" | awk '{print $3;}')
BACKUP_PART_FLAGS=${part_type_flags} BACKUP_PART_FLAGS=${part_type_flags}
ilog "Platform Backup: ${BACKUP_PART_NAME}:${BACKUP_PART_FIRST}:${BACKUP_PART_END}:${BACKUP_PART_SIZE}:${part_type_guid}" ilog "Platform Backup: name:${BACKUP_PART_NAME} first:${BACKUP_PART_FIRST} end:${BACKUP_PART_END} size(sectors):${BACKUP_PART_SIZE} guid:${part_type_guid}"
part_fstype=$(exec_retry 5 0.5 "blkid -s TYPE -o value $part") part_fstype=$(exec_retry 5 0.5 "blkid -s TYPE -o value $part")
if [ "${part_fstype}" == "ext4" ]; then if [ "${part_fstype}" == "ext4" ]; then
ilog "Skipping wipe of persistent partition $part" BACKUP_PARTITION_EXISTS=1
BACKUP_CREATED=1 CURRENT_BACKUP_PARTITION_SIZE=$(parted -s $part unit MiB print | grep $part | awk '{print $3}' | sed 's/[^C0-9]*//g')
ilog "Platform Backup filesystem exists, skipping wipe of $part, size=$CURRENT_BACKUP_PARTITION_SIZE"
continue continue
else
ilog "Platform Backup: no ext4 filesystem detected on $part"
fi fi
else
ilog "Backup partition not found, by_dev=${by_dev}, part_type_guid=$part_type_guid, BACKUP_PART_GUID=$BACKUP_PART_GUID"
fi fi
if [ $WIPE_CEPH_OSDS == "true" -a "$part_type_guid" == $CEPH_JOURNAL_GUID ]; then if [ $WIPE_CEPH_OSDS == "true" -a "$part_type_guid" == $CEPH_JOURNAL_GUID ]; then
@ -1202,7 +1228,7 @@ do
fi fi
done done
if [ ${BACKUP_CREATED} -eq 0 -o "${dev}" != "${by_dev}" ]; then if [ ${BACKUP_PARTITION_EXISTS} -eq 0 -o "${dev}" != "${by_dev}" ]; then
ilog "Creating disk label for $dev" ilog "Creating disk label for $dev"
parted -s $dev mktable gpt parted -s $dev mktable gpt
ilog "... done" ilog "... done"
@ -1280,9 +1306,11 @@ if [ "${controller}" = true ] ; then
PLATFORM_BACKUP_SIZE=${DEFAULT_PERSISTENT_SIZE} PLATFORM_BACKUP_SIZE=${DEFAULT_PERSISTENT_SIZE}
if [ -z "$persistent_size" ]; then if [ -n "$persistent_size" ]; then
ilog "Platform Backup persistent size requested: $persistent_size"
else
# Default backup partition size in MiB # Default backup partition size in MiB
ilog "Platform Backup persistent size not on command line ; defaulting to ${DEFAULT_PERSISTENT_SIZE}" ilog "Platform Backup persistent size unspecified; defaulting to ${DEFAULT_PERSISTENT_SIZE}"
persistent_size=${DEFAULT_PERSISTENT_SIZE} persistent_size=${DEFAULT_PERSISTENT_SIZE}
fi fi
@ -1299,11 +1327,21 @@ if [ "${controller}" = true ] ; then
ilog "BIOS Firmware" ilog "BIOS Firmware"
fi fi
if [ ${BACKUP_CREATED} -eq 0 ] ; then if [ ${BACKUP_PARTITION_EXISTS} -eq 0 ] ; then
ilog "Platform Backup partition not detected: CREATING" ilog "Platform Backup partition not detected: CREATING"
else else
BACKUP_PERSISTED=1
ilog "Platform Backup Partition was detected: PERSISTING" ilog "Platform Backup Partition was detected: PERSISTING"
# Issues with this:
# - what if the partition size has changed?
# LAT is overwriting it after this section, based on the values in "a"
echo "checking CURRENT_BACKUP_PARTITION_SIZE=$CURRENT_BACKUP_PARTITION_SIZE, PLATFORM_BACKUP_SIZE=$PLATFORM_BACKUP_SIZE"
if [ "$PLATFORM_BACKUP_SIZE" -lt "$CURRENT_BACKUP_PARTITION_SIZE" ]; then
msg="Configured persistent_size ($PLATFORM_BACKUP_SIZE) is smaller "
msg="$msg than current partition size: $CURRENT_BACKUP_PARTITION_SIZE}. "
msg="$msg Changing to ${CURRENT_BACKUP_PARTITION_SIZE}MiB."
wlog "$msg"
PLATFORM_BACKUP_SIZE=$CURRENT_BACKUP_PARTITION_SIZE
fi
fi fi
if [ ${aio} = true ] ; then if [ ${aio} = true ] ; then
@ -1363,7 +1401,7 @@ if [ "${controller}" = true ] ; then
persistent_size=${DEFAULT_PERSISTENT_SIZE} persistent_size=${DEFAULT_PERSISTENT_SIZE}
fi fi
# PLATFORM_BACKUP_SIZE=${persistent_size} # PLATFORM_BACKUP_SIZE=${persistent_size}
ilog "Persistent Size: $persistent_size ${PLATFORM_BACKUP_SIZE}" ilog "Persistent Size: persistent_size=$persistent_size PLATFORM_BACKUP_SIZE=${PLATFORM_BACKUP_SIZE}"
fi fi
if [ "${aio}" = true ] ; then if [ "${aio}" = true ] ; then
@ -1389,10 +1427,55 @@ dev=$(get_disk "${INSTDEV}")
# Only init Platform Backup partition filesystem if the partition was just created # Only init Platform Backup partition filesystem if the partition was just created
pi=$((pi+1)) pi=$((pi+1))
if [ ${BACKUP_PERSISTED} -eq 0 ] ; then if [ $BACKUP_PARTITION_EXISTS -eq 0 ] ; then
ilog "Platform Backup Partition was CREATED. Initialize filesystem on ${BACKUP_PART}" ilog "Platform Backup Partition was CREATED. Initialize filesystem on ${BACKUP_PART}"
mkfs.ext4 -F -L ${BACKUP_PART_LABEL} ${BACKUP_PART} mkfs.ext4 -F -L ${BACKUP_PART_LABEL} ${BACKUP_PART}
[ ${?} -ne 0 ] && report_failure_with_msg "Failed Platform Backup partition filesystem init ${BACKUP_PART}" [ ${?} -ne 0 ] && report_failure_with_msg "Failed Platform Backup partition filesystem init ${BACKUP_PART}"
else
# In this section , perform sanity checks against both 1) partition size, and 2) filesystem size
# We can grow the partition size but it should never be shrunk.
# The underlying goal is to always preserve the contents of the backup partition.
#
local backup_current_size
ilog "Platform Backup partition check"
backup_current_size=$(parted -s $BACKUP_PART unit MiB print | grep $BACKUP_PART | awk '{print $3}' | sed 's/[^C0-9]*//g')
ilog "Platform Backup current size: ${backup_current_size}MiB"
if [ $backup_current_size -lt $PLATFORM_BACKUP_SIZE ] ; then
wlog "Platform Backup partition: resizing from ${backup_current_size}MiB to ${PLATFORM_BACKUP_SIZE}MiB"
e2fsck -p -f $BACKUP_PART
[ $? -ne 0 ] && report_failure_with_msg "e2fsck failed on platform backup partition!"
resize2fs -f $BACKUP_PART
[ $? -ne 0 ] && report_failure_with_msg "Failed to resize ext4 fs of platform backup partition!"
elif [ $backup_current_size -gt $PLATFORM_BACKUP_SIZE ] ; then
wlog "Platform Backup partition current size ${backup_current_size}MiB is greater than requested ${PLATFORM_BACKUP_SIZE}MiB"
wlog "Using current size ${backup_current_size}MiB"
PLATFORM_BACKUP_SIZE=$backup_current_size
else
ilog "Platform Backup partition size is unchanged: ${PLATFORM_BACKUP_SIZE}MiB."
fi
# There is a chance that we get here and the filesystem size is out of sync with the partition size.
# In this case it's possible that the resize2fs was passed over in the above check.
# So now we check the filesystem size and expand it to match the partition if necessary:
ilog "Platform Backup filesystem size check"
block_count=$(dumpe2fs -h $BACKUP_PART 2>/dev/null | awk '/Block count/ {print $3;}')
block_size=$(dumpe2fs -h $BACKUP_PART 2>/dev/null | awk '/Block size/ {print $3;}')
fs_size_mib=$(( block_count * block_size / 1024 / 1024 ))
ilog "Platform Backup filesystem size: ${fs_size_mib}MiB"
if [ $fs_size_mib -lt $PLATFORM_BACKUP_SIZE ] ; then
wlog "Platform Backup partition: resizing to ${PLATFORM_BACKUP_SIZE}MiB."
e2fsck -p -f $BACKUP_PART
[ $? -ne 0 ] && report_failure_with_msg "e2fsck failed on platform backup partition!"
resize2fs -f $BACKUP_PART
[ $? -ne 0 ] && report_failure_with_msg "Failed to resize ext4 fs of platform backup partition!"
elif [ $fs_size_mib -gt $PLATFORM_BACKUP_SIZE ] ; then
# This should not happen (from previous partition checks), but let's check and fail:
msg="Configured Platform Backup filesystem size ${PLATFORM_BACKUP_SIZE}MiB "
msg="$msg is smaller than existing filesystem ${fs_size_mib}MiB."
report_failure_with_msg "$msg"
else
ilog "Platform Backup partition: no resize required: ${PLATFORM_BACKUP_SIZE}MiB."
fi
fi fi
# Log important LVM config settings # Log important LVM config settings