Partition range operations
feclora’s whole-disk image format stores the raw disk payload and an associated sfdisk partition-table snapshot. A partition can therefore be selected from an existing whole-disk image without first restoring the entire disk.
Implemented core
src/feclora/storage/partition_range.py provides:
- Strict parsing of
sfdisk --jsonwith duplicate-key rejection, plus parsing of thesfdisk --dumptext artifact currently produced by whole-disk capture. - Conversion of partition start/size sectors into byte offsets and lengths.
- Bounds checks against the whole-disk image size.
- Duplicate-node and overlapping-range rejection.
- Exact selection by partition device node, PARTUUID or partition name; ambiguous selectors fail closed.
- Bounded
pread/pwritecopying of a selected byte range, SHA-256 calculation, progress callbacks and cancellation.
Disk-image extraction workflow now integrated
The extracted raw artifact is retained in the image repository as a separately manifested image. It is not automatically deleted after restore, allowing audit/retry but consuming repository space.
Remaining integration and validation
The remaining caller responsibilities are:
- Load and authenticate the image manifest and verify the whole-disk image digest before trusting its partition table.
- Obtain the actual logical sector size and validate it against image metadata.
- Present the partition list and require independent local target selection.
- Run the existing mounted/root/system-device protections and destructive confirmation before opening the target.
- Ensure the selected destination partition is large enough and compatible with the source partition’s filesystem/content.
- Read the destination back and compare SHA-256 before recording success.
Partition-to-partition cloning can reuse the same bounded copier with source offset zero and the source partition’s exact byte length. Whole-disk-image-to-partition restore uses the selected partition’s offset and length from the validated partition table. The code must never infer a destination from a remote image or remote host.
Direct partition cloning
src/feclora/storage/partition_clone.py implements offline partition-to-partition cloning. It independently inspects both partition geometries, requires equal logical sector sizes and a destination at least as large as the source, rejects partitions sharing a physical backing disk, applies the existing fail-closed mounted/root/busy-device checks, streams the exact source partition byte count through bounded dd pipes, and reads the destination range back for SHA-256 comparison. The Local rescue menu exposes independent source and target selection with an exact ERASE target FROM source confirmation, progress and cancellation. The source is not modified; bytes beyond the source length on a larger destination partition are left unchanged.
Hardware-independent unit tests for partition cloning run as part of make validate using controlled test doubles. They do not write to physical devices; disposable-media acceptance remains an operator task.
Resizing policy
Raw partition-range copying does not resize filesystems. Disk layout planning must be a separate operation. Preserve-layout mode retains partition starts and sizes; proportional growth and selected-partition growth require a previewed, validated sector layout, followed by filesystem-specific growth tools and a final consistency check. EFI, BIOS boot, recovery, swap, LVM and LUKS partitions need explicit policies rather than blind proportional scaling.