Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jirutka committed Sep 11, 2023
1 parent e3c5a3f commit 0105aeb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 12 deletions.
29 changes: 28 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
- push

jobs:
test:
test-x86_64:
runs-on: ubuntu-latest
steps:
- name: Install qemu-utils
Expand Down Expand Up @@ -51,3 +51,30 @@ jobs:
--fs-skel-chown root:root \
--script-chroot \
alpine-uefi-$(date +%Y-%m-%d).qcow2 -- ./example/configure.sh
test-aarch64:
runs-on: ubuntu-latest
steps:
- name: Install qemu-utils
run: |
sudo apt-get update
sudo apt-get install qemu-utils
- uses: actions/checkout@v3

- uses: jirutka/setup-alpine@v1
with:
arch: aarch64

- name: Build image with UEFI boot mode
run: |
sudo ./alpine-make-vm-image \
--image-format qcow2 \
--image-size 2G \
--arch aarch64 \
--repositories-file example/repositories \
--packages "$(cat example/packages)" \
--fs-skel-dir example/rootfs \
--fs-skel-chown root:root \
--script-chroot \
alpine-$(date +%Y-%m-%d).qcow2 -- ./example/configure.sh
45 changes: 34 additions & 11 deletions alpine-make-vm-image
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
# <script-opts> Arguments to pass to the script.
#
# Options and Environment Variables:
# -B --boot-mode BOOT_MODE Either "BIOS" (default) or "UEFI".
# -a --arch ARCH Target CPU architecture. If it doesn't match the host's
# architecture, you must register an interpreter (emulator)
# for the target architecture in binfmt, e.g. qemu userspace
# emulator. Options: x86_64, aarch64 (Alpine v3.18+).
#
# -B --boot-mode BOOT_MODE Either "BIOS" (default on x86/x86_64) or "UEFI" (default
# on others). "BIOS" is supported only on x86/x86_64.
#
# -b --branch ALPINE_BRANCH Alpine branch to install; used only when
# --repositories-file is not specified. Default is
Expand All @@ -40,7 +46,7 @@
# specified USER:GROUP.
#
# -P --partition (PARTITION) Create GUID Partition Table (GPT) with a single partition.
# GPT is always created for --boot-mode UEFI.
# GPT is always created if --boot-mode is UEFI.
#
# -f --image-format IMAGE_FORMAT Format of the disk image (see qemu-img --help).
#
Expand All @@ -56,8 +62,9 @@
# (Alpine >=3.11), or vanilla (Alpine <3.11).
#
# --keys-dir KEYS_DIR Path of directory with Alpine keys to copy into the image.
# Default is /etc/apk/keys. If does not exist, keys for
# x86_64 embedded in this script will be used.
# Default is /etc/apk/keys if --arch matches the host arch.
# If does not exist, keys for aarch64 and x86_64 embedded in
# this script will be used.
#
# -m --mirror-uri ALPINE_MIRROR URI of the Aports mirror to fetch packages; used only
# when --repositories-file is not specified. Default is
Expand Down Expand Up @@ -115,6 +122,8 @@ readonly ALPINE_KEYS='
alpine-devel@lists.alpinelinux.org-4a6a0840.rsa.pub:MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1yHJxQgsHQREclQu4Ohe\nqxTxd1tHcNnvnQTu/UrTky8wWvgXT+jpveroeWWnzmsYlDI93eLI2ORakxb3gA2O\nQ0Ry4ws8vhaxLQGC74uQR5+/yYrLuTKydFzuPaS1dK19qJPXB8GMdmFOijnXX4SA\njixuHLe1WW7kZVtjL7nufvpXkWBGjsfrvskdNA/5MfxAeBbqPgaq0QMEfxMAn6/R\nL5kNepi/Vr4S39Xvf2DzWkTLEK8pcnjNkt9/aafhWqFVW7m3HCAII6h/qlQNQKSo\nGuH34Q8GsFG30izUENV9avY7hSLq7nggsvknlNBZtFUcmGoQrtx3FmyYsIC8/R+B\nywIDAQAB
alpine-devel@lists.alpinelinux.org-5261cecb.rsa.pub:MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwlzMkl7b5PBdfMzGdCT0\ncGloRr5xGgVmsdq5EtJvFkFAiN8Ac9MCFy/vAFmS8/7ZaGOXoCDWbYVLTLOO2qtX\nyHRl+7fJVh2N6qrDDFPmdgCi8NaE+3rITWXGrrQ1spJ0B6HIzTDNEjRKnD4xyg4j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d5S47H7XTROHnalYDuF1RpS+DpQidT5tUimaT\nJZDr++FjKrnnijbyNF8b98UCAwEAAQ==
'

