1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
imgname=sqmeta
target=alpine
format="custom"
# Sections
# Core system
# Provisioning
# Anemos
# Other
packages="
alpine-base
linux-virt
syslinux
e2fsprogs
lsblk
zstd
curl
openssh
"
services="
networking:boot
sshd
"
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)
printf "UUID=%s\t/\t%s\t%s\t0 1\n" "${uuidr}" "ext4" "${opts}" > "${imgroot}/etc/fstab"
opts=$(findmnt -no OPTIONS /dev/vda1)
printf "UUID=%s\t/boot\t%s\t%s\t0 2\n" "${uuidb}" "ext2" "${opts},noauto" >> "${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
}