when preserving existing partitions, size: -1 is calculated incorrectly
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
subiquity |
New
|
Undecided
|
Unassigned |
Bug Description
When preserving existing partitions, specifying a partition size as -1 causes curtin to fail. /var/log/
A user-data file is attached that demonstrates the problem. For anybody trying to use it, it is designed to be run on an EFI system. Partitioning is done via an early command.
For the purposes of hard numbers, I tested with a 10GB disk. It has 20971520 sectors. The 512MB ESP partition has 1048576 sectors. The 2048 leading sectors and the 33 trailing sectors of the disk are reserved by GPT or otherwise unused. That leaves 20971520 - 1048576 - 2048 - 33 = 19920863 sectors, which is exactly what is reported by fdisk. For whatever reason, subiquity seems to calculate 19920863 - 2048 + 33 = 19918848 sectors as the size, which it then provides (in bytes) to curtin.
Things work when the partition size is explicitly provided, but this defeats the point of size: -1.
The basic problem is that subiquity reserves 2MiB for GPT, but GPT only reserves 66 sectors (33KiB). When partitioning with sfdisk, as in the provided example, specifying that a partition's size should be "as much as possible" to "end-of-device" causes 33 sectors at the end of the disk to be reserved for GPT. However, the partition size calculated by subiquity effectively reserves 1MiB at the end of the disk.
Superficially, this is a disagreement between GPT, sfdisk, and subiquity over how much to reserve. However, there are other problems with the size calculation done by subiquity. That calculation is effectively:
GPT_OVERHEAD = 2 * (1 << 20)
self.size - self.used - GPT_OVERHEAD
This doesn't account for the actual partition arrangement. If the first partition does not start at sector 2048 or if there are holes in the partition table, then the end of the last partition will not be at 1MiB + self.used.
I think a better approach would do different things depending on whether the partition is to be preserved or not. If it is to be preserved, it would just use the actual size of the partition. If it is not to be preserved, then subiquity should probably account for the last sector of the previous partition.
Finally, when preserving partitions, I don't think the size needs to be required, as partition numbers apparently have to be given anyway:
https:/ /bugs.launchpad .net/subiquity/ +bug/1885638
So to summarize, I have a few suggestions:
1. Don't require size when preserving a partition.
2. Account for position of the end of the last partition.
3. Use the actual partition size when preserving a partition with size: -1.