@anthony winner thanks a lot for sharing your script. One little thing I don't understand:
echo "$datafs /home ${mkfs[$ROOTFS_TYPE]} defaults,noatime${mountopts[$ROOTFS_TYPE]} 0 2" >> $SDCARD/etc/fstab
here $datafs will contains something like "/dev/loop19p2", but it should be a real partition name then the device runs.