User avatar
Milliways
Posts: 518
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Gap in Raspbian images

Wed Sep 25, 2019 8:02 am

I was just looking at my Raspbian and there seemed to be a 4MB gap between the end of the boot partition and the start of the root, confirmed in gparted.

Thinking this may be an artefact of the image copying utilities I use I checked against a downloaded Raspbian image (2019-07-10-raspbian-buster-lite) which has the same gap.

Is there any reason for the gap? It is not big enough to worry about or worth the effort to modify.

User avatar
Paeryn
Posts: 2836
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Gap in Raspbian images

Wed Sep 25, 2019 8:40 am

Generally it's down to optimisations for the SD card like trying to make sure the two partitions are in different erase blocks. This reduces the wear and hopefully limits the erase/write block operations on one partition from affecting another.
She who travels light — forgot something.

Kendek
Posts: 145
Joined: Thu Jul 25, 2019 4:39 pm
Location: Kaposvár, Hungary

Re: Gap in Raspbian images

Wed Sep 25, 2019 8:41 am

It's because the first, FAT32 boot partition is larger exactly one sector than the ideal.

256 MiB (524288s) proper last sector = 8192 + 256 * 1024 * 1024 / 512 - 1 = 532479

If the last sector is 532480 (so 256 MiB + 512 bytes), then the first sector for the second partition is 540672.

Code: Select all

parted /dev/mmcblk0
unit s
print

User avatar
Milliways
Posts: 518
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: Gap in Raspbian images

Wed Sep 25, 2019 9:45 am

Paeryn wrote:
Wed Sep 25, 2019 8:40 am
Generally it's down to optimisations for the SD card like trying to make sure the two partitions are in different erase blocks. This reduces the wear and hopefully limits the erase/write block operations on one partition from affecting another.
I understand why partitions should be aligned on an Erase Block Boundary.

The boot partition is aligned with a 4MB Erase Block Boundary, its size is a multiple of 4MB , so is the root partition aligned with a 4MB Erase Block Boundary, but it would if it started at 532480 immediately following the boot partition.

Kendek
Posts: 145
Joined: Thu Jul 25, 2019 4:39 pm
Location: Kaposvár, Hungary

Re: Gap in Raspbian images

Wed Sep 25, 2019 9:49 am

Milliways wrote:
Wed Sep 25, 2019 9:45 am
The boot partition is aligned with a 4MB Erase Block Boundary, its size is a multiple of 4MB , so is the root partition aligned with a 4MB Erase Block Boundary, but it would if it started at 532480 immediately following the boot partition.
Yes, but currently the first partition ends in sector 532480, so the next partition is started at 264 MiB.

User avatar
Milliways
Posts: 518
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: Gap in Raspbian images

Wed Sep 25, 2019 11:11 am

Kendek wrote:
Wed Sep 25, 2019 9:49 am
Milliways wrote:
Wed Sep 25, 2019 9:45 am
The boot partition is aligned with a 4MB Erase Block Boundary, its size is a multiple of 4MB , so is the root partition aligned with a 4MB Erase Block Boundary, but it would if it started at 532480 immediately following the boot partition.
Yes, but currently the first partition ends in sector 532480, so the next partition is started at 264 MiB.
That just changes the focus of the question; why is the boot partition size set incorrectly?

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6195
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Gap in Raspbian images

Wed Sep 25, 2019 11:18 am

If you would like to fix it, a PR can be sent here https://github.com/RPi-Distro/pi-gen/bl ... run.sh#L26

Kendek
Posts: 145
Joined: Thu Jul 25, 2019 4:39 pm
Location: Kaposvár, Hungary

Re: Gap in Raspbian images

Wed Sep 25, 2019 12:42 pm

ShiftPlusOne wrote:
Wed Sep 25, 2019 11:18 am
If you would like to fix it, a PR can be sent here https://github.com/RPi-Distro/pi-gen/bl ... run.sh#L26

Code: Select all

16 - ROUNDED_ROOT_SECTOR=$(((BOOT_SIZE + ROUND_SIZE) / ROUND_SIZE * ROUND_SIZE / 512 + 8192))
16 + ROUNDED_ROOT_SECTOR=$(((BOOT_SIZE + ROUND_SIZE) / 512))

26 - +$((BOOT_SIZE / 512))
26 + +$((BOOT_SIZE / 512 - 1))
But there is already a fix:
https://github.com/RPi-Distro/pi-gen/pull/285

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6195
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Gap in Raspbian images

Wed Sep 25, 2019 12:47 pm

Ah, I knew it rang a bell. Thank you.

ejolson
Posts: 4493
Joined: Tue Mar 18, 2014 11:47 am

Re: Gap in Raspbian images

Thu Sep 26, 2019 3:43 am

ShiftPlusOne wrote:
Wed Sep 25, 2019 12:47 pm
Ah, I knew it rang a bell. Thank you.
Has anyone checked whether the gap is full of zeros or whether it contains a secret message?

User avatar
rpdom
Posts: 16380
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Gap in Raspbian images

Thu Sep 26, 2019 6:34 am

ejolson wrote:
Thu Sep 26, 2019 3:43 am
ShiftPlusOne wrote:
Wed Sep 25, 2019 12:47 pm
Ah, I knew it rang a bell. Thank you.
Has anyone checked whether the gap is full of zeros or whether it contains a secret message?
Like the BBC Micro OS ROM that had an area of memory mapped I/O ports over part of it and that (normally inaccessible) area of the ROM had the names of all the developers in it?

Or the time I was given a floppy disk from an Acorn developer and looked at the unused space on it and found fragments of text files that contained details about the original ARM design plans.

Return to “General discussion”