imgname=sqmeta
target=alpine
format="custom"
# Sections
# Core system
# Provisioning
# Anemos
# Other
packages="
alpine-base
linux-virt
syslinux
e2fsprogs
lsblk
zstd
curl
openssh
qemu-guest-agent
ufw
"
services="
networking:boot
sshd
qemu-guest-agent
ufw
"
passwords="
root:+pw_root_enc
"
setup() {
# Repartition
parted -s -- /dev/vda mklabel msdos \
mkpart primary 2048s 256MiB \
mkpart primary 256MiB -1s \
set 1 boot on
partprobe /dev/vda
# wait for hotplug events to settle...
sleep 1 && mdev -sf
uuidr=$(uuidgen)
uuidb=$(uuidgen)
mkfs.ext2 -q -F -U "$uuidb" /dev/vda1
mkfs.ext4 -q -F -U "$uuidr" /dev/vda2
mount /dev/vda2 "${imgroot}"
mkdir "${imgroot}/boot"
mount /dev/vda1 "${imgroot}/boot"
mkdir "${imgroot}/etc"
opts=$(findmnt -no OPTIONS /dev/vda2)
echo "UUID=$uuidr / ext4 $opts 0 1" > "${imgroot}/etc/fstab"
opts=$(findmnt -no OPTIONS /dev/vda1)
echo "UUID=$uuidb /boot ext2 $opts,noauto 0 2" >> "${imgroot}/etc/fstab"
# Persistent partition, see README
echo "UUID=1ad73c24-2a0b-42a7-83e9-12e2dc3d2ef1 /mnt/persistent ext4 rw,relatime 0 2" >> "${imgroot}/etc/fstab"
}
cleanup() {
umount "${imgroot}/boot"
umount "${imgroot}"
}
provision() {
case "$format" in
"custom")
# Bootloader
echo "Setting up bootloader"
uuid=$(lsblk -rno UUID /dev/vda2)
sed -e "s|^root=|root=/dev/disk/by-uuid/${uuid}|" -i /etc/update-extlinux.conf
dd bs=440 count=1 conv=notrunc if=/usr/share/syslinux/mbr.bin of="${BLKDEV}"
extlinux --install /boot
update-extlinux -v
;;
*)
echo "Not setting up bootloader"
;;
esac
# Create persistent mount directory
mkdir -p /mnt/persistent
ufw default deny incoming
ufw limit SSH
ufw enable
}