Skip to content

Only first partition is aligned to 4MiB

This is related to !208 (closed) where the 1st partition is started at 4MiB or 8192s.
If you want (consistent) proper alignment, all the start sectors should be divisible by 8192 with 0 remainder. Or the number of sectors (except the last one).
That is however not the case.

Simply put, the end sector (and thereby the number of sectors) should be 1 less then it is. If you then remove the spacing between the partitions (like here), then all the partitions would be aligned properly at 4MiB boundaries. Alternatively, you make the size 1MiB smaller and keep the spacing. This is assuming that all partition sizes now are 'cleanly' divisible by 4, which a quick glance seem to indicate.

I think that the root of the problem is that parted doesn't handle then end parameter in mib correctly.
At https://salsa.debian.org/raspi-team/image-specs/-/blob/master/raspi_master.yaml 'we' use % and then parted does seem to do the right thing.
If you convert the mib to sectors (s suffix) and subtract 1, then I believe parted also does the right thing (as it doesn't try to help you, I guess)

The output of fdisk -l (from apparently an 'old' image) shows the problem in detail:

# fdisk -l freedombox-testing-nonfree_latest_raspberry3-b-plus-armhf.img
Disk freedombox-testing-nonfree_latest_raspberry3-b-plus-armhf.img: 3.71 GiB, 3984588800 bytes, 7782400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x210012fc

Device                                                         Boot  Start     End Sectors  Size Id Type
freedombox-testing-nonfree_latest_raspberry3-b-plus-armhf.img1        2048  124928  122881   60M  c W95 FAT32 (LBA)
freedombox-testing-nonfree_latest_raspberry3-b-plus-armhf.img2 *    126976  389120  262145  128M 83 Linux
freedombox-testing-nonfree_latest_raspberry3-b-plus-armhf.img3      391168 7782399 7391232  3.5G 83 Linux

And here's the output from an image created with (RPi) image-specs:

# fdisk -l raspi_3_bullseye.img 
Disk raspi_3_bullseye.img: 1.46 GiB, 1572864000 bytes, 3072000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x8efe20ed

Device                Boot  Start     End Sectors  Size Id Type
raspi_3_bullseye.img1        8192  614399  606208  296M  c W95 FAT32 (LBA)
raspi_3_bullseye.img2      614400 3071999 2457600  1.2G 83 Linux
Edited by Diederik de Haas