Skip to content

Commit

Permalink
sgdisk: Run partx after partition changes
Browse files Browse the repository at this point in the history
The sgdisk tool does not update the kernel partition table with BLKPG in
contrast to other similar tools but only uses BLKRRPART which fails as
soon as one partition of the disk is mounted.
Update the kernel partition table with partx when we know that a
partition of the disk is in use.
  • Loading branch information
pothos committed Nov 21, 2023
1 parent a0ac6ee commit 612571a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ nav_order: 9
### Changes

- Require Go 1.19+
- The Dracut module now installs partx

### Bug fixes

- Prevent races with udev after disk editing
- Don't fail to wipe partition table if it's corrupted
- Force partition table update after repartitioning, even if one partition is already mounted


## Ignition 2.16.2 (2023-07-12)
Expand Down
1 change: 1 addition & 0 deletions dracut/30ignition/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ install() {
mkfs.xfs \
mkswap \
sgdisk \
partx \
useradd \
userdel \
usermod \
Expand Down
2 changes: 2 additions & 0 deletions internal/distro/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
mdadmCmd = "mdadm"
mountCmd = "mount"
sgdiskCmd = "sgdisk"
partxCmd = "partx"
modprobeCmd = "modprobe"
udevadmCmd = "udevadm"
usermodCmd = "usermod"
Expand Down Expand Up @@ -90,6 +91,7 @@ func GroupdelCmd() string { return groupdelCmd }
func MdadmCmd() string { return mdadmCmd }
func MountCmd() string { return mountCmd }
func SgdiskCmd() string { return sgdiskCmd }
func PartxCmd() string { return partxCmd }
func ModprobeCmd() string { return modprobeCmd }
func UdevadmCmd() string { return udevadmCmd }
func UsermodCmd() string { return usermodCmd }
Expand Down
12 changes: 12 additions & 0 deletions internal/exec/stages/disks/partitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"
"io/ioutil"

Check failure on line 25 in internal/exec/stages/disks/partitions.go

View workflow job for this annotation

GitHub Actions / Test (1.20.x)

SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)
"os"
"os/exec"
"path/filepath"
"regexp"
"sort"
Expand All @@ -32,6 +33,7 @@ import (

cutil "github.com/coreos/ignition/v2/config/util"
"github.com/coreos/ignition/v2/config/v3_5_experimental/types"
"github.com/coreos/ignition/v2/internal/distro"
"github.com/coreos/ignition/v2/internal/exec/util"
"github.com/coreos/ignition/v2/internal/sgdisk"
)
Expand Down Expand Up @@ -536,6 +538,16 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
return fmt.Errorf("commit failure: %v", err)
}

if len(activeParts) > 0 {
// In contrast to similar tools, sgdisk does not trigger the update of the
// kernel partition table with BLKPG but only uses BLKRRPART which fails
// as soon as one partition of the disk is mounted
cmd := exec.Command(distro.PartxCmd(), "-u", "-", blockDevResolved)
if _, err := s.Logger.LogCmd(cmd, "triggering partition table reread on %q", devAlias); err != nil {
return fmt.Errorf("re-reading partitions failed: %v", err)
}
}

// It's best to wait here for the /dev/ABC entries to be
// (re)created, not only for other parts of the initramfs but
// also because s.waitOnDevices() can still race with udev's
Expand Down

0 comments on commit 612571a

Please sign in to comment.