Skip to content

tookit: switch from parted to sfdisk - #18429

Open
Muhammad Falak R Wani (mfrw) wants to merge 2 commits into
3.0-devfrom
mfrw/update-for-latest-ubuntu
Open

tookit: switch from parted to sfdisk#18429
Muhammad Falak R Wani (mfrw) wants to merge 2 commits into
3.0-devfrom
mfrw/update-for-latest-ubuntu

Conversation

@mfrw

Copy link
Copy Markdown
Member
    • Switch from parted to sfdisk.*

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.

  • Ensure partition metadata is populated in kernel.

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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.0-dev PRs Destined for AzureLinux 3.0 Tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants