I'm using buildroot to generate a Linux system for RPi. As output I get rootfs.tar and zImage. From that output (and some other files) I would like to generate a ready SD card image so it can be installed using dd. How can I do that (if possible automated using bash)? The image has two partitions: small VFAT and bigger for root fs.

1 Answer 1


Not sure if there is a better way. That works for me:


if [ -z "$1" ]; then
    echo "provide the path to buildroot folder as parameter"
    exit 1

echo "Generating SD card image"
cd build/
rm -f sdcard.img
rm -rf boot
rm -rf root
dd if=/dev/zero of=./sdcard.img bs=1M count=250
losetup /dev/loop0 ./sdcard.img
echo -e "o\nn\np\n1\n\n+60M\nn\np\n2\n\n\nt\n1\nb\np\nw" | fdisk /dev/loop0
losetup -o 1048576 /dev/loop1 /dev/loop0
losetup -o 63963136 /dev/loop2 /dev/loop0
mkfs.vfat /dev/loop1
mkfs.ext3 /dev/loop2
mkdir boot
mkdir root
mount /dev/loop1 ./boot
mount /dev/loop2 ./root
cp $1/output/images/*.dtb ./boot
#cp $1/output/images/zImage ./boot
cp $1/output/images/rpi-firmware/* ./boot
tar xf $1/output/images/rootfs.tar -C ./root
$1/output/host/usr/bin/mkknlimg $1/output/images/zImage ./boot/zImage

# copy other staff to root fs

echo "Finishing"
umount ./boot
umount ./root
rm -r boot
rm -r root
losetup -D

You must log in to answer this question.

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