2021-01-09
this script is just template, please tweak/adapt it for particular use case.
How to enable boot from external media (mmc or usb flash) is out of this notes. On the Inet could be found good guides about this.
Tools needed are linux machine with cgpt, parted or fdisk and usual linux tools
set proper block device to mmc card on which Alpine will be installed, for example /dev/mmcblk1
when script finishes there will be all needed on mmc card to boot newly installed alpine
when machine boots there will be iwd
(Internet Wireless Daemon) running and device can connect to wifi network
with iwctl
iwd utility
Packages installed by this script are minimally needed, rest can installed when the machine boots
usual disclaimer: no one is responsible for any damage/loss by using this
#!bin/sh
instdir="/mnt/elm"
device="/dev/mmcblk1"
kernel="${device}p1"
root="${device}p2"
parted -s $device mktable gpt
cgpt create $device
cgpt add -i 1 -t kernel -b 8192 -s 65536 -l Kernel -S 1 -T 5 -P 10 $device
cgpt add -i 2 -t data -b 73728 -s 15187959 -l Root $device
partprobe $device
mkfs.f2fs -f -l elm.rfs $root
sync
#exit
echo "making dirs and mounting"
rm -rf $instdir
mkdir $instdir
mount $root $instdir
apk --root $instdir --arch aarch64 --allow-untrusted --initdb \
-X http://dl-cdn.alpinelinux.org/alpine/v3.12/main \
-X http://dl-cdn.alpinelinux.org/alpine/v3.12/community \
-X http://dl-cdn.alpinelinux.org/alpine/edge/testing \
add alpine-base alpine-baselayout alpine-conf kmod openrc \
linux-elm linux-firmware-mediatek linux-firmware-atmel linux-firmware-mrvl \
sysfsutils ssl_client ca-certificates-bundle alpine-mirrors alpine-keys \
iwd dbus cgpt
sync
echo "writing kernel to kernel partition"
dd if=/boot/vmlinux.kpart of=${kernel}
ln -s /etc/init.d/bootmisc $instdir/etc/runlevels/boot/
ln -s /etc/init.d/hostname $instdir/etc/runlevels/boot
ln -s /etc/init.d/modules $instdir/etc/runlevels/boot
ln -s /etc/init.d/sysctl $instdir/etc/runlevels/boot
ln -s /etc/init.d/urandom $instdir/etc/runlevels/boot
ln -s /etc/init.d/devfs $instdir/etc/runlevels/sysinit
ln -s /etc/init.d/hwdrivers $instdir/etc/runlevels/sysinit
ln -s /etc/init.d/mdev $instdir/etc/runlevels/sysinit
ln -s /etc/init.d/modules $instdir/etc/runlevels/sysinit
ln -s /etc/init.d/mount-ro $instdir/etc/runlevels/shutdown
ln -s /etc/init.d/killprocs $instdir/etc/runlevels/shutdown
ln -s /etc/init.d/iwd $instdir/etc/runlevels/default
sync
umount $instdir
rmdir $instdir
echo
echo "install completed."
exit 0