: ${APK_TOOLS_URI:="https://gitlab.alpinelinux.org/api/v4/projects/5/packages/generic/v2.12.10/x86_64/apk.static"}
Expand Down Expand Up @@ -376,14 +385,15 @@ wgets() (

#============================= M a i n ==============================#

opts=$(getopt -n $PROGNAME -o b:B:cCf:hi:k:m:p:Pr:s:S:tv \
-l boot-mode:,branch:,fs-skel-chown:,fs-skel-dir:,image-format:,image-size:,initfs-features:,kernel-flavor:,keys-dir:,mirror-uri:,no-cleanup,packages:,partition,repositories-file:,rootfs:,script-chroot,serial-console,help,version \
opts=$(getopt -n $PROGNAME -o a:b:B:cCf:hi:k:m:p:Pr:s:S:tv \
-l arch:,boot-mode:,branch:,fs-skel-chown:,fs-skel-dir:,image-format:,image-size:,initfs-features:,kernel-flavor:,keys-dir:,mirror-uri:,no-cleanup,packages:,partition,repositories-file:,rootfs:,script-chroot,serial-console,help,version \
-- "$@") || help 1 >&2

eval set -- "$opts"
while [ $# -gt 0 ]; do
n=2
case "$1" in
-a | --arch) ARCH="$2";;
-B | --boot-mode) BOOT_MODE="$2";;
-b | --branch) ALPINE_BRANCH="$2";;
-S | --fs-skel-dir) FS_SKEL_DIR="$(realpath "$2")";;
Expand All @@ -410,26 +420,36 @@ done

: ${ALPINE_BRANCH:="latest-stable"}
: ${ALPINE_MIRROR:="http://dl-cdn.alpinelinux.org/alpine"}
: ${BOOT_MODE:="BIOS"}
: ${ARCH:=}
: ${CLEANUP:="yes"}
: ${FS_SKEL_CHOWN:=}
: ${FS_SKEL_DIR:=}
: ${IMAGE_FORMAT:=}
: ${IMAGE_SIZE:="2G"}
: ${INITFS_FEATURES:="scsi virtio"}
: ${INITFS_FEATURES:="scsi virtio kms"}
: ${KERNEL_FLAVOR:="virt"}
: ${KEYS_DIR:="/etc/apk/keys"}
: ${PACKAGES:=}
: ${PARTITION:="no"}
: ${REPOS_FILE:=}
: ${ROOTFS:="ext4"}
: ${SCRIPT_CHROOT:="no"}
: ${SERIAL_CONSOLE:="no"}

if [ -z "$ARCH" ] || [ "$(uname -m)" = "$ARCH" ]; then
: ${KEYS_DIR:="/etc/apk/keys"}
else
: ${KEYS_DIR:=}
fi

case "$ALPINE_BRANCH" in
[0-9]*) ALPINE_BRANCH="v$ALPINE_BRANCH";;
esac

case "${ARCH:-"$(uname -m)"}" in
x86*) : ${BOOT_MODE:="BIOS"};;
*) : ${BOOT_MODE:="UEFI"}
[ "$BOOT_MODE" = 'BIOS' ] && die 'BIOS boot mode is supported only on x86/x86_64';;
esac
case "$BOOT_MODE" in
BIOS | UEFI) ;;
*) die "Invalid boot-mode: $BOOT_MODE";;
Expand Down Expand Up @@ -559,7 +579,7 @@ if [ -L /etc/apk/cache ]; then
ln -s "$(realpath /etc/apk/cache)" etc/apk/cache
fi

_apk add --root . --update-cache --initdb alpine-base
_apk add --root . ${ARCH:+--arch "$ARCH"} --update-cache --initdb alpine-base

fsprogs_pkgs=
# btrfs doesn't use fsck, so we don't have to install btrfs-progs.
Expand Down Expand Up @@ -612,12 +632,15 @@ if [ "$BOOT_MODE" = 'UEFI' ]; then
>> etc/fstab

# This script is interpreted by UEFI.
# NOTE: When console=$SERIAL_PORT is added here, no messages are printed to
# console on QEMU after switch_root. 'console=tty0' must be explicitly set
# for aarch64 (it's the default on x86_64).
echo "vmlinuz-$KERNEL_FLAVOR" \
"initrd=initramfs-$KERNEL_FLAVOR" \
"root=UUID=$root_uuid" \
"rootfstype=$ROOTFS" \
"modules=$(echo $INITFS_FEATURES | tr ' ' ',')" \
${SERIAL_PORT:+"console=ttyS0"} \
'console=tty0' \
> boot/startup.nsh
fi

Expand Down

0 comments on commit 0105aeb

Please sign in to comment.