File mkimage-nopart.sh of Package altimagebuild

#!/bin/sh
# This script creates an image from a rootfs
#
# by Bernhard M. Wiedemann
# License: MIT

rbase=$1
r=$rbase/.root
img=$rbase/.img
mnt=/mnt/1
uuid=$(printf "%08x" $(($RANDOM$RANDOM &0xffffffff)))-a4ec-4304-a70f-c549ea829da8
dd if=/dev/zero of=$img bs=1M count=2000
# partitioning boot=75MB, swap=75MB, rootfs
echo "
n
p


+75M
t
c
n
p



p
w
" |true fdisk -u $img

# prepare filesystems
modprobe loop
l=$(losetup --find --show $l $img)
#kpartx -afsv $l ; sleep 1
#l2=/dev/mapper/loop\*
#ls -l /dev/mapper/loop*
#ls -l $l2
#mkdosfs   -n BOOT -F32 ${l2}p1
#mkfs.ext2 -L BOOT ${l2}p1
mkfs.ext2 -F -U $uuid -L root ${l}

mkdir $mnt
mount -o loop ${l} $mnt || exit 17
mkdir $mnt/boot
#mount -o loop ${l2}p1 $mnt/boot
rsync -aSHx $r/ $mnt/
#rsync -RS $r/boot/ $mnt/boot/

pushd $mnt
for m in proc sys dev ; do mount --bind /$m $m ; done
chroot $mnt grub2-install --no-bootsector --verbose --skip-fs-probe --target=i386-pc --force ${l}
chroot $mnt grub2-mkconfig | sed -e "s,root=/dev/loop.,root=UUID=$uuid," > $mnt/boot/grub2/grub.cfg
#chroot $mnt update-bootloader --config
chroot $mnt extlinux --install /boot/extlinux/
for m in proc sys dev ; do umount $m ; done
popd

# cleanup
#umount $mnt/boot
umount $mnt
sleep 1
e2fsck -f $l
#kpartx -dsv $l
losetup -d $l

echo result is in $img
echo now write it to an SD-card with dd bs=1M if=$img of=/dev/sdX
openSUSE Build Service is sponsored by