Merge "Prestage ostree repo at /opt/platform-backup for local installation"

This commit is contained in:
Zuul 2022-09-27 19:55:07 +00:00 committed by Gerrit Code Review
commit e80a64faef
1 changed files with 182 additions and 0 deletions

View File

@ -308,6 +308,37 @@ function is_usb_install()
fi
}
#########################################################################
# Name : check_prestage
# Returns : true :0
# false:1
#########################################################################
function check_prestage()
{
set -- `cat /proc/cmdline`
for value in "\$@"; do
if [ "\${value}" = "prestage" ]; then
touch /tmp/lat/.prestage
return 0
fi
done
return 1
}
#########################################################################
# Name : is_prestage
# Returns : true :0
# false:1
#########################################################################
function is_prestage()
{
if [ -e /tmp/lat/.prestage ] ; then
return 0
else
return 1
fi
}
#########################################################################
# Name : update_platform_conf
# Purpose : Update the platform.conf file with logging
@ -900,6 +931,136 @@ wlog "timezone not set ; 'timezone --nontp --utc UTC'"
true
%end
####################################################
# prestaging: local installation
####################################################
#
# This code is only executed if "prestage" is set in the command line
# to the kernel.
%pre-part --interpreter=/bin/bash
HOOK_LABEL="pre-part"
. /tmp/lat/ks_functions.sh
# First, parse /proc/cmdline to find the boot args
# Check for prestaging
#
set -- `cat /proc/cmdline`
for value in "$@"; do case "$value" in force_install) force_install=${value};; esac; done
if check_prestage -eq 0 ; then
ilog "Prestaging for Local Install"
# The iso label is instboot. To mount the iso, we use
# /dev/disk/by-label/instboot.
ISO_DEV=/dev/disk/by-label/instboot
ISODIR=/run/install/repo
mkdir -p ${ISODIR}
rootfs_device=${INSTDEV}
# Mount the isofile
mount "${ISO_DEV}" "${ISODIR}"
rc=$?
if [ "${rc}" -ne 0 ]; then
report_failure_with_msg "Unable to mount ${ISO_DEV} Error rc=${rc}"
fi
if [ -e "${ISODIR}/ks-setup.cfg" ]; then
source "${ISODIR}/ks-setup.cfg"
fi
umount ${ISODIR}
# override the INSTDEV based on the information from ks-setup.cfg
export INSTDEV="${rootfs_device}"
ilog "rootfs device is ${INSTDEV}"
# Check if force_install is not set. If it is set, then install anyway.
if [ -z "${force_install}" ]; then
if [ -z "${rootfs_device}" ]; then
rootfs_device=$(get_disk_dev)
fi
orig_rootfs_device=$rootfs_device
by_path_rootfs_device=$(get_by_path ${rootfs_device})
rootfs_device=$(get_disk ${by_path_rootfs_device})
ilog "Found rootfs $orig_rootfs_device on: $by_path_rootfs_device->$rootfs_device."
part_numbers=( $(parted -s ${rootfs_device} print | awk '$1 == "Number" {i=1; next}; i {print $1}') )
# Get the correct rootfs prefix
ROOTFS_PART_PREFIX=${rootfs_device}
# Check if rootfs part is nvme (eg. /dev/nvme0n1). The partitions have a "p" in the part prefix.
# For example, /dev/nvme0n1p1
# So we need to add the letter "p" to get the prefix.
# The part numbers will be used later in the code.
case ${rootfs_device} in
*"nvme"*)
ROOTFS_PART_PREFIX=${ROOTFS_PART_PREFIX}p
;;
esac
# temporary mount directory
temp_mount=/mnt/temp_mount
mkdir -p ${temp_mount}
ilog "Searching for existing installation..."
for part in "${part_numbers[@]}"; do
device=${ROOTFS_PART_PREFIX}${part}
ilog "Searching on ${device}"
# mount this part at a temporary mount point
mount ${device} ${temp_mount}
if [ $? -ne 0 ]; then
wlog "Unable to mount ${device}"
continue
fi
# Check for the presence of install_uuid in one of the partitions on
# the root device
if [[ -e "${temp_mount}/www/pages/feed/rel-xxxPLATFORM_RELEASExxx/install_uuid" ]]; then
wlog "Found valid installation on ${device}"
umount ${temp_mount}
# Do not modify the system in any way
report_failure_with_msg "Prestage rejected. Existing installation detected. Please eject the media before rebooting."
fi
umount ${temp_mount}
done
rm -rf ${temp_mount}
ilog "Installing Prestaged content. No existing installation found."
else
# force install in spite of existing installation
wlog "Prestage: Force Installing Prestaged content. All existing installations will be lost."
fi
# If the size of the Platform Backup partition is greater than 30GB, parted will fail when
# it tries to reconfigure the partition in a later step. We delete the partition now so that
# parted succeeds in the later step.
partition_id=$(parted -s ${rootfs_device} print | awk '/platform_backup/ { print $1; }')
ilog "Partition id = ${partition_id}"
# If the partition id is not empty or zero, then the partition actually exists.
# Delete the partition.
if [[ "${partition_id}" -ne '' && "${partition_id}" -ne "0" ]]; then
wlog "Deleting platform backup at partition ${partition_id} on ${rootfs_device}"
# Delete the platform backup partition
parted -s ${rootfs_device} rm ${partition_id}
rc=$?
if [ "${rc}" -ne 0 ]; then
report_failure_with_msg "Unable to delete platform backup at partition ${partition_id} on ${rootfs_device}: [exit code ${rc}]"
else
ilog "Deleted partition ${partition_id} on ${rootfs_device}"
fi
fi
fi
true
%end
# Pre Partition - Pre Disk Setup Common Script
%pre-part --interpreter=/bin/bash
HOOK_LABEL="pre-part"
@ -2415,6 +2576,27 @@ if [ "${controller}" = true ] ; then
ostree --repo=${repo} init --mode=archive
ostree --repo=${repo} remote add ${instbr} file:///instboot/ostree_repo
ostree --repo=${repo} pull ${pull_options} ${instbr}:${instbr}
# Check if this is a prestage iso.If yes, then
# copy the ostree_repo to the backup directory.
if is_prestage -eq 0 ; then
ilog "Prestage operation: copying repo to /opt/platform-backup"
staging_dir=platform-backup
backup_device=/dev/disk/by-partlabel/platform_backup
backup_mount=/tmp/${staging_dir}
ilog "Temporary backup mount is ${backup_mount}"
mkdir -p "${backup_mount}"
mount "${backup_device}" "${backup_mount}" 2>/dev/null
ilog "Copying repo to ${backup_mount}"
cp -a ${repo} ${backup_mount}
rc=$?
if [ ${rc} -ne 0 ]; then
report_failure_with_msg "Unable to copy repo to /opt/platform-backup"
fi
umount "${backup_mount}"
fi
else
ilog "Stage ostree_repo from previous /sysroot pull to ${repo}"
mv -f /sysroot/var/www/pages/feed/rel-${sw_release}/ostree_repo ${IMAGE_ROOTFS}/var/www/pages/feed/rel-${sw_release}/