Skip to content

Commit 204e09f

Browse files
committed
sgdisk: Run partx after partition changes
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.
1 parent de4da0e commit 204e09f

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

docs/release-notes.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ nav_order: 9
1515

1616
### Changes
1717

18+
- The Dracut module now installs partx
1819

1920
### Bug fixes
2021

2122
- Prevent races with udev after disk editing
23+
- Force partition table update after repartitioning, even if one partition is already mounted
2224

2325

2426
## Ignition 2.16.2 (2023-07-12)

dracut/30ignition/module-setup.sh

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ install() {
3333
mkfs.xfs \
3434
mkswap \
3535
sgdisk \
36+
partx \
3637
useradd \
3738
userdel \
3839
usermod \

internal/distro/distro.go

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var (
3737
mdadmCmd = "mdadm"
3838
mountCmd = "mount"
3939
sgdiskCmd = "sgdisk"
40+
partxCmd = "partx"
4041
modprobeCmd = "modprobe"
4142
udevadmCmd = "udevadm"
4243
usermodCmd = "usermod"
@@ -90,6 +91,7 @@ func GroupdelCmd() string { return groupdelCmd }
9091
func MdadmCmd() string { return mdadmCmd }
9192
func MountCmd() string { return mountCmd }
9293
func SgdiskCmd() string { return sgdiskCmd }
94+
func PartxCmd() string { return partxCmd }
9395
func ModprobeCmd() string { return modprobeCmd }
9496
func UdevadmCmd() string { return udevadmCmd }
9597
func UsermodCmd() string { return usermodCmd }

internal/sgdisk/sgdisk.go

+7
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ func (op *Operation) Commit() error {
121121
if _, err := op.logger.LogCmd(cmd, "deleting %d partitions and creating %d partitions on %q", len(op.deletions), len(op.parts), op.dev); err != nil {
122122
return fmt.Errorf("create partitions failed: %v", err)
123123
}
124+
// In contrast to similar tools, sgdisk does not trigger the update of the
125+
// kernel partition table with BLKPG but only uses BLKRRPART which fails
126+
// as soon as one partition of the disk is mounted
127+
cmd = exec.Command(distro.PartxCmd(), "-u", "-", op.dev)
128+
if _, err := op.logger.LogCmd(cmd, "triggering partition table reread on %q", op.dev); err != nil {
129+
return fmt.Errorf("re-reading partitions failed: %v", err)
130+
}
124131

125132
return nil
126133
}

0 commit comments

Comments
 (0)