Solved: Kickstart clearpart not working in RHEL CentOS 7 8

Kickstart, Linux

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.


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
   echo "All raid devices are cleared"

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

rm -vf $available_disks


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.


clearpart - kickstart command in RHEL 8

Views: 205
Deepak Prasad

Deepak Prasad

He is the founder of GoLinuxCloud and brings over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels in various domains, from development to DevOps, Networking, and Security, ensuring robust and efficient solutions for diverse projects. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to

Thank You for your support!!

2 thoughts on “Solved: Kickstart clearpart not working in RHEL CentOS 7 8”

  1. Thanks so much for this!!! Same as Volker. I spent 3 days trying to work this out. I knew the issue had something to do with the legacy md raid devices on the disks. I had originally put nodmraid in the bootparmas which should have removed them however it didnt. Added this gem to %pre and bingo.

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


Leave a Comment