
During restore we have to skip wiping OSDs on controller-1 if ansible is run with 'wipe_ceph_osds: false'. To skip wiping osds we query sysinv v1/ihosts/wipe_osds from the kickstarts. This is similar to how we query upgrade status. Change-Id: I28dd4a4858dfb12c1f0dc2486bb25bf77cfffb0a Story: 2004761 Task: 36593 Depends-On: I93ab2c1e0a0759c2492d4d481e49de315c4998b3 Depends-On: Ief93da56c1344ab259e674ca8d79f9952fefcd2b Signed-off-by: Ovidiu Poncea <ovidiu.poncea@windriver.com>
189 lines
6.5 KiB
INI
189 lines
6.5 KiB
INI
%pre --erroronfail
|
|
|
|
# Source common functions
|
|
. /tmp/ks-functions.sh
|
|
|
|
# This is a really fancy way of finding the first usable disk for the
|
|
# install and not stomping on the USB device if it comes up first
|
|
|
|
# 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
|
|
|
|
# Find either the ISO or USB device first chopping off partition
|
|
ISO_DEV=`readlink /dev/disk/by-label/oe_iso_boot`
|
|
sdev=`echo $ISO_DEV | sed -e 's/.$//'`
|
|
if [ -e /dev/disk/by-label/$sdev ] ; then
|
|
ISO_DEV=$sdev
|
|
fi
|
|
USB_DEV=`readlink /dev/disk/by-label/wr_usb_boot`
|
|
sdev=`echo $USB_DEV | sed -e 's/.$//'`
|
|
if [ -e /dev/disk/by-label/$sdev ] ; then
|
|
USB_DEV=$sdev
|
|
fi
|
|
|
|
# Temporary, until lab pxelinux.cfg files are updated to specify install devices
|
|
if [ -z "$rootfs_device" -o -z "$boot_device" ]
|
|
then
|
|
INST_HDD=""
|
|
# Prefer a vd* device if this is kvm/qemu
|
|
for e in vda vdb sda sdb nvme0n1; do
|
|
if [ -e /dev/$e -a "$ISO_DEV" != "../../$e" -a "$USB_DEV" != "../../$e" ] ; then
|
|
INST_HDD=$e
|
|
break
|
|
fi
|
|
done
|
|
|
|
# Set variables to $INST_HDD if not set
|
|
rootfs_device=${rootfs_device:-$INST_HDD}
|
|
boot_device=${boot_device:-$INST_HDD}
|
|
fi
|
|
|
|
# Convert to by-path
|
|
orig_rootfs_device=$rootfs_device
|
|
rootfs_device=$(get_by_path $rootfs_device)
|
|
|
|
orig_boot_device=$boot_device
|
|
boot_device=$(get_by_path $boot_device)
|
|
|
|
if [ ! -e "$rootfs_device" -o ! -e "$boot_device" ] ; then
|
|
# Touch this file to prevent Anaconda from dying an ungraceful death
|
|
touch /tmp/part-include
|
|
|
|
report_pre_failure_with_msg "ERROR: Specified installation ($orig_rootfs_device) or boot ($orig_boot_device) device is invalid."
|
|
fi
|
|
|
|
# Ensure specified device is not a USB drive
|
|
udevadm info --query=property --name=$rootfs_device |grep -q '^ID_BUS=usb' || \
|
|
udevadm info --query=property --name=$boot_device |grep -q '^ID_BUS=usb'
|
|
if [ $? -eq 0 ]; then
|
|
# Touch this file to prevent Anaconda from dying an ungraceful death
|
|
touch /tmp/part-include
|
|
|
|
report_pre_failure_with_msg "ERROR: Specified installation ($orig_rootfs_device) or boot ($orig_boot_device) device is a USB drive."
|
|
fi
|
|
|
|
# Deactivate existing volume groups to avoid Anaconda issues with pre-existing groups
|
|
vgs --noheadings -o vg_name | xargs --no-run-if-empty -n 1 vgchange -an
|
|
|
|
ONLYUSE_HDD=""
|
|
if [ "$(curl -sf http://pxecontroller:6385/v1/upgrade/$(hostname)/in_upgrade 2>/dev/null)" = "true" ]; then
|
|
# In an upgrade, only wipe the disk with the rootfs and boot partition
|
|
echo "In upgrade, wiping only $rootfs_device"
|
|
WIPE_HDD="$(get_disk $rootfs_device)"
|
|
ONLYUSE_HDD="$(basename $(get_disk $rootfs_device))"
|
|
if [ "$(get_disk $rootfs_device)" != "$(get_disk $boot_device)" ]; then
|
|
WIPE_HDD="$WIPE_HDD,$(get_disk $boot_device)"
|
|
ONLYUSE_HDD="$ONLYUSE_HDD,$(basename $(get_disk $boot_device))"
|
|
fi
|
|
else
|
|
# Make a list of all the hard drives that are to be wiped
|
|
WIPE_HDD=""
|
|
# Partition type OSD has a unique globally identifier
|
|
part_type_guid_str="Partition GUID code"
|
|
CEPH_OSD_GUID="4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D"
|
|
|
|
# Check if we wipe OSDs
|
|
if [ "$(curl -sf http://pxecontroller:6385/v1/ihosts/wipe_osds 2>/dev/null)" = "true" ]; then
|
|
echo "Wipe OSD data."
|
|
WIPE_CEPH_OSDS="true"
|
|
else
|
|
echo "Skip Ceph OSD data wipe."
|
|
WIPE_CEPH_OSDS="false"
|
|
fi
|
|
|
|
for f in /dev/disk/by-path/*
|
|
do
|
|
dev=$(readlink -f $f)
|
|
lsblk --nodeps --pairs $dev | grep -q 'TYPE="disk"'
|
|
if [ $? -ne 0 ]
|
|
then
|
|
continue
|
|
fi
|
|
|
|
# Avoid wiping USB drives
|
|
udevadm info --query=property --name=$dev |grep -q '^ID_BUS=usb' && continue
|
|
|
|
# Avoid wiping ceph osds if sysinv tells us so
|
|
if [ ${WIPE_CEPH_OSDS} == "false" ]; then
|
|
wipe_dev="true"
|
|
part_numbers=( `parted -s $dev print | awk '$1 == "Number" {i=1; next}; i {print $1}'` )
|
|
# Scanning the partitions looking for CEPH OSDs and
|
|
# skipping any disk found with such partitions
|
|
for part_number in "${part_numbers[@]}"; do
|
|
sgdisk_part_info=$(flock $dev sgdisk -i $part_number $dev)
|
|
part_type_guid=$(echo "$sgdisk_part_info" | grep "$part_type_guid_str" | awk '{print $4;}')
|
|
if [ "$part_type_guid" == $CEPH_OSD_GUID ]; then
|
|
echo "OSD found on $dev, skipping wipe"
|
|
wipe_dev="false"
|
|
break
|
|
fi
|
|
done
|
|
if [ "$wipe_dev" == "false" ]; then
|
|
continue
|
|
fi
|
|
fi
|
|
|
|
# Add device to the wipe list
|
|
devname=$(basename $dev)
|
|
if [ -e $dev -a "$ISO_DEV" != "../../$devname" -a "$USB_DEV" != "../../$devname" ]; then
|
|
if [ -n "$WIPE_HDD" ]; then
|
|
WIPE_HDD=$WIPE_HDD,$dev
|
|
else
|
|
WIPE_HDD=$dev
|
|
fi
|
|
fi
|
|
done
|
|
echo "Not in upgrade, wiping disks: $WIPE_HDD"
|
|
fi
|
|
|
|
for dev in ${WIPE_HDD//,/ }
|
|
do
|
|
# Clearing previous GPT tables or LVM data
|
|
# Delete the first few bytes at the start and end of the partition. This is required with
|
|
# GPT partitions, they save partition info at the start and the end of the block.
|
|
# Do this for each partition on the disk, as well.
|
|
partitions=$(lsblk -rip $dev -o TYPE,NAME |awk '$1 == "part" {print $2}')
|
|
for p in $partitions $dev
|
|
do
|
|
echo "Pre-wiping $p from kickstart"
|
|
dd if=/dev/zero of=$p bs=512 count=34
|
|
dd if=/dev/zero of=$p bs=512 count=34 seek=$((`blockdev --getsz $p` - 34))
|
|
done
|
|
done
|
|
|
|
# Check for remaining cgts-vg PVs, which could potentially happen
|
|
# in an upgrade where we're not wiping all disks.
|
|
# If we ever create other volume groups from kickstart in the future,
|
|
# include them in this search as well.
|
|
partitions=$(pvs --select 'vg_name=cgts-vg' -o pv_name --noheading | grep -v '\[unknown\]')
|
|
for p in $partitions
|
|
do
|
|
echo "Pre-wiping $p from kickstart (cgts-vg present)"
|
|
dd if=/dev/zero of=$p bs=512 count=34
|
|
dd if=/dev/zero of=$p bs=512 count=34 seek=$((`blockdev --getsz $p` - 34))
|
|
done
|
|
|
|
let -i gb=1024*1024*1024
|
|
|
|
cat<<EOF>/tmp/part-include
|
|
clearpart --all --drives=$WIPE_HDD --initlabel
|
|
EOF
|
|
|
|
if [ -n "$ONLYUSE_HDD" ]; then
|
|
cat<<EOF>>/tmp/part-include
|
|
ignoredisk --only-use=$ONLYUSE_HDD
|
|
EOF
|
|
fi
|
|
|
|
if [ -d /sys/firmware/efi ] ; then
|
|
cat<<EOF>>/tmp/part-include
|
|
part /boot/efi --fstype=efi --size=300 --ondrive=$(get_disk $boot_device)
|
|
EOF
|
|
else
|
|
cat<<EOF>>/tmp/part-include
|
|
part biosboot --asprimary --fstype=biosboot --size=1 --ondrive=$(get_disk $boot_device)
|
|
EOF
|
|
fi
|
|
|