Support configurable sector size for raw/WIC images#156
Conversation
jsrc27
left a comment
There was a problem hiding this comment.
No major comments on my end, just a minor one.
|
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>
dc301bc to
9ae6236
Compare
|
Fixed — suppressed |
lucas-akira
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
From what I found the blocksize parameter was added to add_drive_opts in libguestfs 1.42, not 1.44:
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 provisionfail.Change
Add
--raw-sector-size {512,4096}(and tcbuildsector-size:/base-sector-size:keys), threaded to everyopen_disk_image()→add_drive_opts(blocksize=N).virt-resizecan'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.