From bbb181d582d1318f0caf4fcd206eafd8641611a7 Mon Sep 17 00:00:00 2001 From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:57:21 -0600 Subject: [PATCH 1/3] Alpine Linux support (WiP) --- builds.yml | 5 +- .../alpine/alpine-3.21-aarch64.pkrvars.hcl | 10 ++++ .../alpine/alpine-3.21-x86_64.pkrvars.hcl | 9 ++++ packer_templates/pkr-builder.pkr.hcl | 36 ++++++++++----- packer_templates/scripts/_common/vmware.sh | 6 ++- .../scripts/alpine/build-tools_alpine.sh | 5 ++ .../scripts/alpine/cleanup_apk.sh | 46 +++++++++++++++++++ .../install-supporting-packages_alpine.sh | 8 ++++ .../scripts/alpine/networking_alpine.sh | 20 ++++++++ .../scripts/alpine/real-tmp_alpine.sh | 10 ++++ packer_templates/scripts/alpine/update_apk.sh | 7 +++ 11 files changed, 148 insertions(+), 14 deletions(-) create mode 100644 os_pkrvars/alpine/alpine-3.21-aarch64.pkrvars.hcl create mode 100644 os_pkrvars/alpine/alpine-3.21-x86_64.pkrvars.hcl create mode 100644 packer_templates/scripts/alpine/build-tools_alpine.sh create mode 100644 packer_templates/scripts/alpine/cleanup_apk.sh create mode 100644 packer_templates/scripts/alpine/install-supporting-packages_alpine.sh create mode 100644 packer_templates/scripts/alpine/networking_alpine.sh create mode 100644 packer_templates/scripts/alpine/real-tmp_alpine.sh create mode 100644 packer_templates/scripts/alpine/update_apk.sh diff --git a/builds.yml b/builds.yml index 9baf1a2e2..d16e85dc6 100644 --- a/builds.yml +++ b/builds.yml @@ -1,5 +1,5 @@ --- -vagrant_cloud_account: 'bento' +vagrant_cloud_account: "bento" default_architectures: - x86_64 @@ -9,6 +9,7 @@ public: - amazonlinux-2023 - almalinux-8 - almalinux-9 + - alpine-3.21 - centos-stream-9 - centos-stream-10 - debian-11 @@ -29,6 +30,7 @@ public: slugs: - almalinux-8 - almalinux-9 + - alpine-3.21 - debian-12 - debian-11 - fedora-latest @@ -50,6 +52,7 @@ do_not_build: - rhel - windows # - almalinux +# - alpine-3.21 # - centos # - debian # - fedora diff --git a/os_pkrvars/alpine/alpine-3.21-aarch64.pkrvars.hcl b/os_pkrvars/alpine/alpine-3.21-aarch64.pkrvars.hcl new file mode 100644 index 000000000..6edb3358f --- /dev/null +++ b/os_pkrvars/alpine/alpine-3.21-aarch64.pkrvars.hcl @@ -0,0 +1,10 @@ +os_name = "alpine" +os_version = "3.21" +os_arch = "aarch64" +iso_url = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/aarch64/alpine-standard-3.21.3-aarch64.iso" +iso_checksum = "file:https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/aarch64/alpine-standard-3.21.3-aarch64.iso.sha256" +parallels_guest_os_type = "other" +vbox_guest_os_type = "other" +vmware_guest_os_type = "other" +parallels_boot_wait = "0s" +boot_command = ["e inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/fedora/ks.cfg inst.repo=https://download.fedoraproject.org/pub/fedora/linux/releases/41/Server/aarch64/os/ "] diff --git a/os_pkrvars/alpine/alpine-3.21-x86_64.pkrvars.hcl b/os_pkrvars/alpine/alpine-3.21-x86_64.pkrvars.hcl new file mode 100644 index 000000000..efd1b16bd --- /dev/null +++ b/os_pkrvars/alpine/alpine-3.21-x86_64.pkrvars.hcl @@ -0,0 +1,9 @@ +os_name = "alpine" +os_version = "3.21" +os_arch = "x86_64" +iso_url = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-standard-3.21.3-x86_64.iso" +iso_checksum = "file:https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-standard-3.21.3-x86_64.iso.sha256" +parallels_guest_os_type = "other" +vbox_guest_os_type = "other" +vmware_guest_os_type = "other" +boot_command = ["e inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/fedora/ks.cfg inst.repo=https://download.fedoraproject.org/pub/fedora/linux/releases/41/Server/x86_64/os/ "] diff --git a/packer_templates/pkr-builder.pkr.hcl b/packer_templates/pkr-builder.pkr.hcl index 41a627197..7f3b6c6e1 100644 --- a/packer_templates/pkr-builder.pkr.hcl +++ b/packer_templates/pkr-builder.pkr.hcl @@ -121,17 +121,31 @@ locals { "${path.root}/scripts/fedora/real-tmp_fedora.sh", "${path.root}/scripts/fedora/cleanup_dnf.sh", "${path.root}/scripts/_common/minimize.sh" - ] : [ - "${path.root}/scripts/rhel/update_dnf.sh", - "${path.root}/scripts/_common/motd.sh", - "${path.root}/scripts/_common/sshd.sh", - "${path.root}/scripts/_common/vagrant.sh", - "${path.root}/scripts/_common/virtualbox.sh", - "${path.root}/scripts/_common/vmware.sh", - "${path.root}/scripts/_common/parallels.sh", - "${path.root}/scripts/rhel/cleanup_dnf.sh", - "${path.root}/scripts/_common/minimize.sh" - ] + ] : var.os_name == "fedora" ? [ + "${path.root}/scripts/alpine/networking_alpine.sh", + "${path.root}/scripts/alpine/update_apk.sh", + "${path.root}/scripts/_common/motd.sh", + "${path.root}/scripts/_common/sshd.sh", + "${path.root}/scripts/alpine/install-supporting-packages_alpine.sh", + "${path.root}/scripts/alpine/build-tools_alpine.sh", + "${path.root}/scripts/_common/virtualbox.sh", + "${path.root}/scripts/_common/vmware.sh", + "${path.root}/scripts/_common/parallels.sh", + "${path.root}/scripts/_common/vagrant.sh", + "${path.root}/scripts/alpine/real-tmp_alpine.sh", + "${path.root}/scripts/alpine/cleanup_apk.sh", + "${path.root}/scripts/_common/minimize.sh" + ] : [ + "${path.root}/scripts/rhel/update_dnf.sh", + "${path.root}/scripts/_common/motd.sh", + "${path.root}/scripts/_common/sshd.sh", + "${path.root}/scripts/_common/vagrant.sh", + "${path.root}/scripts/_common/virtualbox.sh", + "${path.root}/scripts/_common/vmware.sh", + "${path.root}/scripts/_common/parallels.sh", + "${path.root}/scripts/rhel/cleanup_dnf.sh", + "${path.root}/scripts/_common/minimize.sh" + ] ) ) ) diff --git a/packer_templates/scripts/_common/vmware.sh b/packer_templates/scripts/_common/vmware.sh index b6a3c171e..c84d7fffc 100644 --- a/packer_templates/scripts/_common/vmware.sh +++ b/packer_templates/scripts/_common/vmware.sh @@ -1,4 +1,6 @@ -#!/bin/bash -eux +#!/bin/sh + +set -eux # set a default HOME_DIR environment variable if not set HOME_DIR="${HOME_DIR:-/home/vagrant}" @@ -12,7 +14,7 @@ vmware-iso|vmware-vmx) systemctl start vmtoolsd elif [ -f "/usr/bin/apt-get" ]; then # determine the major Debian version we're runninng - major_version="$(grep VERSION_ID /etc/os-release | awk -F= '{print $2}' | tr -d '"')" + major_version="$(. /etc/os-release | printf '%s' "${VERSION_ID}")" architecture="$(uname -m)" # open-vm-tools for amd64 are only available in bullseye-backports repo echo "install open-vm-tools" diff --git a/packer_templates/scripts/alpine/build-tools_alpine.sh b/packer_templates/scripts/alpine/build-tools_alpine.sh new file mode 100644 index 000000000..1a00d8f16 --- /dev/null +++ b/packer_templates/scripts/alpine/build-tools_alpine.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +set -eux + +apk add autoconf gcc libelf libtool linux-headers make musl-dev perl diff --git a/packer_templates/scripts/alpine/cleanup_apk.sh b/packer_templates/scripts/alpine/cleanup_apk.sh new file mode 100644 index 000000000..c7fa101ac --- /dev/null +++ b/packer_templates/scripts/alpine/cleanup_apk.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +set -eux + +echo "reduce the grub menu time to 1 second" +sed -i -e 's/^GRUB_TIMEOUT=[0-9]\+$/GRUB_TIMEOUT=1/' /etc/default/grub +grub2-mkconfig -o /boot/grub2/grub.cfg + +echo "Remove development and kernel source packages" +apk del linux-headers libelf gcc make perl + +echo "Remove older versions of packages the from cache directory" +apk cache clean + +echo "clean whole package cache" +rm -rf /var/cache/apk/* + +echo "truncate any logs that have built up during the install" +find /var/log -type f -exec truncate --size=0 {} \; + +echo "Remove any non-loopback network configs" +if test -d /etc/sysconfig/network-scripts +then + find /etc/sysconfig/network-scripts -name "ifcfg-*" -not -name "ifcfg-lo" -exec rm -f {} \; +fi + +echo "remove the install log" +rm -f /root/anaconda-ks.cfg /root/original-ks.cfg + +echo "remove the contents of /tmp and /var/tmp" +rm -rf /tmp/* /var/tmp/* + +echo "Force a new random seed to be generated" +# https://wiki.alpinelinux.org/wiki/Entropy_and_randomness +dd if=/dev/zero of=/var/tmp/tempfile bs=1M count=200 && find / -size +1k && ls -R / && rm /var/tmp/tempfile && sync + +echo "Wipe netplan machine-id (DUID) so machines get unique ID generated on boot" +truncate -s 0 /etc/machine-id +if test -f /var/lib/dbus/machine-id +then + truncate -s 0 /var/lib/dbus/machine-id # if not symlinked to "/etc/machine-id" +fi + +echo "Clear the history so our install commands aren't there" +rm -f /root/.wget-hsts +export HISTSIZE=0 diff --git a/packer_templates/scripts/alpine/install-supporting-packages_alpine.sh b/packer_templates/scripts/alpine/install-supporting-packages_alpine.sh new file mode 100644 index 000000000..fe2999d3e --- /dev/null +++ b/packer_templates/scripts/alpine/install-supporting-packages_alpine.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +set -eux + +# Chef with Fedora >= 30 requires libxcrypt-compat to be installed +# dnf -y install libxcrypt-compat +# https://gitlab.alpinelinux.org/alpine/aports/-/issues/13251 +# not yet^ diff --git a/packer_templates/scripts/alpine/networking_alpine.sh b/packer_templates/scripts/alpine/networking_alpine.sh new file mode 100644 index 000000000..917ed96b2 --- /dev/null +++ b/packer_templates/scripts/alpine/networking_alpine.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +set -eux + +case "$PACKER_BUILDER_TYPE" in + 'virtualbox'*) + ## https://access.redhat.com/site/solutions/58625 (subscription required) + # add 'single-request-reopen' so it is included when /etc/resolv.conf is generated + cat >> /etc/NetworkManager/dispatcher.d/fix-slow-dns <> /etc/resolv.conf + EOF + chmod +x /etc/NetworkManager/dispatcher.d/fix-slow-dns + systemctl restart NetworkManager.service + echo 'Slow DNS fix applied (single-request-reopen)' + ;; + *) + echo 'Slow DNS fix not required for this platform, skipping' + ;; +esac diff --git a/packer_templates/scripts/alpine/real-tmp_alpine.sh b/packer_templates/scripts/alpine/real-tmp_alpine.sh new file mode 100644 index 000000000..083eb5d4f --- /dev/null +++ b/packer_templates/scripts/alpine/real-tmp_alpine.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +set -eux + +#echo "Don't use the tmpfs based /tmp dir that is limited to 50% of RAM" +#systemctl mask tmp.mount + + +# One can modify their /etc/fstab with, e.g.: +# /tmp /tmp tmpfs defaults,size=8G 0 0 diff --git a/packer_templates/scripts/alpine/update_apk.sh b/packer_templates/scripts/alpine/update_apk.sh new file mode 100644 index 000000000..56503a1a5 --- /dev/null +++ b/packer_templates/scripts/alpine/update_apk.sh @@ -0,0 +1,7 @@ +#!/bin/sh -eux + +# update all packages +apk upgrade --available + +reboot; +sleep 60; From da04a6a94e3df3f4732c40377a17eaad90e002fa Mon Sep 17 00:00:00 2001 From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com> Date: Tue, 1 Apr 2025 14:10:35 -0600 Subject: [PATCH 2/3] Further progress on Alpine Linux support --- .github/workflows/pkr-bld-hyperv-x64.yml | 1 + .github/workflows/pkr-bld-parallels-arm64.yml | 11 +- .github/workflows/pkr-bld-parallels-x64.yml | 9 +- .github/workflows/pkr-bld-qemu-arm64.yml | 1 + .github/workflows/pkr-bld-qemu-x64.yml | 1 + .../workflows/pkr-bld-virtualbox-arm64.yml | 1 + .github/workflows/pkr-bld-virtualbox-x64.yml | 1 + .github/workflows/pkr-bld-vmware-arm64.yml | 1 + .github/workflows/pkr-bld-vmware-x64.yml | 1 + .github/workflows/test-pkr-bld-parallels.yml | 1 + CHANGELOG.md | 1 + alpine-3.21-aarch64-virtualbox-build.sh | 111 ++++++++++++++++++ .../alpine/alpine-3.21-aarch64.pkrvars.hcl | 6 +- .../alpine/alpine-3.21-x86_64.pkrvars.hcl | 6 +- .../alpine/alpine-3_21-aarch64.pkrvars.hcl | 21 ++++ packer_templates/http/alpine/ks.cfg | 46 ++++++++ packer_templates/pkr-builder.pkr.hcl | 2 +- .../scripts/_common/virtualbox.sh | 2 + 18 files changed, 207 insertions(+), 16 deletions(-) create mode 100755 alpine-3.21-aarch64-virtualbox-build.sh create mode 100644 os_pkrvars/alpine/alpine-3_21-aarch64.pkrvars.hcl create mode 100644 packer_templates/http/alpine/ks.cfg diff --git a/.github/workflows/pkr-bld-hyperv-x64.yml b/.github/workflows/pkr-bld-hyperv-x64.yml index 94287ae0a..4924df47b 100644 --- a/.github/workflows/pkr-bld-hyperv-x64.yml +++ b/.github/workflows/pkr-bld-hyperv-x64.yml @@ -15,6 +15,7 @@ jobs: os: - almalinux-8 - almalinux-9 + - alpine-3.21 - centos-stream-9 - centos-stream-10 - debian-11 diff --git a/.github/workflows/pkr-bld-parallels-arm64.yml b/.github/workflows/pkr-bld-parallels-arm64.yml index ce9696518..8b39143df 100644 --- a/.github/workflows/pkr-bld-parallels-arm64.yml +++ b/.github/workflows/pkr-bld-parallels-arm64.yml @@ -15,6 +15,7 @@ jobs: os: - almalinux-8 - almalinux-9 + - alpine-3.21 - centos-stream-9 - centos-stream-10 - debian-11 @@ -35,11 +36,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@main -# - name: Setup Packer -# if: steps.verify-changed-files.outputs.files_changed == 'true' -# uses: hashicorp/setup-packer@main -# with: -# version: latest + # - name: Setup Packer + # if: steps.verify-changed-files.outputs.files_changed == 'true' + # uses: hashicorp/setup-packer@main + # with: + # version: latest - name: Bento build run: | eval "$(chef shell-init bash)" diff --git a/.github/workflows/pkr-bld-parallels-x64.yml b/.github/workflows/pkr-bld-parallels-x64.yml index 96b83055b..a707d4bd8 100644 --- a/.github/workflows/pkr-bld-parallels-x64.yml +++ b/.github/workflows/pkr-bld-parallels-x64.yml @@ -15,6 +15,7 @@ jobs: os: - almalinux-8 - almalinux-9 + - alpine-3.21 - centos-stream-9 - centos-stream-10 - debian-11 @@ -35,10 +36,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@main -# - name: Setup Packer -# uses: hashicorp/setup-packer@main -# with: -# version: latest + # - name: Setup Packer + # uses: hashicorp/setup-packer@main + # with: + # version: latest - name: Bento build run: | eval "$(chef shell-init bash)" diff --git a/.github/workflows/pkr-bld-qemu-arm64.yml b/.github/workflows/pkr-bld-qemu-arm64.yml index 0c39e0367..7591cf53e 100644 --- a/.github/workflows/pkr-bld-qemu-arm64.yml +++ b/.github/workflows/pkr-bld-qemu-arm64.yml @@ -15,6 +15,7 @@ jobs: os: - almalinux-8 - almalinux-9 + - alpine-3.21 - centos-stream-9 - centos-stream-10 - debian-11 diff --git a/.github/workflows/pkr-bld-qemu-x64.yml b/.github/workflows/pkr-bld-qemu-x64.yml index 8c6062e86..8d892d7c3 100644 --- a/.github/workflows/pkr-bld-qemu-x64.yml +++ b/.github/workflows/pkr-bld-qemu-x64.yml @@ -15,6 +15,7 @@ jobs: os: - almalinux-8 - almalinux-9 + - alpine-3.21 - centos-stream-9 - centos-stream-10 - debian-11 diff --git a/.github/workflows/pkr-bld-virtualbox-arm64.yml b/.github/workflows/pkr-bld-virtualbox-arm64.yml index 14b4bdcb5..28c4767bf 100644 --- a/.github/workflows/pkr-bld-virtualbox-arm64.yml +++ b/.github/workflows/pkr-bld-virtualbox-arm64.yml @@ -15,6 +15,7 @@ jobs: os: - almalinux-8 - almalinux-9 + - alpine-3.21 - centos-stream-9 - centos-stream-10 - debian-11 diff --git a/.github/workflows/pkr-bld-virtualbox-x64.yml b/.github/workflows/pkr-bld-virtualbox-x64.yml index fd962b1b8..71b15a2dd 100644 --- a/.github/workflows/pkr-bld-virtualbox-x64.yml +++ b/.github/workflows/pkr-bld-virtualbox-x64.yml @@ -15,6 +15,7 @@ jobs: os: - almalinux-8 - almalinux-9 + - alpine-3.21 - centos-stream-9 - centos-stream-10 - debian-11 diff --git a/.github/workflows/pkr-bld-vmware-arm64.yml b/.github/workflows/pkr-bld-vmware-arm64.yml index 12ca0c7fc..b51b78f10 100644 --- a/.github/workflows/pkr-bld-vmware-arm64.yml +++ b/.github/workflows/pkr-bld-vmware-arm64.yml @@ -15,6 +15,7 @@ jobs: os: - almalinux-8 - almalinux-9 + - alpine-3.21 - centos-stream-9 - centos-stream-10 - debian-11 diff --git a/.github/workflows/pkr-bld-vmware-x64.yml b/.github/workflows/pkr-bld-vmware-x64.yml index 6c8cd1c46..808657c11 100644 --- a/.github/workflows/pkr-bld-vmware-x64.yml +++ b/.github/workflows/pkr-bld-vmware-x64.yml @@ -15,6 +15,7 @@ jobs: os: - almalinux-8 - almalinux-9 + - alpine-3.21 - centos-stream-9 - centos-stream-10 - debian-11 diff --git a/.github/workflows/test-pkr-bld-parallels.yml b/.github/workflows/test-pkr-bld-parallels.yml index 5fc3d17b0..396aa087c 100644 --- a/.github/workflows/test-pkr-bld-parallels.yml +++ b/.github/workflows/test-pkr-bld-parallels.yml @@ -14,6 +14,7 @@ jobs: os: - almalinux-8 - almalinux-9 + - alpine-3.21 - centos-stream-9 - debian-11 - debian-12 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9348c0fd5..2207f2905 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Markdown table generated at |:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:| | almalinux-8 | | x | na | x | na | x | na | x | na | | almalinux-9 | | x | x | x | | x | x | x | x | +| alpine-3.21 | TBD | TBD | TBD | TBD | TBD | TBD | TBD | TDB | TDB | | amazonlinux-2023 | | | | | | x | | | | | centos-stream-9 | | x | x | x | | x | x | x | x | | centos-stream-10 | | x | x | x | | x | x | x | x | diff --git a/alpine-3.21-aarch64-virtualbox-build.sh b/alpine-3.21-aarch64-virtualbox-build.sh new file mode 100755 index 000000000..25d3bd62d --- /dev/null +++ b/alpine-3.21-aarch64-virtualbox-build.sh @@ -0,0 +1,111 @@ +#!/bin/sh + +if [ ! -z "${BASH_VERSION+x}" ]; then + this_file="${BASH_SOURCE[0]}" + set -o pipefail +elif [ ! -z "${ZSH_VERSION+x}" ]; then + this_file="${(%):-%x}" + set -o pipefail +else + this_file="${0}" +fi +set -feu + +export ARCH="${ARCH:-aarch64}" +export VERSION="${VERSION:-3.21.3}" +export VERSION_MAJOR_MINOR="${VERSION%.*}" + +# Getting script directory location +SCRIPT_RELATIVE_DIR=$(dirname -- "${this_file}") +cd -- "$SCRIPT_RELATIVE_DIR" || exit + +# set tmp dir for files +ALPDIR="$(pwd)/builds/build_files/alpine-${VERSION}-${ARCH}-virtualbox" +mkdir -p "$ALPDIR" + +echo "Cleaning up old files" +set +f +rm -f -- "$ALPDIR"/*.iso "$ALPDIR"/*.ovf "$ALPDIR"/*.vmdk "$ALPDIR"/*.vdi + +# Get virtualbox vdi file name with latest version number + +qemu-img create -f qcow2 -- "$ALPDIR"'/alpine.qcow2' 8G + +export IMG='alpine-standard-'"${VERSION}"'-aarch64.iso' +if [ ! -f "$ALPDIR"'/'"${IMG}" ]; then + echo "Downloading $IMG" + wget -q -O "$ALPDIR"'/'"${IMG}" -c 'https://dl-cdn.alpinelinux.org/alpine/v'"${VERSION_MAJOR_MINOR}"'/releases/aarch64/alpine-standard-'"${VERSION}"'-aarch64.iso' +fi + +if [ ! -f "$ALPDIR"'/alpine_arm64.vdi' ]; then + qemu-system-x86_64 -m 512 -nic user -boot d -cdrom "$ALPDIR"'/'"${IMG}" -hda "$ALPDIR"'/alpine.qcow2' -display none # -enable-kvm + echo "Convert qcow2 to vdi" + qemu-img convert -f qcow2 "$ALPDIR"'/alpine.qcow2' -O vdi "$ALPDIR"'/alpine_arm64.vdi' +fi + +echo "Creating ISO" +SEED_ISO_DIR="$(pwd)/packer_templates/http/alpine" +if [ -x "$(command -v genisoimage)" ]; then + genisoimage -output "$ALPDIR"/seed.iso -volid cidata -joliet -rock "$SEED_ISO_DIR"/user-data -- "$SEED_ISO_DIR"/meta-data +elif [ -x "$(command -v hdiutil)" ]; then + hdiutil makehybrid -o "$ALPDIR"/seed.iso -hfs -joliet -iso -default-volume-name cidata -- "$SEED_ISO_DIR"/ +elif [ -x "$(command -v mkisofs)" ]; then + mkfsiso9660 -o "$ALPDIR"/seed.iso -- "$SEED_ISO_DIR"/ +else + echo "No tool found to create the seed.iso" + exit 1 +fi + +VM="AlpineLinuxBento" +echo Powering off and deleting any existing VMs named $VM +VBoxManage controlvm "$VM" poweroff --type headless 2>/dev/null +VBoxManage unregistervm "$VM" --delete 2>/dev/null +sleep 5 + +echo "Creating the VM" +# from https://www.perkin.org.uk/posts/create-virtualbox-vm-from-the-command-line.html +VBoxManage createvm --name "$VM" --ostype "ArchLinux_arm64" --register +VBoxManage storagectl "$VM" --name "VirtioSCSI" --add virtio-scsi --controller VirtIO +VBoxManage storageattach "$VM" --storagectl "VirtioSCSI" --port 0 --type hdd --medium "$ALPDIR"/alpine_arm64.vdi +VBoxManage storageattach "$VM" --storagectl "VirtioSCSI" --port 1 --type dvddrive --medium "$ALPDIR"/seed.iso +VBoxManage modifyvm "$VM" --chipset armv8virtual +VBoxManage modifyvm "$VM" --firmware efi +VBoxManage modifyvm "$VM" --memory 4096 +VBoxManage modifyvm "$VM" --cpus 2 +VBoxManage modifyvm "$VM" --nat-localhostreachable1 on +VBoxManage modifyvm "$VM" --vram 33 +VBoxManage modifyvm "$VM" --graphicscontroller vmsvga +VBoxManage modifyvm "$VM" --vrde on +VBoxManage modifyvm "$VM" --audio-enabled off +VBoxManage modifyvm "$VM" --ioapic on +VBoxManage modifyvm "$VM" --usb-xhci on +VBoxManage modifyvm "$VM" --mouse usb +VBoxManage modifyvm "$VM" --keyboard usb +VBoxManage modifyvm "$VM" --boot1 disk +VBoxManage modifyvm "$VM" --boot2 dvd +sleep 5 + +echo "Starting $VM then sleeping for 120 seconds to let the system boot and cloud-init to run" +VBoxManage startvm "$VM" --type headless +sleep 120 +VBoxManage guestcontrol "$VM" run --exe /bin/sh -- 'apk add virtualbox-guest-additions && + rc-service virtualbox-guest-additions start && + rc-update add virtualbox-guest-additions boot' +VBoxManage controlvm "$VM" poweroff +VBoxManage storageattach "$VM" --storagectl "VirtioSCSI" --port 1 --type dvddrive --medium none +sleep 5 + +echo "Exporting the VM to an OVF file" +vboxmanage export "$VM" -o "$ALPDIR"/alpine_arm64.ovf +sleep 5 + +echo "Deleting the VM" +vboxmanage unregistervm "$VM" --delete + +echo "starting packer build of alpine ${VERSION} for ${ARCH}" +if bento build --vars 'ssh_timeout=60m' --vars vbox_source_path="$ALPDIR"/alpine_arm64.ovf,vbox_checksum=null "$(pwd)"/os_pkrvars/alpine/alpine-3.21-aarch64.pkrvars.hcl; then + echo "Cleaning up files" + rm -rf -- "$ALPDIR" +else + exit 1 +fi diff --git a/os_pkrvars/alpine/alpine-3.21-aarch64.pkrvars.hcl b/os_pkrvars/alpine/alpine-3.21-aarch64.pkrvars.hcl index 6edb3358f..dd479c42f 100644 --- a/os_pkrvars/alpine/alpine-3.21-aarch64.pkrvars.hcl +++ b/os_pkrvars/alpine/alpine-3.21-aarch64.pkrvars.hcl @@ -3,8 +3,8 @@ os_version = "3.21" os_arch = "aarch64" iso_url = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/aarch64/alpine-standard-3.21.3-aarch64.iso" iso_checksum = "file:https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/aarch64/alpine-standard-3.21.3-aarch64.iso.sha256" -parallels_guest_os_type = "other" -vbox_guest_os_type = "other" -vmware_guest_os_type = "other" +parallels_guest_os_type = "otherlinux" +vbox_guest_os_type = "ArchLinux_arm64" +vmware_guest_os_type = "otherlinux" parallels_boot_wait = "0s" boot_command = ["e inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/fedora/ks.cfg inst.repo=https://download.fedoraproject.org/pub/fedora/linux/releases/41/Server/aarch64/os/ "] diff --git a/os_pkrvars/alpine/alpine-3.21-x86_64.pkrvars.hcl b/os_pkrvars/alpine/alpine-3.21-x86_64.pkrvars.hcl index efd1b16bd..18a3b1556 100644 --- a/os_pkrvars/alpine/alpine-3.21-x86_64.pkrvars.hcl +++ b/os_pkrvars/alpine/alpine-3.21-x86_64.pkrvars.hcl @@ -3,7 +3,7 @@ os_version = "3.21" os_arch = "x86_64" iso_url = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-standard-3.21.3-x86_64.iso" iso_checksum = "file:https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-standard-3.21.3-x86_64.iso.sha256" -parallels_guest_os_type = "other" -vbox_guest_os_type = "other" -vmware_guest_os_type = "other" +parallels_guest_os_type = "otherlinux" +vbox_guest_os_type = "ArchLinux_64" +vmware_guest_os_type = "otherlinux-64" boot_command = ["e inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/fedora/ks.cfg inst.repo=https://download.fedoraproject.org/pub/fedora/linux/releases/41/Server/x86_64/os/ "] diff --git a/os_pkrvars/alpine/alpine-3_21-aarch64.pkrvars.hcl b/os_pkrvars/alpine/alpine-3_21-aarch64.pkrvars.hcl new file mode 100644 index 000000000..f1e3ff39b --- /dev/null +++ b/os_pkrvars/alpine/alpine-3_21-aarch64.pkrvars.hcl @@ -0,0 +1,21 @@ +os_name = "alpine" +os_version = "3_21" +os_arch = "aarch64" +iso_url = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/aarch64/alpine-standard-3.21.3-aarch64.iso" +iso_checksum = "file:https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/aarch64/alpine-standard-3.21.3-aarch64.iso.sha256" +parallels_guest_os_type = "otherlinux" +vbox_guest_os_type = "ArchLinux_arm64" +vmware_guest_os_type = "otherlinux" +parallels_boot_wait = "0s" +boot_command = ["root", + "ifconfig eth0 up && udhcpc -i eth0", + "wget http://{{ .HTTPIP }}:{{ .HTTPPort }}/answers", + "setup-alpine -f answers", + "{{user `ssh_password`}}", + "{{user `ssh_password`}}", + "y", + "rc-service sshd stop", + "mount /dev/sda3 /mnt", + "echo 'PermitRootLogin yes' >> /mnt/etc/ssh/sshd_config", + "umount /mnt", + "reboot"] diff --git a/packer_templates/http/alpine/ks.cfg b/packer_templates/http/alpine/ks.cfg new file mode 100644 index 000000000..b8c66af4e --- /dev/null +++ b/packer_templates/http/alpine/ks.cfg @@ -0,0 +1,46 @@ +lang en_US.UTF-8 +keyboard --xlayouts='us' +network --bootproto=dhcp --noipv6 --onboot=on --device=eth0 +rootpw --plaintext vagrant +firewall --disabled +selinux --permissive +timezone UTC +bootloader --timeout=1 --location=mbr --append="net.ifnames=0 biosdevname=0" +text +skipx +zerombr +clearpart --all --initlabel +autopart --nohome --nolvm --noboot +firstboot --disabled +reboot --eject +user --name=vagrant --plaintext --password vagrant + +%packages +bzip2 +tar +wget +nfs-utils +net-tools +rsync +akms +%end + +%post +# sudo +echo 'Defaults:vagrant !requiretty' > /etc/sudoers.d/vagrant +echo '%vagrant ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/vagrant +chmod 440 /etc/sudoers.d/vagrant + +# Enable hyper-v daemons only if using hyper-v virtualization +if [ $(virt-what) == "hyperv" ]; then +apk add hvtools + +rc-service hv_fcopy_daemon start +rc-service hv_kvp_daemon start +rc-service hv_vss_daemon start + +rc-update add hv_fcopy_daemon +rc-update add hv_kvp_daemon +rc-update add hv_vss_daemon +fi +%end diff --git a/packer_templates/pkr-builder.pkr.hcl b/packer_templates/pkr-builder.pkr.hcl index 7f3b6c6e1..ff708570a 100644 --- a/packer_templates/pkr-builder.pkr.hcl +++ b/packer_templates/pkr-builder.pkr.hcl @@ -121,7 +121,7 @@ locals { "${path.root}/scripts/fedora/real-tmp_fedora.sh", "${path.root}/scripts/fedora/cleanup_dnf.sh", "${path.root}/scripts/_common/minimize.sh" - ] : var.os_name == "fedora" ? [ + ] : var.os_name == "alpine" ? [ "${path.root}/scripts/alpine/networking_alpine.sh", "${path.root}/scripts/alpine/update_apk.sh", "${path.root}/scripts/_common/motd.sh", diff --git a/packer_templates/scripts/_common/virtualbox.sh b/packer_templates/scripts/_common/virtualbox.sh index 8b0447d46..9e5edd7db 100644 --- a/packer_templates/scripts/_common/virtualbox.sh +++ b/packer_templates/scripts/_common/virtualbox.sh @@ -22,6 +22,8 @@ virtualbox-iso|virtualbox-ovf) apt-get install -y build-essential dkms bzip2 tar linux-headers-"$(uname -r)" elif [ -f "/usr/bin/zypper" ]; then zypper install -y perl cpp gcc make bzip2 tar kernel-default-devel + elif [ -f "/sbin/apk" ]; then + apk add perl musl-dev gcc make bzip2 tar linux-headers fi echo "installing the vbox additions for architecture $ARCHITECTURE" From 3f0d2c6a3eef62e5fba6046dfe434eba2ddc5d07 Mon Sep 17 00:00:00 2001 From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com> Date: Sun, 6 Apr 2025 22:32:11 -0600 Subject: [PATCH 3/3] [alpine-3.21-aarch64-virtualbox-build.sh] WiP creating builds for different virtual machines based on official alpine --- alpine-3.21-aarch64-virtualbox-build.sh | 82 ++++--------------------- 1 file changed, 13 insertions(+), 69 deletions(-) diff --git a/alpine-3.21-aarch64-virtualbox-build.sh b/alpine-3.21-aarch64-virtualbox-build.sh index 25d3bd62d..68b8e337c 100755 --- a/alpine-3.21-aarch64-virtualbox-build.sh +++ b/alpine-3.21-aarch64-virtualbox-build.sh @@ -12,7 +12,7 @@ fi set -feu export ARCH="${ARCH:-aarch64}" -export VERSION="${VERSION:-3.21.3}" +export VERSION="${VERSION:-3.21.2}" export VERSION_MAJOR_MINOR="${VERSION%.*}" # Getting script directory location @@ -21,86 +21,30 @@ cd -- "$SCRIPT_RELATIVE_DIR" || exit # set tmp dir for files ALPDIR="$(pwd)/builds/build_files/alpine-${VERSION}-${ARCH}-virtualbox" -mkdir -p "$ALPDIR" +[ -d "$ALPDIR" ] || mkdir -p -- "$ALPDIR" echo "Cleaning up old files" set +f rm -f -- "$ALPDIR"/*.iso "$ALPDIR"/*.ovf "$ALPDIR"/*.vmdk "$ALPDIR"/*.vdi -# Get virtualbox vdi file name with latest version number +NAME='generic_alpine-'"${VERSION}"'-'"${ARCH}"'-uefi-tiny-r0' +export QCOW="${NAME}"'.qcow2' +export VMDK="${NAME}"'.vmdk' +export VDI="${NAME}"'.vdi' -qemu-img create -f qcow2 -- "$ALPDIR"'/alpine.qcow2' 8G - -export IMG='alpine-standard-'"${VERSION}"'-aarch64.iso' -if [ ! -f "$ALPDIR"'/'"${IMG}" ]; then - echo "Downloading $IMG" - wget -q -O "$ALPDIR"'/'"${IMG}" -c 'https://dl-cdn.alpinelinux.org/alpine/v'"${VERSION_MAJOR_MINOR}"'/releases/aarch64/alpine-standard-'"${VERSION}"'-aarch64.iso' +if [ ! -f "$ALPDIR"'/'"${QCOW}" ]; then + wget -q -O -- "$ALPDIR"'/'"${QCOW}" 'https://dl-cdn.alpinelinux.org/alpine/v'"${VERSION_MAJOR_MINOR}"'/releases/cloud/'"${QCOW}" fi -if [ ! -f "$ALPDIR"'/alpine_arm64.vdi' ]; then - qemu-system-x86_64 -m 512 -nic user -boot d -cdrom "$ALPDIR"'/'"${IMG}" -hda "$ALPDIR"'/alpine.qcow2' -display none # -enable-kvm - echo "Convert qcow2 to vdi" - qemu-img convert -f qcow2 "$ALPDIR"'/alpine.qcow2' -O vdi "$ALPDIR"'/alpine_arm64.vdi' +if [ ! -f "${VMDK}" ]; then + qemu-img convert -f qcow2 -O vmdk -- "$ALPDIR"'/'"${QCOW}" "$ALPDIR"'/'"${VMDK}" # & fi -echo "Creating ISO" -SEED_ISO_DIR="$(pwd)/packer_templates/http/alpine" -if [ -x "$(command -v genisoimage)" ]; then - genisoimage -output "$ALPDIR"/seed.iso -volid cidata -joliet -rock "$SEED_ISO_DIR"/user-data -- "$SEED_ISO_DIR"/meta-data -elif [ -x "$(command -v hdiutil)" ]; then - hdiutil makehybrid -o "$ALPDIR"/seed.iso -hfs -joliet -iso -default-volume-name cidata -- "$SEED_ISO_DIR"/ -elif [ -x "$(command -v mkisofs)" ]; then - mkfsiso9660 -o "$ALPDIR"/seed.iso -- "$SEED_ISO_DIR"/ -else - echo "No tool found to create the seed.iso" - exit 1 +if [ ! -f "${VMDK}" ]; then + qemu-img convert -f qcow2 -O vdi -- "$ALPDIR"'/'"${QCOW}" "$ALPDIR"'/'"${VDI}" # & fi -VM="AlpineLinuxBento" -echo Powering off and deleting any existing VMs named $VM -VBoxManage controlvm "$VM" poweroff --type headless 2>/dev/null -VBoxManage unregistervm "$VM" --delete 2>/dev/null -sleep 5 - -echo "Creating the VM" -# from https://www.perkin.org.uk/posts/create-virtualbox-vm-from-the-command-line.html -VBoxManage createvm --name "$VM" --ostype "ArchLinux_arm64" --register -VBoxManage storagectl "$VM" --name "VirtioSCSI" --add virtio-scsi --controller VirtIO -VBoxManage storageattach "$VM" --storagectl "VirtioSCSI" --port 0 --type hdd --medium "$ALPDIR"/alpine_arm64.vdi -VBoxManage storageattach "$VM" --storagectl "VirtioSCSI" --port 1 --type dvddrive --medium "$ALPDIR"/seed.iso -VBoxManage modifyvm "$VM" --chipset armv8virtual -VBoxManage modifyvm "$VM" --firmware efi -VBoxManage modifyvm "$VM" --memory 4096 -VBoxManage modifyvm "$VM" --cpus 2 -VBoxManage modifyvm "$VM" --nat-localhostreachable1 on -VBoxManage modifyvm "$VM" --vram 33 -VBoxManage modifyvm "$VM" --graphicscontroller vmsvga -VBoxManage modifyvm "$VM" --vrde on -VBoxManage modifyvm "$VM" --audio-enabled off -VBoxManage modifyvm "$VM" --ioapic on -VBoxManage modifyvm "$VM" --usb-xhci on -VBoxManage modifyvm "$VM" --mouse usb -VBoxManage modifyvm "$VM" --keyboard usb -VBoxManage modifyvm "$VM" --boot1 disk -VBoxManage modifyvm "$VM" --boot2 dvd -sleep 5 - -echo "Starting $VM then sleeping for 120 seconds to let the system boot and cloud-init to run" -VBoxManage startvm "$VM" --type headless -sleep 120 -VBoxManage guestcontrol "$VM" run --exe /bin/sh -- 'apk add virtualbox-guest-additions && - rc-service virtualbox-guest-additions start && - rc-update add virtualbox-guest-additions boot' -VBoxManage controlvm "$VM" poweroff -VBoxManage storageattach "$VM" --storagectl "VirtioSCSI" --port 1 --type dvddrive --medium none -sleep 5 - -echo "Exporting the VM to an OVF file" -vboxmanage export "$VM" -o "$ALPDIR"/alpine_arm64.ovf -sleep 5 - -echo "Deleting the VM" -vboxmanage unregistervm "$VM" --delete +wait echo "starting packer build of alpine ${VERSION} for ${ARCH}" if bento build --vars 'ssh_timeout=60m' --vars vbox_source_path="$ALPDIR"/alpine_arm64.ovf,vbox_checksum=null "$(pwd)"/os_pkrvars/alpine/alpine-3.21-aarch64.pkrvars.hcl; then