Skip to content

Commit e3d639d

Browse files
committed
Fix device mapper partitioning
When run ignition on a device mapper, ie, multipath, it fails because the function blockDevHeld returns true as the block device contains holders. A block device with holders do not necessary means the block device is in use (like mounted). The function blockDevInUse will not check if it is a device mapper and if so, do not check for blockDevHeld. Signed-off-by: Tiago Bueno <[email protected]>
1 parent 2bcc596 commit e3d639d

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

docs/release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ nav_order: 9
2828
### Bug fixes
2929

3030
- Fix fetch-offline for Oracle Cloud Infrastructure
31+
- Fix device mapper partitioning ([#2128](https://github.com/coreos/ignition/issues/2128))
3132

3233
## Ignition 2.22.0 (2025-07-08)
3334
Starting with this release, ignition-validate binaries are signed with the

internal/exec/stages/disks/partitions.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,13 @@ func (p PartitionList) Swap(i, j int) {
323323
p[i], p[j] = p[j], p[i]
324324
}
325325

326+
func isBlockDevMapper(blockDevResolved string) bool {
327+
blockDevNode := filepath.Base(blockDevResolved)
328+
dmName := fmt.Sprintf("/sys/class/block/%s/dm/name", blockDevNode)
329+
_, err := os.Stat(dmName)
330+
return err == nil
331+
}
332+
326333
// Expects a /dev/xyz path
327334
func blockDevHeld(blockDevResolved string) (bool, error) {
328335
_, blockDevNode := filepath.Split(blockDevResolved)
@@ -384,9 +391,14 @@ func blockDevPartitions(blockDevResolved string) ([]string, error) {
384391
func blockDevInUse(blockDevResolved string, skipPartitionCheck bool) (bool, []string, error) {
385392
// Note: This ignores swap and LVM usage
386393
inUse := false
387-
held, err := blockDevHeld(blockDevResolved)
388-
if err != nil {
389-
return false, nil, fmt.Errorf("failed to check if %q is held: %v", blockDevResolved, err)
394+
isDevMapper := isBlockDevMapper(blockDevResolved)
395+
held := false
396+
if !isDevMapper {
397+
var err error
398+
held, err = blockDevHeld(blockDevResolved)
399+
if err != nil {
400+
return false, nil, fmt.Errorf("failed to check if %q is held: %v", blockDevResolved, err)
401+
}
390402
}
391403
mounted, err := blockDevMounted(blockDevResolved)
392404
if err != nil {

0 commit comments

Comments
 (0)