I want to create a image file that contains two partitions:

  1. 100MB FAT Boot partition that contains my kernel zImage and dtb(device tree blob) files.
  2. 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.

1 Answer 1


It's an easy task! Just follow these 15 steps.


  1. Allocate a file space with fallocate -l 500M sd.img.
  2. Use fdisk(dos partition table) or gdisk(gpt(guided partition table)) to create partition table sudo fdisk sd.img.
  3. 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.
  4. Redo the third step to create the second partition.
  5. Enter w to save and exit.
  6. Create loop device of your image using sudo kpartx -av sd.img.
  7. Format the partitions sudo mkfs.fat /dev/mapper/loop0p1 and sudo mkfs.ext4 /dev/mapper/loop0p2.
  8. Create a mounting points sudo mkdir /mnt/temp_part1/ & sudo mkdir /mnt/temp_part2/.
  9. Mount the partitions sudo mount /dev/mapper/loop0p1 /mnt/temp_part1/ and sudo mount /dev/mapper/loop0p2 /mnt/temp_part2/ .
  10. copy your content into the mounting points.
  11. sync sudo sync.
  12. Unmount them sudo umount /dev/mapper/loop0p1 /mnt/temp_part1/ and sudo umount /dev/mapper/loop0p2 /mnt/temp_part2/
  13. Delete loop devices sudo kpartx -d sd.img
  14. Flash your image on your sdcard using any flasher software on any OS. I use BalenaEtcher.
  15. Enjoy your SD Card!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .