馃悰 Deactivate LVM before stopping mdraid in wipe-disk.sh - #2176
Open
guettli wants to merge 4 commits into
Open
Conversation
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
Contributor
|
Hi @guettli can we push this :) |
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
Collaborator
Author
|
@ashish1099 I updated the script. Can you test it, if it works for your environment? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wipe-disk.shfailed 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 makesmdadm --stopfail.Before stopping the mdraid arrays of a disk, the script now deactivates the volume groups that live on that disk:
lsblkreports every device stacked on the disk, andlvsreports which volume group each active logical volume belongs to. A logical volume is matched by its/dev/mapperpath, which both tools print the same way.lsblkwalks 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.lsblk, so exactly the volume groups that keep the disk busy get deactivated. Volume groups on other disks are left alone.lvsis not installed, there is no LVM on the machine and the step is skipped. Errors fromlvsstop the script instead of turning into a confusing "device or resource busy" later on.Fixes #2145