| 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 --allis 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:
zerombr
clearpart --all --initlabel
autopart --type=lvmOn 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:
ignoredisk --drives=sdb
zerombr
clearpart --all --initlabel --drives=sda
autopart --type=lvm --nohomeignoredisk 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):
%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
%endThe 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:
ksvalidator /var/www/html/ks/rhel10-lab.cfgChecking kickstart file /var/www/html/ks/rhel10-lab.cfgA 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:
/tmp/storage.log
/tmp/anaconda.logAfter a successful harness install on vm2, confirm scoped clearing and ignoredisk on the running system:
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTsda 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_membersda 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-*orrl_*volume names inlsblk - 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.

