metal/bsp-files/kickstarts/pre_disk_setup_common.cfg
Dean Troyer 18922761a6 StarlingX open source release updates
Signed-off-by: Dean Troyer <dtroyer@gmail.com>
2018-05-31 07:36:43 -07:00

155 lines
5.2 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=""
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
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 all 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