I want to create a image file that contains two partitions:
100MB FAT Boot partition that contains my kernel zImage and dtb(device tree blob) files.
900MB EXT4 Rootfs partition that contains my root file system.
Then I want to be able to flash that image file to any sdcard to boot may linux board.
How can I do this and what tools I need? (I prefer cli based tools rather than GUI)
Note: I have my kernel zImage and DTB and rootfs already and I need to make an sdcard bootable image of all of them to easily burn it on any sdcard. But for now I don't have an sdcard. I'll buy my sdcards later. first I want to have the image ready and when I buy them I'll flash the image on all of them swiftly.
Allocate a file space with fallocate -l 500M sd.img.
Use fdisk(dos partition table) or gdisk(gpt(guided partition table)) to create partition table sudo fdisk sd.img.
After opening fdisk, create a partition by pressing n and then press p to create a primary partition and then just press enter to leave everything by default, except the "Last sector" option. enter +100M to create a 100MB partition.
Redo the third step to create the second partition.
Enter w to save and exit.
Create loop device of your image using sudo kpartx -av sd.img.
Format the partitions sudo mkfs.fat /dev/mapper/loop0p1 and sudo mkfs.ext4 /dev/mapper/loop0p2.