How to correctly set an image to safely "Expand on First Boot"

Greetings!

While working with the GoPiGo O/S 3.0.1 V2 image I uploaded, I discovered a SERIOUS BUG in the expansion script I was provided.  If the image is loaded onto a SD card or other media with other partitions, all other partitions are destroyed!

(I will document this on the Corrected GoPiGo OS thread)
[insert link here when done]

As a consequence, I did additional research into how Raspbian and/or Raspberry Pi O/S

It turns out that all the jumping through hoops that everyone does is not necessary as the necessary logic is part of the operating system as designed.  (At least for anything re-spun from a Raspbian version.)

Viz:.

  1. There is an extra command in the cmdline.txt file:
    init=/usr/lib/raspi-config/init_resize.sh
  2. Apparently the /usr/lib/raspi-config/init_resize.sh
    • Does all the heavy lifting.
    • Provides a notification pop-up on the screen.
       

There’s only one kicker:
If this is the first boot and the partition does NOT need to be resized, it will stop with a dialog that expects you to hit “OK” to continue - and this can only be done from an attached monitor, (AFAIK), because the boot process is only about half-done.

So, to summarize:

  1. If you want to create an image that automatically re-expands on first boot safely, you add init=/usr/lib/raspi-config/init_resize.sh to the end of the cmdline.txt file.
1 Like