Re: debian-installer: how to exactly specify partition sizes?
On 11/07/2025 at 00:52, Andy Smith wrote:
You'd expect that specifying "499122176B" (that's 487424 * 1024) would
result in a partition of exactly 487424 1024-byte blocks being created,
right? Nope, it creates one 498073600 bytes long which is exactly 1 MiB
(1048576 bytes) less than what I asked for.
Also trying to use MB or MiB never does result in anything that exactly
matches the other existing partition layout.
I can make the first partition match by manually adding 1048576 bytes
and asking for that. But when I try the same trick with the next
partition, again it gives me something slightly off.
Why does it alter the value I specify? The other machine was installed
using debian-installer so if there is some alignment thing going on,
well, the original one was acceptable to debian-installer so it
shouldn't need to alter the values I specify.
Debian installer's partitioning tool, partman, is based on libparted. By
default, it applies parted's "optimal" alignment constraint. On disks
with 512-byte sector size, it aligns partition start and end positions
on 1-MiB (2048 sectors) boundaries. Additionally, it reserves a gap at
the end of the disk to avoid ambiguity about whether MD RAID 0.90 or 1.0
metadata belong to either the entire disk or the last partition.
Free space and partitions are identified as start-end intervals in
bytes. When creating a partition, partman specifies in which free space
interval, the partition type (primary|logical), the position
(beginning|end|full) and the desired size in bytes (irrelevant if the
position is "full").
The partitioning log is recorded in /var/log/partman during the
installation or in /var/log/installer/partman in the installed system.
Here is an example:
/lib/partman/free_space/50new/do_option: IN: NEW_PARTITION =dev=sda Primary ext2 50105906176-112857186303 full 62800000000
50105906176-112857186303 is the free space start-end interval in bytes
(~62.75 GB).
"full" means that the new partition must use the entire free space.
The desired size was rounded (62.8 GB) from the exact free space size by
the user interface.
parted_server: Read command: NEW_PARTITION
parted_server: command_new_partition()
parted_server: Note =dev=sda as changed
parted_server: Opening outfifo
parted_server: requested partition with type Primary
parted_server: requested partition with file system ext2
parted_server: add_primary_partition(disk(312581808),97863098-220424191)
312581808 is the disk size in sectors (160 GB).
97863098-220424191 is the desired partition start-end interval in
sectors, calculated from the free space start-end interval, desired
partition size and position (beginning|end|full).
parted_server: OUT: OK
parted_server: OUT: 3 50106204160-112857186303 62750982144 primary ext2 /dev/sda3
Here is the actual resulting partition interval and size in bytes. The
start position had to be adjusted to align on the next 1-MiB boundary.
The end position was already aligned.
It is important to note that reported free space intervals do not take
the alignment constraint into account, so the resulting partition size
may be at worst 2-MiB smaller than the desired size. This is blatant
with the first partition at the beginning of the disk: the reported free
space begins right after the partition table (at sector 2 with MSDOS, 34
with GPT), so partman will request to create a partition in interval
34-(34+desired size), then will align the start sector to 2048. This
results in a partition being 1-MiB smaller than expected.
The free space after the first partition is aligned, so the next primary
partition sizes should not be altered if they are multiple of 1 MiB. On
MSDOS, logical partition size is reduced by 1 MiB because of the nested
extended partition table before each logical partition.
Reply to: