Skip to content

Commit c5fd2b5

Browse files
feat(templates): add amazonlinux-2023 distro
This commit adds a simple template for the Amazon Linux 2023 operating system's 2025-12-08 version. The OS is scheduled to release every two weeks, therefore, a new script called hack/update-template-amazonlinux.sh is added next to the other template updater scripts. Find the latest images here: cdn.amazonlinux.com/al2023/os-images/latest/ This patch: - Adds amazonlinux-2023 template with 2025-12-08 release by default (fallback). - Resolves mount issues on AL2023 with host OS. - Introduces a script on VM init where it updates the system to latest release. - Adds update-template-amazonlinux.sh script to help maintainers automatically update the verison. Signed-off-by: Gyokhan Kochmarla <[email protected]>
1 parent b18eed7 commit c5fd2b5

File tree

6 files changed

+136
-0
lines changed

6 files changed

+136
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
3+
# SPDX-FileCopyrightText: Copyright The Lima Authors
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -eu -o pipefail
7+
8+
# check if the script is executed or sourced
9+
# shellcheck disable=SC1091
10+
if [[ ${BASH_SOURCE[0]} == "${0}" ]]; then
11+
scriptdir=$(dirname "${BASH_SOURCE[0]}")
12+
# shellcheck source=./cache-common-inc.sh
13+
. "${scriptdir}/cache-common-inc.sh"
14+
15+
# shellcheck source=/dev/null
16+
. "${scriptdir}/update-template.sh"
17+
else
18+
# this script is sourced
19+
if [[ -v SUPPORTED_DISTRIBUTIONS ]]; then
20+
SUPPORTED_DISTRIBUTIONS+=("amazonlinux")
21+
else
22+
declare -a SUPPORTED_DISTRIBUTIONS=("amazonlinux")
23+
fi
24+
25+
function amazonlinux_cache_key_for_image_kernel() {
26+
local location=$1
27+
case "${location}" in
28+
https://cdn.amazonlinux.com/al2023/os-images/*) ;;
29+
*) return 1 ;;
30+
esac
31+
# Create a cache key based on the location
32+
# We don't cache based on the resolved version because `update-template.sh` loop structure
33+
# and cache key usage implies one-to-one mapping if possible, but here we just return a unique key for the input.
34+
echo "amazonlinux_${location}"
35+
}
36+
37+
function amazonlinux_image_entry_for_image_kernel() {
38+
local location=$1
39+
case "${location}" in
40+
https://cdn.amazonlinux.com/al2023/os-images/*) ;;
41+
*) return 1 ;;
42+
esac
43+
44+
local latest_url
45+
# Get the redirect URL
46+
latest_url=$(curl -Ls -o /dev/null -w %{url_effective} https://cdn.amazonlinux.com/al2023/os-images/latest/)
47+
local version
48+
version=$(basename "${latest_url}")
49+
50+
local arch
51+
if [[ "${location}" == *"x86_64"* ]]; then
52+
arch="x86_64"
53+
elif [[ "${location}" == *"arm64"* ]] || [[ "${location}" == *"aarch64"* ]]; then
54+
arch="aarch64"
55+
else
56+
error_exit "Unknown arch for amazonlinux location: ${location}"
57+
fi
58+
59+
local folder="kvm"
60+
[[ "${arch}" == "aarch64" ]] && folder="kvm-arm64"
61+
62+
local base_url="https://cdn.amazonlinux.com/al2023/os-images/${version}/${folder}"
63+
local checksums
64+
checksums=$(download_to_cache "${base_url}/SHA256SUMS")
65+
66+
local filename digest line
67+
# Find the qcow2 file in SHA256SUMS
68+
line=$(grep "\.qcow2$" "${checksums}" | head -n 1)
69+
[[ -n ${line} ]] || error_exit "No qcow2 image found in ${base_url}/SHA256SUMS"
70+
71+
digest=$(echo "${line}" | awk '{print "sha256:"$1}')
72+
filename=$(echo "${line}" | awk '{print $2}')
73+
74+
# Allow shadowing the function argument 'location' with the new location
75+
# shellcheck disable=SC2034
76+
local location="${base_url}/${filename}"
77+
78+
json_vars location arch digest
79+
}
80+
81+
return 0
82+
fi

hack/update-template.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ if [[ ${BASH_SOURCE[0]} == "${0}" ]]; then
170170
. "${scriptdir}/update-template-fedora.sh"
171171
# shellcheck source=./update-template-opensuse.sh
172172
. "${scriptdir}/update-template-opensuse.sh"
173+
# shellcheck source=./update-template-amazonlinux.sh
174+
. "${scriptdir}/update-template-amazonlinux.sh"
173175
else
174176
# this script is sourced
175177
return 0
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# SPDX-FileCopyrightText: Copyright The Lima Authors
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -eux -o pipefail
7+
8+
# Workaround for Amazon Linux 2023
9+
if [ -f /etc/os-release ] && grep -q "Amazon Linux" /etc/os-release; then
10+
# 1. Create missing mount.virtiofs helper
11+
if [ ! -e /sbin/mount.virtiofs ]; then
12+
cat >/sbin/mount.virtiofs <<'EOF'
13+
#!/bin/sh
14+
exec mount -i -t virtiofs "$@"
15+
EOF
16+
chmod +x /sbin/mount.virtiofs
17+
fi
18+
19+
# Cloud-init fails to mount 'mount0' because it doesn't recognize it as a device,
20+
# so we extract the intended path from user-data and mount it manually.
21+
USER_DATA="/var/lib/cloud/instance/user-data.txt"
22+
if [ -f "${USER_DATA}" ]; then
23+
MOUNT_POINT=$(grep "mount0" "${USER_DATA}" | awk -F, '{print $2}' | tr -d '[:space:]')
24+
if [ -n "${MOUNT_POINT}" ] && ! mountpoint -q "${MOUNT_POINT}"; then
25+
mkdir -p "${MOUNT_POINT}"
26+
mount -t virtiofs mount0 "${MOUNT_POINT}" || true
27+
fi
28+
fi
29+
fi
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
images:
2+
- location: "https://cdn.amazonlinux.com/al2023/os-images/2023.9.20251208.0/kvm/al2023-kvm-2023.9.20251208.0-kernel-6.1-x86_64.xfs.gpt.qcow2"
3+
arch: "x86_64"
4+
digest: "sha256:c91f244483d9a460869738f7fcfb5e37eb402aec8582d10456cf0c108e1a4d4c"
5+
- location: "https://cdn.amazonlinux.com/al2023/os-images/2023.9.20251208.0/kvm-arm64/al2023-kvm-2023.9.20251208.0-kernel-6.1-arm64.xfs.gpt.qcow2"
6+
arch: "aarch64"
7+
digest: "sha256:7aef1f189076a0416cd16062bbf7e0928d81061e68411cab8904447e1bd5eafd"

templates/amazonlinux-2023.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
minimumLimaVersion: 2.0.0
2+
3+
base:
4+
- template:_images/amazonlinux-2023
5+
- template:_default/mounts
6+
7+
provision:
8+
- mode: system
9+
script: |
10+
#!/bin/bash
11+
set -eux -o pipefail
12+
# Update to the latest release on the first boot
13+
if [ ! -f /etc/lima-al2023-updated ]; then
14+
dnf upgrade -y --releasever=latest
15+
fi

templates/amazonlinux.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazonlinux-2023.yaml

0 commit comments

Comments
 (0)