Creating an ext2 partition (and resizing rootfs)

Continuing the discussion from Does this even work on a Raspberry Zero !?:


To create an ext2 partition using RPiOS 32bit Lite image; this works on a PiZ v1.3 (not W I used a dongle)

  1. Flash using Rasp Imager (setting Wi-Fi, SSH etc)
  2. In Windows, create a partition using the Disk Manager (size is irrelevant) in free space. [this prevents firstboot doing its expansion]
  3. Boot card in Pi.
  4. Do the following;
## delete additional partition
sudo parted /dev/mmcblk0 rm 3
## create a new partition at the end - the 20G is the start point for the end partition (rough guess)
## Can vary depending on size of card of course. For testing make it small so the mkfs doesn't take an age!!
echo "20G, +" | sudo sfdisk --force -N 3 /dev/mmcblk0
sudo partprobe
## Expand the root partition in the space available
echo ", +" | sudo sfdisk --force -N 2 /dev/mmcblk0
sudo partprobe
## resize the rootfs
sudo resize2fs /dev/mmcblk0p2
## Format the new partition
sudo mkfs.ext2 -b 1024 /dev/mmcblk0p3
## pull down the fstab as before
sudo mv fstab /etc/fstab
sudo reboot now

And bingo. Thanks to @Bramco for the idea of creating a partition in the free space - inspired.

For the emonSD you can do all this and then use the sfdisk commands to expand and fill. I’d do it as a separate script so it is clear the mkfs is running as it takes an age (as you know).

Instead of creating the ext2 from a fixed point, you could specify the size of the rootfs and then fill the remaining with the ext2. (only reference I found using sfdisk this way Karel Zak's blog: resize by sfdisk)

Now to work out why the scripts are not quite running!

Useful commands to see what sizes are what

sudo fdisk -l /dev/mmcblk0*
sudo lsblk
sudo parted -l
sudo sfdisk -d /dev/mmcblk0

Credit where credit is due, I think it was @emonsouth that suggested this approach. I was letting Raspbian do it’s thing, then making the 2nd partition smaller with Gparted and creating the ext2 in the new space.

Brian, the sfdisks throw up some warnings and failures - is there a way to prepare the system before these are used, unmounting the partitions?

Also, given people will be using (probably) either 16G or 32G SD cards, should there be 2 versions of the instructions to expand the 2nd partition to as big as is needed for emoncms with plenty of space left over for other things and then take up the remainder for the 3rd partition. This would be smaller on the 16G card of course.


I’m sure that not everyone knows that you can use the ‘gear’ symbol on the Imager tool to set these up. Might be worth adding this to the instructions.

Again, this might need more explanation - Windows Disk Manager talks about volumes and the need to assign a drive letter which can be confusing.


I wasn’t anticipating this was a complete HowTo!

I also anticipate that anyone who knows enough to do this, knows more than just the basic.

You can just leave the defaults when you create that partition. You are deleting it after booting into the system so it does not matter

1 Like