Solved: Kickstart clearpart Not Working on RHEL

Deepak Prasad
Tested on RHEL 10.2 (Coughlan) — kickstart harness on vm2.lab.example (sda 20 GiB install, sdb 10 GiB ignored)
Package pykickstart 3.52.12-1.el10
Applies to RHEL, Rocky Linux, AlmaLinux, Oracle Linux, CentOS Stream
Privilege Installer boot access on the target host (PXE or ISO)
Scope Why clearpart fails on reused disks, scoped clearpart and ignoredisk lines, and a %pre wipe script from the GoLinuxCloud lab harness. Does not cover full kickstart file structure or PXE wiring.
Related guides Automate RHEL installation with Kickstart
Kickstart %pre script examples
Configure Kickstart PXE boot server
Kickstart %post script examples
Red Hat installation steps

Kickstart clearpart should erase partition tables before Anaconda lays down a new layout. On reused lab VMs and rack servers with old LVM, RAID, or leftover signatures, Anaconda sometimes stops with:

  • not enough free space on the install disk
  • clearpart did not remove partitions even when clearpart --all is in the file

This article documents the failure we hit on RHEL 10 vm2 during PXE kickstart testing and the fix: scope disks with ignoredisk, tighten clearpart --drives=, and run a %pre script that deactivates volume groups and wipefs the install disk before partitioning.


Problem: clearpart not working

In a kickstart file you use clearpart to erase partitions before autopart or manual part lines. A minimal pattern looks like this:

text
zerombr
clearpart --all --initlabel
autopart --type=lvm

On vm2 the install failed during storage setup. Anaconda reported insufficient free space on sda because an old LVM stack from a prior install was still present. clearpart --all without --drives= also risked touching every disk. vm2 has a second disk (sdb) that the harness must keep for ignoredisk demos.

clearpart option Role
--all Erase all partitions on the selected drive(s)
--drives= Limit which drives are cleared
--initlabel Create a fresh partition table label
--linux Erase Linux partitions only
--none Default—do not remove partitions

Solution: scope disks and wipe in %pre

Two kickstart changes plus a %pre script fixed the lab run.

Step 1 — ignoredisk and scoped clearpart

Keep sdb untouched and limit clearing to sda:

text
ignoredisk --drives=sdb
zerombr
clearpart --all --initlabel --drives=sda
autopart --type=lvm --nohome

ignoredisk tells Anaconda to ignore sdb for partitioning. clearpart --drives=sda avoids wiping every disk when --all is set.

Step 2 — %pre script to break old LVM and wipe signatures

When clearpart alone is not enough, add a %pre block that runs before partitioning. This is the script from the lab harness on vm1 (/var/www/html/ks/rhel10-lab.cfg):

text
%pre --log=/tmp/kickstart_pre.log
#!/bin/bash
set -x
echo "=== %pre wipe install disk $(date -Is) ==="
INSTALL_DISK=sda
udevadm settle
vgchange -an 2>/dev/null || true
dmsetup remove_all 2>/dev/null || true
if [[ -b /dev/${INSTALL_DISK} ]]; then
  wipefs -af "/dev/${INSTALL_DISK}" || true
  for part in /dev/${INSTALL_DISK}*; do
    [[ -b "$part" ]] && wipefs -af "$part" || true
  done
  lsblk "/dev/${INSTALL_DISK}"
fi
%end

The script deactivates volume groups, removes device-mapper nodes, and wipes partition and filesystem signatures on one disk only. That matches ignoredisk and clearpart --drives=sda.

For RAID-heavy hosts, extend the pattern with mdadm --stop and per-RAID wipefs before the disk loop. See the extended example in Kickstart %pre script examples.

Step 3 — validate before netboot

Run ksvalidator on the full kickstart file on the server:

bash
ksvalidator /var/www/html/ks/rhel10-lab.cfg
output
Checking kickstart file /var/www/html/ks/rhel10-lab.cfg

A silent exit after that line means the parser accepted the storage and script sections.

If storage still fails, inspect installer logs on the target during the failed run:

text
/tmp/storage.log
/tmp/anaconda.log

After a successful harness install on vm2, confirm scoped clearing and ignoredisk on the running system:

bash
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT
output
sda                   20G disk
├─sda2                 2G part xfs         /boot
└─sda3                18G part LVM2_member
  ├─rhel_vm200-root   16G lvm  xfs         /
  └─rhel_vm200-swap    2G lvm  swap        [SWAP]
sdb                   10G disk
└─sdb1                10G part LVM2_member

sda carries the new install. sdb was not partitioned by Anaconda, but a leftover LVM partition from earlier lab runs can remain on the ignored disk. That is expected with ignoredisk --drives=sdb; wipe sdb manually in %pre only when you need a completely blank second disk for other demos.


When to rely on clearpart alone

clearpart without %pre is enough on blank disks or after a single prior kickstart that did not leave active LVM. Add the wipe %pre when you:

  • Reinstall the same VM repeatedly in a lab
  • See "not enough free space" with existing dm-* or rl_* volume names in lsblk
  • Run kickstart on servers that previously used software RAID or complex LVM

References


Summary

When kickstart clearpart does not remove old partitions, combine ignoredisk, scoped clearpart --drives=, and a %pre script that deactivates VGs and runs wipefs on the install disk only.

The lab harness on vm2 uses sda for install and ignores sdb for partitioning. After a successful run, lsblk should show LVM on sda (rhel_vm200-* when the hostname is vm2.lab.example). sdb may still show an old LVM2_member partition if prior installs used it; ignoredisk prevents Anaconda from clearing or reusing that disk. Adapt disk names for your hardware before production netboots, and never run a blanket wipe loop across every /dev/sd* on a multi-disk server.


Frequently Asked Questions

1. Why does clearpart --all fail when old LVM exists?

Active volume groups and device-mapper nodes can block Anaconda from reclaiming space. Deactivate VGs in %pre, remove DM devices, and wipe partition signatures with wipefs before clearpart runs.

2. Should I use clearpart --all on multi-disk servers?

No. Combine ignoredisk --drives=sdb with clearpart --all --initlabel --drives=sda so only the install disk is wiped. clearpart --all without --drives risks every disk on the machine.

3. Does zerombr erase data like wipefs?

No. zerombr clears the partition table signature on selected drives. wipefs removes filesystem and LVM signatures on partitions and whole disks. Use both patterns when old LVM and partition tables stack on the same disk.

4. What does ignoredisk actually skip?

ignoredisk tells Anaconda not to partition or clear the listed drives. It does not stop a sloppy %pre wipe script. Keep INSTALL_DISK and ignoredisk aligned on the same disk names.

5. Is clearpart --linux enough on mixed disk layouts?

Often not on lab VMs with leftover LVM or RAID metadata. --linux skips non-Linux partitions but may leave active volume groups. Scoped clearpart plus a %pre wipe is safer on disks you reinstall repeatedly.

6. Will a %pre wipe script touch ignored disks?

Only if your script targets them. The lab harness wipes sda only while ignoredisk --drives=sdb keeps sdb out of Anaconda storage. Hard-code or detect the install disk name and never loop over every /dev/sd* blindly.
Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware.

  • Debian
  • Ubuntu
  • Linux
  • Red Hat Enterprise Linux
  • Shell Script
  • System Administration