resizeFilesystem: invoke resize2fs against the partition device, not the whole disk#10
Open
eriknordmark wants to merge 1 commit into
Open
Conversation
When running against a real block device, resizeFilesystem was calling resize2fs (via execResize2fs) with the whole-disk path that the disk.Disk was opened with — e.g. "/dev/sda" — instead of the partition device path "/dev/sda9". resize2fs on the whole disk fails because there is no filesystem at offset 0. Resolve the partition device path by walking /sys/class/block/<disk>/<part>/partition under sysfs and matching on the partition number. This handles the different naming conventions (sda9, nvme0n1p9, mmcblk0p9, …) without having to hardcode them. The disk-image (DeviceTypeFile) branch is unaffected; it continues to copy the partition's bytes out to a temp file, resize that, and copy back. Tests cover the sda-style and nvme-style naming, plus the not-found cases (partition number absent, disk absent). Closes diskfs#9. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
Fixes #9.
When
resizeFilesystemis invoked against a real block device (DeviceTypeBlockDevicebranch), it was handing the whole-disk path toresize2fsrather than the partition device path.resize2fs /dev/sdafinds no filesystem at offset 0 and errors out; what was needed wasresize2fs /dev/sda9(or/dev/nvme0n1p9,/dev/mmcblk0p9, …).Approach
Resolve the partition device path by sysfs lookup rather than hardcoding the naming convention:
The kernel-named partition directory under sysfs always matches the device node under
/dev, so the lookup gives us backsda9,nvme0n1p9,mmcblk0p9, etc. correctly without us having to maintain a naming-convention table.The disk-image (
DeviceTypeFile) branch is unchanged — it continues to copy the partition's bytes out to a temp file, resize that, and copy back.Tests
New
TestPartitionDevicePathcovers:sda→sda9(traditional convention).nvme0n1→nvme0n1p9(the "p"-prefix convention used by NVMe / eMMC / virtio-blk).Uses a fake-sysfs tree under
t.TempDir(), same pattern as the existingTestFindDisks.Test plan
End-to-end against a real block device isn't unit-testable here, but the load-bearing piece is the partition-name resolution, which is now under test.
Signed-off-by: eriknordmark erik@zededa.com