I cannot modify partition size afterwards using on target linux, because this is the partition of root filesystem on which Linux is working.
This is not true when extending a file system. The manual for resize2fs says:
If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the kernel supports on-line resizing. (As of this writing, the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 and ext4.).
So you can create a much smaller image, copy it onto the device then use resize2fs to extend the file system:
resize2fs /dev/mmcblok0
There is an alternative method that's dependent on the hardware you're using. It's complicated so I can give an outline for the technique, but I'll avoid writing out exact steps to use this technique.
The technique there is to create an image with a re-configured bootloader.
This is designed to run directly from an sd card. The bootloader starts up Linux, telling it to directly run a script (rather than the regular /sbin/init). The script then:
- formats internal flash
- mounts internal flash to /mnt
- copies all files from the sd card to /mnt
- re-configures the bootloader in /mnt/boot to run /sbin/init instead of the script.
- Shuts down linux