Skip to content

Commit b48521f

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-2023.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-2023.sh script to help maintainers automatically update the verison. Signed-off-by: Gyokhan Kochmarla <[email protected]>
1 parent b18eed7 commit b48521f

File tree

5 files changed

+135
-0
lines changed

5 files changed

+135
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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}" == *"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+
local new_location="${base_url}/${filename}"
74+
75+
json_vars location="${new_location}" arch="${arch}" digest="${digest}"
76+
}
77+
78+
return 0
79+
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
fi

templates/amazonlinux-2023.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
minimumLimaVersion: 2.0.0
2+
3+
images:
4+
- 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"
5+
arch: "x86_64"
6+
digest: "sha256:c91f244483d9a460869738f7fcfb5e37eb402aec8582d10456cf0c108e1a4d4c"
7+
- 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"
8+
arch: "aarch64"
9+
digest: "sha256:7aef1f189076a0416cd16062bbf7e0928d81061e68411cab8904447e1bd5eafd"
10+
11+
provision:
12+
- mode: system
13+
script: |
14+
#!/bin/bash
15+
set -eux -o pipefail
16+
17+
# Lima seemingly uses 'mount0' tag on this setup but Guest Agent expects path.
18+
MOUNT_POINT="/mnt/host"
19+
20+
if ! mountpoint -q "${MOUNT_POINT}"; then
21+
mkdir -p "${MOUNT_POINT}"
22+
mount -t virtiofs mount0 "${MOUNT_POINT}" || true
23+
fi
24+
- mode: system
25+
script: |
26+
#!/bin/bash
27+
set -eux -o pipefail
28+
# Update to the latest release on the first boot
29+
if [ ! -f /etc/lima-al2023-updated ]; then
30+
dnf upgrade -y --releasever=latest
31+
fi
32+
33+
mounts:
34+
- location: "~"
35+
mountPoint: "/mnt/host"

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)