Solved: Kickstart clearpart not working in RHEL CentOS 7 8

We have kickstart command clearpart in RHEL/CentOS 7/8 Linux to clear the partition label before performing the fresh installation. In one of our scenarios, Kickstart clearpart not working and it was unable to remove existing partitions from the node.

In this article I will share the solution to fix "Kickstart clearpart not working" which worked in my case. Although it may or may not work for you, please do let me know if some other solution worked for your environment.

 

Problem: Kickstart clearpart not working

In the kickstart file we use clearpart command to erase some or all the existing partitions

In some scenarios Kickstart clearpart not working issue is seen where it fails to delete existing partitions due to which kickstart installation fails.

clearpart supports below options

  • --all - Erases all partitions from the system.
  • --drives= - Specifies which drives to clear partitions from
  • --initlabel - Initializes a disk (or disks) by creating a default disk label for all disks in their respective architecture that have been designated for formatting
  • --list= - Specifies which partitions to clear.
  • --linux - Erases all Linux partitions.
  • --none (default) - Do not remove any partitions.
  • --cdl - Reformat any LDL DASDs to CDL format.
  • --disklabel=LABEL - Set the default disklabel to use.

 

Solution: Kickstart clearpart not working

It is possible that a partition is still in use which is why clearpart fails to delete partitions. As a solution we will write a %pre script to manually delete all existing partitions, wipe out all partition and file system labels, delete any raid devices

Below is my sample %pre script to fix kickstart clearpart not working problem.

%pre

udevadm settle
dmsetup remove_all

# De-activate any exiting Volume Groups
vgchange -an system
vgchange -an os

# Clear software raid devices if any
raid_devices=$(mktemp /tmp/mdstat.XXXXXXXXX)
cat /proc/mdstat | grep ^md | cut -d : -f 1 > $raid_devices

if [ -s $raid_devices ];then
   for raid in `cat $raid_devices`;do
       wipefs -f -a /dev/$raid
       mdadm --stop -f /dev/$raid
       if [ $? != "0" ];then
          udevadm settle
          dmsetup remove_all
          mdadm --stop -f /dev/$raid
       fi
   done
else
   echo "All raid devices are cleared"
fi

rm -vf $raid_devices

# Wipe any partitions if found
available_disks=$(mktemp /tmp/disks.XXXXXXXXX)
ls -r /dev/sd* > $available_disks

for disk in `cat $available_disks`;do
   wipefs -f -a $disk
done

rm -vf $available_disks

%end

You can modify this %pre script to identify and delete and more partitions, file systems on your Linux environment.

So you will not be dependent on clearpart to delete the existing partitions.

 

Lastly I hope the steps from the article to fix kickstart clearpart not working issue on RHEL/CentOS 7/8 Linux was helpful. So, let me know your suggestions and feedback using the comment section.

 

References:
clearpart - kickstart command in RHEL 8

1 thought on “Solved: Kickstart clearpart not working in RHEL CentOS 7 8”

  1. Thanks for that solution! I experienced the same issues with Fedora 32 kickstart. Drove me nuts until I found this.

    Reply

Leave a Comment

Please use shortcodes <pre class=comments>your code</pre> for syntax highlighting when adding code.