Skip to content

Several issues with partitioning #284

@matthijskooijman

Description

@matthijskooijman

I had a look at the image partitioning code and noticed some issues:

  1. There is some empty space between the boot and root partitions. Since commit 40eae05 (make root filesystem 4M aligned (make root filesystem 4M aligned #154)), the start of the root partition is aligned, but the boot partition size is unchanged, which leaves some unused space (which is a waste and makes it slightly harder to add a new partition in the remaining space on a disk, which is why I noticed this).
  2. There is an off-by-one in the aligning of the root partition. If the boot partition size is already exactly rounded to 4M increments, the root partition is put 4M after the boot partition, rather than adjacent to it. This is pretty much Image size is rounded up even when already multiple of 4 MB #156, but about a missing -1 in this line:
    ROUNDED_ROOT_SECTOR=$(((2 * BOOT_SIZE + ROUND_SIZE) / ROUND_SIZE * ROUND_SIZE / 512 + 8192))
  3. Sending data into fdisk seems fragile to me. fdisk is, AFAIK, intended to be run interactively and the current script relies on default values and other interactive behaviour which could very well change in future versions.

I had a stab at fixing this with the current fdisk-based approach, which fixes 1) and 2), but obviously not 3). After doing so, I wondered if it would not be better to switch to parted for partition rather than fdisk.

One downside of parted is that, I think, it requires more specific instructions about the partition layout. It has no way to non-interactively say "put root adjacent to boot" without preculculating the exact starting point (note that specifying "use the rest of the disk" is possible by specifying 100%). I suspect this is why fdisk was chosen originally.

However, with the alignment for the root partition that is done now, pretty much the entire partition layout is calculated by prerun.sh already, so it seems sensible to use parted rather than fdisk (parted is already used to print the partition layout, so the dependency is already present).

If this sounds good, I can probably provide a PR to implement this somewhere in the coming days (after that, I'll probably be moving to other projects and might not have time anymore).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions