metal/bsp-files/kickstarts/pre_prestaging_install_check.cfg
Kyle MacLeod 5f3c54297d Support CentOS previous release in subcloud remote install
This commit introduces support for installing CentOS-based previous
release (21.12) in Debian.

There are two main components in this commit:
1. Handle the label change for the backup partition:

Platform Backup in 21.12 vs 'platform_backup' in Debian
This is accomplished by ignoring the label/partlabel entirely when
searching for an existing backup partition. Instead, the partition
GUID is used to locate the partition. The GUID does not change
between distributions.

2. Use pre-bundled CentOS kickstarts for subcloud installs in Debian

Since modifications are required to the CentOS kickstart files for the
above, we copy the relevant pre-bundled centos kickstarts (for miniboot
and prestaged ISO only) into a centos-specific directory under the
Debian /var/www/pages/feed/rel-${platform_release}/kickstart directory
structure, in order to be available for the gen-bootloader-iso-centos.sh
utility. These files are included in the platform-kickstarts .deb
package.

NOTES on how the pre-bundled files are created:
- We cannot use the files under bsp-file/kickstarts/*.cfg, since they
  are not valid for 21.12 release (e.g. they refer to /var/www)
- Instead, files were taken from a valid 21.12 release and manually
  merged with the pre-bundled files generated from this repo

GOING FORWARD:
Only the bundled files at kickstart/files/centos/*.cfg will be
maintained. At a later time, we may choose to remove the partial
kickstarts under bsp-files/kickstarts/*.cfg, since they are not used
anywhere.

Test Plan

PASS:
- Build full ISO, verify that the
  /var/www/pages/feed/rel-23.09/kickstart/centos directory is populated
  with the pre-bundled kickstart files
- Verify previous-release CentOS subcloud install/deployment under
  Debian (requires patched 22.12 load)
- Verify current-release subcloud install under Debian

Story: 2010611
Task: 48268

Signed-off-by: Kyle MacLeod <kyle.macleod@windriver.com>
Change-Id: I1b7f76212e222dea7c6e586e4e9492f8a86a955e
2023-06-30 13:06:35 -04:00

105 lines
3.8 KiB
INI

%pre --erroronfail
# Get the FD used by subshells to log output
exec {stdout}>&1
# Source common functions
. /tmp/ks-functions.sh
wlog "pre prestaging install check"
# First, parse /proc/cmdline to find the boot args
set -- `cat /proc/cmdline`
for I in $*; do case "$I" in *=*) eval $I 2>/dev/null;; esac; done
for J in $*; do case "$J" in force_install) force_install=${J};; esac; done
if [ -e /run/install/repo/ks-setup.cfg ]; then
source /run/install/repo/ks-setup.cfg
fi
# if force_install is set, install anyway. Ignore the remainder of this section.
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)
wlog "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}') )
# print the partnumber info for informational purposes
for i in ${part_numbers[@]}; do
wlog "partnumber: ${i}"
done
# 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}
wlog "Searching for existing installation..."
for part in "${part_numbers[@]}"; do
device=${ROOTFS_PART_PREFIX}${part}
wlog "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}/var/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_pre_failure_with_msg "Prestage rejected. Existing installation detected. Please eject the media before rebooting."
fi
umount ${temp_mount}
done
rm -rf ${temp_mount}
wlog "Installing Prestaged content. No existing installation found."
else
# force install inspite of existing installation
wlog "Force install the prestage content"
wlog "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.
# The backup partition may be labeled 'Platform Backup' (centos) or 'platform_backup' (debian)
partition_id=$(parted -s ${rootfs_device} print | awk '/(Platform Backup|platform_backup)/ { print $1; }')
# If the partition id is not empty or zero, then the partition actually exists.
# Delete the partition.
if [ -n "${partition_id}" ] && [ "${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
wlog "Unable to delete platform backup at partition ${partition_id} on ${rootfs_device}: [exit code ${rc}]"
exit -1
else
wlog "Deleted partition ${partition_id} on ${rootfs_device}"
fi
fi
%end