We have a situation where an image file of a Linux distribution is written to a Flash media, such as a USB-stick or an SD-card, and the image is smaller than the actual size of the drive.
For example, an image labeled as "8GB" should in fact be small enough to fit on all 8GB drives, and on many drives there might be a few hundred MB left unused at the end of the drive.
If the "8GB" image is written to a much bigger drive, say 16GB, then of course there is several GB unused.
Some distributions, such as Ubuntu Mate (official image from HardKernel) for the Odroid XU4, perform an automatic reboot at first startup, and grow the partition to fill the drive -- this reboot actually happens just after the login screen appears, without any warning.
I have chosen to be polite and ask at first bootup. QuickSetup displays at first bootup, and there is now a checkbox, that you can tick if you want to grow the partition.
This checkbox will only appear if the unused space immediately after the system partition is greater than 400MB.
I chose this threshold, as I didn't want to bother the user with one more option in the QuickSetup window, when only a small amount will be recovered.
There is a Help button, that informs you how much space is unused, so you can make the decision whether you want to do it.
If you do tick the checkbox, QuickSetup (/usr/sbin/quicksetup) will write "partition,filesystem,MAXSIZE,start-sector,end-sector" to /.fsckme.flg, where 'start-sector" is the sector at which the system partition starts, and "end-sector" is the last sector of the unallocated space immediately past the system partition.
On a reboot, /sbin/init will read /.fsckme.flg and will recognise the label "MAXSIZE", and will create a ramdisk, switch-root into it, then grow the system partition, check the filesystem, then grow the filesystem to fill the bigger partition.
This only works for ext2, ext3 and ext4 filesystems. f2fs does not support filesystem resizing. So in the case of f2fs, the checkbox won't appear in QuickSetup, that is, there won't be an offer to grow the partition.