pop-os / distinst

Installer Backend
GNU Lesser General Public License v3.0
221 stars 43 forks source link

Partitions are 1 sector smaller than expected and not aligned to 1 MiB boundaries #305

Open acodegazer opened 2 years ago

acodegazer commented 2 years ago

Distribution: Pop!_OS 22.04 LTS

Related Application and/or Package Version: The Pop!_OS 22.04 LTS installer.

Issue/Bug Description: Each partition's end sector is 1 sector less than expected. For example, a 498 MiB Boot EFI partition starting at 4096 should end at 1023999 with a size of 1019904 sectors. However, it ends at 1023998 with a size of 1019903 sectors. The next partition starts at 1024000 as expected. This happens when doing a custom install or a clean install. There seems to be an off-by-one bug somewhere.

For a clean install, I noticed that the end of the root partition and start of the swap partition were not aligned at 1 MiB boundary. It seems the root partition is sized at whatever fits between fixed recovery and swap partitions.

Steps to reproduce (if you know): Perform either a clean install or custom install.

Expected behavior: Partitions should be fully sized and aligned to 1 MiB boundaries.

Other Notes: I tested installations to a USB drive and to an SSD.

Here is an installer log excerpt. Note the incorrect partition sizes; I think it's calculated with end - start when it should be end - start + 1:

[INFO distinst:crates/disk-ops/src/ops.rs:221] creating partition (PartitionCreate { path: "/dev/sdb", start_sector: 4096, end_sector: 1023999, format: true, file_system: Some(Fat32), kind: Primary, flags: [PED_PARTITION_ESP], label: None }) on /dev/sdb
[INFO distinst:crates/disk-ops/src/parted.rs:20] opening device at /dev/sdb
[INFO distinst:crates/disk-ops/src/mkpart.rs:81] creating new partition with 1019903 sectors: 4096 - 1023999
[INFO distinst:crates/disk-ops/src/parted.rs:31] opening disk at /dev/sdb
[INFO distinst:crates/disk-ops/src/mkpart.rs:124] committing new partition (4096:1023999) on /dev/sdb
[INFO distinst:crates/disk-ops/src/parted.rs:62] committing changes to /dev/sdb
[INFO distinst:crates/disk-ops/src/parted.rs:78] syncing device at /dev/sdb
[INFO distinst:crates/disk-ops/src/parted.rs:8] getting device at /dev/sdb
[INFO distinst:crates/disk-ops/src/parted.rs:31] opening disk at /dev/sdb
[INFO distinst:crates/disk-ops/src/ops.rs:221] creating partition (PartitionCreate { path: "/dev/sdb", start_sector: 1024000, end_sector: 15693823, format: true, file_system: Some(Ext4), kind: Primary, flags: [], label: None }) on /dev/sdb
[INFO distinst:crates/disk-ops/src/parted.rs:20] opening device at /dev/sdb
[INFO distinst:crates/disk-ops/src/mkpart.rs:81] creating new partition with 14669823 sectors: 1024000 - 15693823
[INFO distinst:crates/disk-ops/src/parted.rs:31] opening disk at /dev/sdb
[INFO distinst:crates/disk-ops/src/mkpart.rs:124] committing new partition (1024000:15693823) on /dev/sdb
[INFO distinst:crates/disk-ops/src/parted.rs:62] committing changes to /dev/sdb

Looking at https://github.com/pop-os/distinst/blob/master/crates/disk-ops/src/mkpart.rs I think line 67 should be let length = partition.get_sector_end() - partition.get_sector_start() + 1; and line 79 should be let (start, end) = (geometry.start(), geometry.start() + geometry.length() - 1);