-
Notifications
You must be signed in to change notification settings - Fork 1
Partition Scheme
The multiple partitions that NOOBS4IoT divides your SD card into (at least 5) can be quite overwhelming and confusing. This page will try and explain how it all works, and illustrate how NOOBS4IoT differs from the 'traditional' standalone images.
This article is based on an entry from the NOOBS Wiki and was adopted to reflect the behaviour of NOOBS4IoT.
For historical reasons (only 4 'slots' in the partition table), hard-drives and SD cards can only have a maximum of 4 primary partitions. To work around that limitation, one of those primary partitions can optionally be an extended partition. An extended partition can contain an unlimited number of logical partitions inside it. Under Linux, the primary partitions are always numbered 1-4 (i.e. seen as /dev/mmcblk0p1
- /dev/mmcblk0p4
on the Pi), and any logical partitions are always numbered 5 and above (i.e. seen as /dev/mmcblk0p5
and above on the Pi).
When NOOBS4IoT is first copied to a FAT-format SD card, there's just a single partition taking up all the space on the card, and this is where the files from the NOOBS4IoT zipfile get written to. In tabular form it looks like:
Primary partition | Logical partition | Type | Label | Contents |
---|---|---|---|---|
1 | FAT | New Volume | NOOBS4IoT boot files & initramfs |
When the Raspberry Pi is powered on with a NOOBS4IoT card inserted, it:
- Loads and runs
bootcode.bin
from the FAT-format/dev/mmcblk0p1
, exactly as it does for standalone images. (This behaviour is built into the BCM2835's internal firmware on all Pis, and so can't be changed.) -
bootcode.bin
then spots thatstart.elf
is missing, so it loads and runsrecovery.elf
instead. - Running
recovery.elf
then switches the firmware into "NOOBS4IoT mode" - it usesrecovery.img
instead ofkernel.img
,recovery.cmdline
instead ofcmdline.txt
, and it sets the root filesystem torecovery.rfs
. -
recovery.elf
then readsrecovery.cmdline
and loads and runsrecovery.img
(the Linux kernel), passing it the entire command-line that it read fromrecovery.cmdline
and telling it to loadrecovery.rfs
as the root filesystem (an initramfs containing various scripts and the NOOBS4IoT application). - What happens next depends on which 'mode' NOOBS4IoT is operating in...
If runinstaller
is present in the kernel command-line, then this must be the first time NOOBS4IoT has been booted, so it enters 'setup mode'. It then:
- Automatically shrinks the first (and only) partition
/dev/mmcblk0p1
, making it just large enough to hold whatever files it contains, and labels it as 'RECOVERY'. - Creates a new large empty extended partition
/dev/mmcblk0p2
, using up the vast majority of the remaining card space. - Creates a new small (32MB) ext4-format partition
/dev/mmcblk0p5
at the start of the extended partition, and labels it as 'SETTINGS'. This is used to store files telling NOOBS4IoT which OSes are installed (and what partitions they're installed on) and which OS should be loaded by default. - Removes
runinstaller
fromrecovery.cmdline
to prevent this process from being triggered again.
This then changes the partitions to:
Primary partition | Logical partition | Type | Label | Contents |
---|---|---|---|---|
1 | FAT | RECOVERY | NOOBS4IoT boot files & initramfs | |
2 | extended | Any logical partitions | ||
5 | ext4 | SETTINGS | NOOBS4IoT settings |
If NOOBS4IoT detects that no Operating Systems have been installed yet, or runinstaller
is defined in the recovery.cmdline
, NOOBS4IoT enters 'recovery mode'. This starts the OS installation webserver, allowing the user to choose which OS(es) to install.
In contrast to the standalone images described earlier (which contain raw partitions), NOOBS4IoT instead uses (compressed) tarballs of the partition contents, along with a bunch of settings files. NOOBS4IoT is responsible for actually creating the partitions on the SD card itself, which means the partitions are always created at the "correct" size in the first place, there's no need to resize them later. And unlike the low-level raw partitions, the tarballs don't store unused disk blocks.
For the first example, let's assume that the user is installing just Raspbian. The partitions.json (which can be viewed online here) then specifies which partitions should be created, how big they should be, and which filesystems they should use. In this example it would create a 60MB FAT partition (/dev/mmcblk0p5
), format it, and extract the contents of boot.tar.xz
to it. As the root partition has want_maximised: true
it would then create an ext4 partition (/dev/mmcblk0p6
) filling up the entirety of the rest of the extended partition, format it, and extract the contents of root.tar.xz
to it. This gives us the full partition layout shown in the table earlier. It then runs the partition_setup.sh
script which mounts these new partitions, and edits files (typically just cmdline.txt
on the boot partition and /etc/fstab
on the root partition) to tell Raspbian which partitions it got installed to. This allows Raspbian to adjust itself to being stored on /dev/mmcblk0p6
and /dev/mmcblk0p7
instead of /dev/mmcblk0p1
and /dev/mmcblk0p2
. And finally it updates the settings partition with details of the OS we just installed.
Primary partition | Logical partition | Type | Label | Contents |
---|---|---|---|---|
1 | FAT | RECOVERY | NOOBS4IoT boot files & initramfs | |
2 | extended | Any logical partitions | ||
5 | ext4 | SETTINGS | NOOBS4IoT settings | |
6 | FAT | boot | Raspbian boot files | |
7 | ext4 | root | Raspbian root filesystem |
If instead we were installing Raspbian and ArchLinux then we might end up with ArchLinux's boot partition as /dev/mmcblk0p6
, ArchLinux's root partition as /dev/mmcblk0p7
, Raspbian's boot partition as /dev/mmcblk0p8
and Raspbian's root partition as /dev/mmcblk0p9
. As both Raspbian's and ArchLinux's partitions.json
file specify one of their partitions as want_maximised: true
then we'd end up with two small boot partitions and two large-as-possible root partitions. NOOBS4IoT never 'wastes' any space on an SD card.
Primary partition | Logical partition | Type | Label | Contents |
---|---|---|---|---|
1 | FAT | RECOVERY | NOOBS4IoT boot files & initramfs | |
2 | extended | Any logical partitions | ||
5 | ext4 | SETTINGS | NOOBS4IoT settings | |
6 | FAT | boot | ArchLinux boot files | |
7 | ext4 | root | ArchLinux root filesystem | |
8 | FAT | boot1 | Raspbian boot files | |
9 | ext4 | root1 | Raspbian root filesystem |
If the recovery.cmdline
does not contain runinstaller
or if there is a OS installed, NOOBS4IoT will boot into the partition specified in the default_boot_partition
file on the settings partition. This then 'reboots' the firmware and loads start.elf from the specified partition (typically /dev/mmcblk0p6 if only one OS is installed) and then proceeds the same as the standalone boot described at the very top of this page - start.elf loads kernel.img and reads cmdline.txt, and then kernel.img uses the command-line that was passed to it to determine which partition the root filesystem is stored on (typically /dev/mmcblk0p7 if only one OS is installed), and loads the rest of the system from there.
NOOBS4IoT Documentation by Frank Steiler is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Based on the work at the NOOBS4IoT Github Repository.