# Kickstart file for destroy install text lang en_US.UTF-8 keyboard us timezone --utc America/New_York rootpw redhat authconfig --enableshadow --passalgo=sha512 firewall --disabled selinux --enforcing zerombr clearpart --all part swap --size 512 part /boot --size 512 part / --size 8192 bootloader reboot %packages @base %end # ---------------------------------------------------------------- # pre script # goals: # + figure out any disks to protect # + wipe disks found (ignoring RHTINST) # ---------------------------------------------------------------- %pre ( set -x chvt 8 echo "$(date): Beginning pre script..." | tee /dev/tty8 # ---------------------------------------------------------------- # figure out if we should poweroff instead of reboot # ---------------------------------------------------------------- POWEROFF="" if (egrep -i '\' /proc/cmdline); then POWEROFF=yes fi # ---------------------------------------------------------------- # figure out any disks to protect # ---------------------------------------------------------------- # the primary disk is where all of the physical allocations take place. # if we are not careful, Anaconda might allocate partitions on the # instructor USB drive. You would like to think we could just say # "ignoredisk ", but then Anaconda will not read the # installer off of it. # CANDIDATES = physical disks (disks that do not end in a number) # Going to need to be more careful here with CANDIDATES: # Drop dm-*, loop*. # I do not think partitions are going to be here by default # Do I still care if it is removable (classroom-on-a-stick) # New PCIe-NVMe disks are named: /dev/nvme0n1 (with p1 added) # CANDIDATES = devices of TYPE disk (avoiding the skipping of partitions, etc) # SRCDISK = disk that contains the LABEL='RHTINST' partition # MAINDISK = calculated main disk #CANDIDATES=$(ls /sys/block | grep -v "[0-9]$") #CANDIDATES=$(ls /sys/block | grep -Ev '^(dm-|loop)') CANDIDATES=$(lsblk -ido KNAME,TYPE | grep -w disk | cut -d" " -f1) SRCDISK=$(blkid -t LABEL=RHTINST | sed -e 's:^/dev/::' -e 's/[0-9].*//') WIPERS='' for d in $CANDIDATES; do #grep -q 1 /sys/block/$d/removable && continue [ "$d" = "$SRCDISK" ] && continue WIPERS="$WIPERS /dev/$d" done echo "RHT: Wiping $WIPERS disk(s)" | tee /dev/tty8 echo "RHT: Protecting $SRCDISK as USB disk" | tee /dev/tty8 # ---------------------------------------------------------------- # wipe disks found (ignoring RHTINST) # ---------------------------------------------------------------- # Should be unnecessary, but clear out the VGDAs for vg in $(vgs --noheadings | awk '{print $1}') do echo Found VG $vg and am trying to remove it... | tee /dev/tty8 vgremove -f ${vg} done for pv in $(pvs --noheadings | awk '{print $1}') do echo Found PV $pv and am trying to remove it... | tee /dev/tty8 pvremove -f ${pv} done # Now start wiping the physical disks found for drive in $WIPERS; do echo "About to wipe the partitions on ${drive}!!!" | tee /dev/tty8 # Get disk size info dsects=$(parted -s ${drive} unit s print | egrep "^Disk ${drive}:" | cut -d' ' -f3 | sed 's/s//' ) ssize=$(parted -s ${drive} unit s print | egrep "^Sector size \(logical/physical\):" | sed -r 's/^Sector size \(logical\/physical\): ([0-9]+)B\/.*$/\1/') [ "$ssize" -gt 0 ] || ssize=512 # Failsafe in case the parted magic fails echo "Working on disk $drive with dsects $dsects and ssize $ssize" | tee /dev/tty8 # Kill the first and last 1 MiB of each partition for part in $(parted -s ${drive} unit s print | egrep '^[[:space:]]*[0-9]+' | awk '{print $1}'); do pstart=$(parted -s ${drive} unit s print | egrep "^[[:space:]]*${part}[[:space:]]+" | awk '{print $2}' | sed 's/s//') pend=$(parted -s ${drive} unit s print | egrep "^[[:space:]]*${part}[[:space:]]+" | awk '{print $3}' | sed 's/s//') echo "Working on partition $part start $pstart end $pend" | tee /dev/tty8 dd if=/dev/zero of=${drive} bs=${ssize} count=2048 seek=${pstart} dd if=/dev/zero of=${drive} bs=${ssize} count=2048 seek=$(( ${pend} - 2048 )) done echo "Killing the beginning and ending of drive $drive" | tee /dev/tty8 # Kill the MBR and partition table dd if=/dev/zero of=${drive} bs=${ssize} count=2048 # GPT places a 2ndary header at the end of the volume that also # needs to be deleted: dd if=/dev/zero of=${drive} bs=${ssize} seek=$(( ${dsects} - 2048 )) done # ---------------------------------------------------------------- # End of pre script # ---------------------------------------------------------------- echo "$(date): Pre script complete." | tee /dev/tty8 sleep 10 chvt 1 # ---------------------------------------------------------------- # Either reboot of poweroff # ---------------------------------------------------------------- if [[ -n "${POWEROFF}" ]]; then poweroff else reboot fi ) > /tmp/rht-ks-pre.log 2>&1 %end