tookit: switch from parted to sfdisk - #18429
Open
Muhammad Falak R Wani (mfrw) wants to merge 2 commits into
Open
tookit: switch from parted to sfdisk#18429Muhammad Falak R Wani (mfrw) wants to merge 2 commits into
Muhammad Falak R Wani (mfrw) wants to merge 2 commits into
Conversation
The `udevadm settle` command is commonly used to wait for udev to read a disk and populate the disk's metadata in the kernel. While this works most of the time, it is well known `udevadm settle` isn't quite enough to guarantee that the metadata population has finished. In theory, `udevadm wait` is new command that does provide that guarantee. But that command isn't widely available yet. This change works around this problem by adding a wait loop that checks the kernel's cached disk's metadata and compares it to the expected values read directly from disk. This change also replaces the usage of `partprobe` with a call to the `BLKRRPART` (block device read partition) IOCTL syscall. This was done because `partprobe` manually handles the partition node updates. Whereas, calling `BLKRRPART` allows the kernel to handle the update, which is more efficient and reliable. Ported from microsoft/azure-linux-image-tools#140. Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
Switch from using `parted` for creating partitions to using `sfdisk` instead. The `sfdisk` API is slightly nicer to use. For example, we only need a single call to `sfdisk` to provision a partition, instead of multiple calls to `parted`. Also, `sfdisk` acquired some (GPT) features a lot earlier than `parted`. So, using `sfdisk` allows us to avoid disabling features for older versions of `parted`. In addition, this avoids an annoying patch[1] in Ubuntu which calls `udevadm settle` in `parted` which can cause our code to deadlock in Ubuntu 24.04. [1] https://git.launchpad.net/ubuntu/+source/parted/tree/debian/patches/udevadm-settle.patch Ported from microsoft/azure-linux-image-tools#164. Note: unlike upstream, `parted` is kept in the tool dependency list and the prerequisite docs because `shrinkfilesystems.go` in this repo still invokes `parted resizepart`. Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
Muhammad Falak R Wani (mfrw)
marked this pull request as ready for review
August 14, 2026 15:03
Muhammad Falak R Wani (mfrw)
requested review from
Daniel McIlvaney (dmcilvaney) and
jslobodzian
August 14, 2026 15:05
jslobodzian
approved these changes
Aug 14, 2026
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.
partedtosfdisk.*Switch from using
partedfor creating partitions to usingsfdiskinstead. The
sfdiskAPI is slightly nicer to use. For example, weonly need a single call to
sfdiskto provision a partition, insteadof multiple calls to
parted. Also,sfdiskacquired some (GPT)features a lot earlier than
parted. So, usingsfdiskallows us toavoid disabling features for older versions of
parted. In addition,this avoids an annoying patch[1] in Ubuntu which calls
udevadm settlein
partedwhich can cause our code to deadlock in Ubuntu 24.04.[1] https://git.launchpad.net/ubuntu/+source/parted/tree/debian/patches/udevadm-settle.patch
Ported from microsoft/azure-linux-image-tools#164.
Note: unlike upstream,
partedis kept in the tool dependency list andthe prerequisite docs because
shrinkfilesystems.goin this repo stillinvokes
parted resizepart.The
udevadm settlecommand is commonly used to wait for udev to reada disk and populate the disk's metadata in the kernel. While this works
most of the time, it is well known
udevadm settleisn't quite enoughto guarantee that the metadata population has finished. In theory,
udevadm waitis new command that does provide that guarantee. But thatcommand isn't widely available yet.
This change works around this problem by adding a wait loop that checks
the kernel's cached disk's metadata and compares it to the expected
values read directly from disk.
This change also replaces the usage of
partprobewith a call to theBLKRRPART(block device read partition) IOCTL syscall. This was donebecause
partprobemanually handles the partition node updates.Whereas, calling
BLKRRPARTallows the kernel to handle the update,which is more efficient and reliable.
Ported from microsoft/azure-linux-image-tools#140.