Skip to content

馃悰 Deactivate LVM before stopping mdraid in wipe-disk.sh - #2176

Open
guettli wants to merge 4 commits into
release-1.1from
tg/fix-wipe-disk-lvm-2145
Open

馃悰 Deactivate LVM before stopping mdraid in wipe-disk.sh#2176
guettli wants to merge 4 commits into
release-1.1from
tg/fix-wipe-disk-lvm-2145

Conversation

@guettli

@guettli guettli commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

wipe-disk.sh failed with "device or resource busy" on machines where an LVM volume group sits on top of an mdraid array (for example root and boot carved out of a volume group built on RAID). As long as a logical volume is active, it holds the layer below it open, which is what makes mdadm --stop fail.

Before stopping the mdraid arrays of a disk, the script now deactivates the volume groups that live on that disk:

  • lsblk reports every device stacked on the disk, and lvs reports which volume group each active logical volume belongs to. A logical volume is matched by its /dev/mapper path, which both tools print the same way.
  • Because lsblk walks the whole stack, a volume group is found no matter what sits between the disk and the logical volume: partitions, an mdraid array, LUKS, or anything else. Nothing is skipped by device type.
  • Only active logical volumes hold the layers below them open, and only those show up in lsblk, so exactly the volume groups that keep the disk busy get deactivated. Volume groups on other disks are left alone.
  • If lvs is not installed, there is no LVM on the machine and the step is skipped. Errors from lvs stop the script instead of turning into a confusing "device or resource busy" later on.

Fixes #2145

While a volume group's logical volumes are active, they keep the
underlying PV (a partition, disk, or mdraid array) busy, so
`mdadm --stop` fails with "device or resource busy" whenever LVM sits
on top of RAID. Deactivate any VG found on the disk's partitions or
mdraid arrays before attempting to stop mdraid.

Fixes #2145

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
# Committing as: thomas.guettler@syself.com
@github-actions github-actions Bot added size/XS Denotes a PR that changes 0-20 lines, ignoring generated files. area/code Changes made in the code directory labels Jul 15, 2026
@guettli
guettli requested a review from batistein July 15, 2026 14:58
@ashish1099

Copy link
Copy Markdown
Contributor

Hi @guettli can we push this :)

guettli and others added 2 commits August 13, 2026 13:58
Ask lvs which volume group each active logical volume belongs to, and
keep the ones whose /dev/mapper path shows up among the devices lsblk
reports for the disk. lsblk walks the whole stack, so a volume group is
found no matter what sits between the disk and the logical volume:
partitions, an mdraid array, LUKS, or anything else.

Only active logical volumes hold the layers below them open, and only
those show up in lsblk, so this deactivates exactly the volume groups
that keep the disk busy.

If lvs is not installed, there is no LVM on the machine and the step is
skipped. Errors from lvs are not hidden: they stop the script instead of
turning into a confusing "device or resource busy" later on.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
# Committing as: thomas.guettler@syself.com
@github-actions github-actions Bot added size/S Denotes a PR that changes 20-50 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-20 lines, ignoring generated files. labels Aug 13, 2026
@guettli

guettli commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author

@ashish1099 I updated the script. Can you test it, if it works for your environment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/code Changes made in the code directory size/S Denotes a PR that changes 20-50 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants