thepian
Posts: 1
Joined: Wed Jul 21, 2021 5:50 pm

Rearranging partitions on SD Card

Wed Jul 21, 2021 5:59 pm

I've searched for days for a solution. I can find posts about how to remove the FAT partition and just have an ext-4 rootfs, or perhaps change the filesystem used. I want to add an extended partition to the SD Card with partitions not involved in the RPi boot.

I've tried adding partitions to the end, restricting the expansion of the rootfs. This leads to the partition expanding process complaining, but otherwise the booting eventually succeeds.

I've also tried adding partitions after the boot FAT partition, and adding the rootfs partition at the end. This doesn't work.
I imagine that I can change bootcode.bin or config.txt to use the correct rootfs partition. I haven't found the documentation covering this.

The SD Card format that I cannot get to work is:

1. boot FAT
2. extended (unrelated)
3. rootfs ext-4
4. available

It also seems that there needs to be a gap before the boot partition. Is that required or incidental?

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 14138
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Rearranging partitions on SD Card

Thu Jul 22, 2021 12:26 pm

a Raspberry PI can only boot from a FAT32 partition, so the FAT partition is a necessity.

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

Re: Rearranging partitions on SD Card

Thu Jul 22, 2021 12:34 pm

You specify the root partition in cmdline.txt
Make sure you also update the /etc/fstab file on the system, but I think it will boot even if that has the wrong rootfs.
Unreadable squiggle

KeithMck
Posts: 290
Joined: Thu Dec 31, 2020 10:58 am

Re: Rearranging partitions on SD Card

Thu Jul 22, 2021 6:57 pm

You can alter the size of the root partition within /usr/lib/raspi-config/init_resize.sh, either before installing (via another system), or before initial rebooting. The line you need to alter is root_dev_size=$(.....) - I believe they are in 4KB blocks.

RonR
Posts: 2388
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: Rearranging partitions on SD Card

Thu Jul 22, 2021 7:40 pm

thepian wrote:
Wed Jul 21, 2021 5:59 pm
I've searched for days for a solution. I can find posts about how to remove the FAT partition and just have an ext-4 rootfs, or perhaps change the filesystem used.

I assume that was a typo and you meant to say "I can't find posts about how to remove the FAT partition...".

The FAT partition MUST remain as it's crucial to the Raspberry Pi boot process.
thepian wrote:
Wed Jul 21, 2021 5:59 pm
I want to add an extended partition to the SD Card with partitions not involved in the RPi boot.

I would recommend not using an extended partition. It's antiquated and messy.

If you need more than the four primary partitions that MBR partitioning allows, use GPT partitioning which supports up to 128 partitions as well as partition sizes greater than 2TB.
thepian wrote:
Wed Jul 21, 2021 5:59 pm
I've tried adding partitions to the end, restricting the expansion of the rootfs. This leads to the partition expanding process complaining, but otherwise the booting eventually succeeds.

The partition expansion logic implemented in Raspberry Pi OS and raspi-config assumes a normal two-partition layout (BOOT/ROOT) and doesn't support other scenarios.

You will have to handle expansion yourself if you stray from the norm.
thepian wrote:
Wed Jul 21, 2021 5:59 pm
I've also tried adding partitions after the boot FAT partition, and adding the rootfs partition at the end. This doesn't work.
I imagine that I can change bootcode.bin or config.txt to use the correct rootfs partition. I haven't found the documentation covering this.

The SD Card format that I cannot get to work is:

1. boot FAT
2. extended (unrelated)
3. rootfs ext-4
4. available

There's no problem with where ROOT partition(s) reside following the FAT BOOT partition.

MultiBoot supports up to 127 ROOT partitions using GPT partitioning.

Here's an example of 10 Raspberry Pi OS installations on a single device:

Code: Select all

root@FreePBX:~# fdisk -l /dev/sda
Disk /dev/sda: 447.13 GiB, 480103981056 bytes, 937703088 sectors
Disk model: Neutron GTX SSD
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Disklabel type: gpt
Disk identifier: D4840608-E287-41D4-9EFC-7BC40AA20FD5

Device         Start       End  Sectors  Size Type
/dev/sda1       8192    532479   524288  256M Microsoft basic data
/dev/sda2     532480  34086399 33553920   16G Linux filesystem
/dev/sda3   34143735  67697654 33553920   16G Linux filesystem
/dev/sda4   67697655 101251574 33553920   16G Linux filesystem
/dev/sda5  101251575 134805494 33553920   16G Linux filesystem
/dev/sda6  134805495 168359414 33553920   16G Linux filesystem
/dev/sda7  168359415 201913334 33553920   16G Linux filesystem
/dev/sda8  201913335 235467254 33553920   16G Linux filesystem
/dev/sda9  235467255 269021174 33553920   16G Linux filesystem
/dev/sda10 269021175 302575094 33553920   16G Linux filesystem
/dev/sda11 302575095 336129014 33553920   16G Linux filesystem
thepian wrote:
Wed Jul 21, 2021 5:59 pm
It also seems that there needs to be a gap before the boot partition. Is that required or incidental?

No gap is needed before the BOOT partition other than the normal space reserved by partitioning programs (fdisk, gdisk, etc.) for the partition table and block alignment.

swampdog
Posts: 762
Joined: Fri Dec 04, 2015 11:22 am

Re: Rearranging partitions on SD Card

Thu Jul 29, 2021 4:54 am

It must be the extended partition, I've never tried one. Fwiw..

1) /boot/
2) [new primary]
3) /rootfs
f) [free space]

..does work and a standard image will see (3) expand into (f) on first boot. Admittedly this is not documented and could break at any time but I don't see it doing so any time soon. Rather than trying to shuffle the partitions around after the fact, just mount the standard image as a pair of loopback devices, modify to taste (hint: PARTUUID), unmount then 'dd' the loopback devices into (1) and (3) respectively.

Return to “Advanced users”