Skip to content

Support configurable sector size for raw/WIC images#156

Open
vdskvortsov wants to merge 1 commit into
torizon:trixiefrom
EmcraftSystems:raw-image-sector-size
Open

Support configurable sector size for raw/WIC images#156
vdskvortsov wants to merge 1 commit into
torizon:trixiefrom
EmcraftSystems:raw-image-sector-size

Conversation

@vdskvortsov

@vdskvortsov vdskvortsov commented Jul 15, 2026

Copy link
Copy Markdown

Problem

The raw/WIC image path assumes a 512-byte logical sector throughout. On 4Kn media (such as UFS on the MediaTek Genio target) the WIC has a 4096-byte sector, so libguestfs mis-reads the partition table and deploy / combine / images unpack / images provision fail.

Change

Add --raw-sector-size {512,4096} (and tcbuild sector-size: / base-sector-size: keys), threaded to every open_disk_image()add_drive_opts(blocksize=N). virt-resize can't open a 4Kn disk, so for non-512 sectors the image is grown with libguestfs directly: enlarge the file, part_expand_gpt, and extend the last partition — preserving its GPT identity so it still boots — then reformat. The rootfs must be the last partition (checked), which holds for WIC layouts. Default stays 512, so existing images are unaffected.

Context

Prompted by torizon/meta-toradex-torizon#570, where 4Kn handling was done by patching the container externally; this option removes that need.

Testing

Validated on a MediaTek Genio 1200 with 4Kn UFS: a customization exceeding the base rootfs partition exercised the grow path, and the target booted with the rootfs grown (1.6 → 5.0 GiB) and the payload present. The 512-byte path is unchanged — verified on an STM32MP target.

@jsrc27 jsrc27 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No major comments on my end, just a minor one.

Comment thread tcbuilder/backend/common.py
@jsrc27

jsrc27 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Oh and also pylint is failing. Looks like it's due to many arguments/variables in some functions, due to the addition of the sector size variable everywhere in this PR. Typically for too many arguments/variables we just decide to suppress the pylint error in the sections of affected code.

Not sure if there is a way to condense this in the PR, but probably not with sector size being needed everywhere.

Add a --raw-sector-size option, plus tcbuild sector-size: (input) and
base-sector-size: (output) keys, so the raw/WIC image path can operate
on 4Kn media such as some UFS targets. The value is threaded to every
libguestfs open via add_drive_opts(blocksize=...).

virt-resize drives libguestfs at 512 bytes and cannot open a 4Kn disk,
so for non-512 sectors the output image is grown with libguestfs
directly: the file is enlarged and the last (rootfs) partition is
extended to fill it, preserving the partition's GPT identity (name,
type, GUID and attributes), then reformatted as usual.

Default stays 512, so existing 512-byte-sector images are unaffected.

Signed-off-by: Vladimir Skvortsov <vskvortsov@emcraft.com>
@vdskvortsov
vdskvortsov force-pushed the raw-image-sector-size branch from dc301bc to 9ae6236 Compare July 17, 2026 08:03
@vdskvortsov

Copy link
Copy Markdown
Author

Fixed — suppressed too-many-positional-arguments (and too-many-locals where it also tripped) on the four functions that gained the sector_size parameter, matching the existing convention (e.g. in deploy.py). Ran the CI lint-python pylint locally over the whole tree and it is back to 10.00/10.

@lucas-akira lucas-akira left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice addition overall, code changes look good to me. I have one minor note on a comment.

try:
gfs = guestfs.GuestFS(python_return_dict=True)
gfs.add_drive_opts(image_path, format="raw", readonly=readonly)
# blocksize optarg needs libguestfs >= 1.44; omit it on the default path.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I found the blocksize parameter was added to add_drive_opts in libguestfs 1.42, not 1.44:

https://libguestfs.org/guestfs-release-notes-1.42.1.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants