Skip to content

Commit f8385a4

Browse files
Add systemvmtemplate arm64 build support (#9437)
* Move and copy files to new filenames * Adjust bash scripts to support arm64 * change preseed for arm64 to create EFI partition * change packer template files to support arm64 * Correct preseed file name in x86_64 packer template * fixes Signed-off-by: Rohit Yadav <[email protected]> * try different machine cpu Signed-off-by: Rohit Yadav <[email protected]> * don't accelerate KVM for different arch (arm64 vm on amd64 host) Signed-off-by: Rohit Yadav <[email protected]> * fix building arm64 on x86 Signed-off-by: Rohit Yadav <[email protected]> * Update README.md --------- Signed-off-by: Rohit Yadav <[email protected]> Co-authored-by: StepBee <[email protected]>
1 parent 49cd5ba commit f8385a4

File tree

8 files changed

+349
-16
lines changed

8 files changed

+349
-16
lines changed

tools/appliance/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,27 @@ CentOS based built-in user VM template.
2525

2626
# Setting up Tools and Environment
2727

28-
- Install packer and latest KVM, qemu on a Linux machine
28+
- Install packer (v1.8.x, v1.9.x tested) and latest KVM, qemu on a Linux x86
29+
machine (Ubuntu 20.04 tested)
2930
- Install tools for exporting appliances: qemu-img, ovftool, faketime, sharutils
3031
- Build and install `vhd-util` as described in build.sh or use pre-built
3132
binaries at:
3233

3334
http://packages.shapeblue.com/systemvmtemplate/vhd-util
3435
http://packages.shapeblue.com/systemvmtemplate/libvhd.so.1.0
3536

37+
- For building ARM64 systemvm template on amd64 systems, please also install:
38+
qemu-utils qemu-system-arm qemu-efi-aarch64
39+
3640
# How to build appliances
3741

3842
Just run build.sh, it will export archived appliances for KVM, XenServer,
3943
VMWare and HyperV in `dist` directory:
4044

41-
bash build.sh systemvmtemplate
45+
bash build.sh <name> <version> <arch>
46+
bash build.sh systemvmtemplate 4.19.1.0 x86_64
47+
bash build.sh systemvmtemplate 4.19.1.0 aarch64
48+
49+
For building builtin x86_64 template run:
50+
4251
bash build.sh builtin

tools/appliance/build.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Usage:
2727
(or use command line arg, default systemvmtemplate)
2828
* Set \$version to provide version to apply to built appliance
2929
(or use command line arg, default empty)
30+
* Set \$target_arch to provide target architecture
31+
(or use command line arg, default to current architecture. Currently x86_64 and aarch64 are implemented)
3032
* Set \$BUILD_NUMBER to provide build number to apply to built appliance
3133
(or use command line arg, default empty)
3234
* Set \$DEBUG=1 to enable debug logging
@@ -85,12 +87,18 @@ if [[ ! -z "${JENKINS_HOME}" ]]; then
8587
DEBUG=1
8688
fi
8789

90+
# get current system architecture
91+
base_arch=`arch`
92+
8893
# which packer definition to use
8994
appliance="${1:-${appliance:-systemvmtemplate}}"
9095

9196
# optional version tag to put into the image filename
9297
version="${2:-${version:-}}"
9398

99+
# which architecture to build the template for
100+
target_arch="${3:-${target_arch:-${base_arch}}}"
101+
94102
# optional (jenkins) build number tag to put into the image filename
95103
BUILD_NUMBER="${4:-${BUILD_NUMBER:-}}"
96104

@@ -105,7 +113,7 @@ elif [ ! -z "${BUILD_NUMBER}" ]; then
105113
version_tag="-${BUILD_NUMBER}"
106114
fi
107115

108-
appliance_build_name=${appliance}${version_tag}
116+
appliance_build_name="${appliance}${version_tag}-${target_arch}"
109117

110118
###
111119
### Generic helper functions
@@ -218,7 +226,7 @@ function prepare() {
218226

219227
function packer_build() {
220228
log INFO "building new image with packer"
221-
cd ${appliance_build_name} && packer build template.json && cd ..
229+
cd ${appliance_build_name} && packer build template-base_${base_arch}-target_${target_arch}.json && cd ..
222230
}
223231

224232
function stage_vmx() {
@@ -349,10 +357,12 @@ function main() {
349357

350358
# process the disk at dist
351359
kvm_export
352-
ovm_export
353-
xen_server_export
354-
vmware_export
355-
hyperv_export
360+
if [ "${target_arch}" == "x86_64" ]; then
361+
ovm_export
362+
xen_server_export
363+
vmware_export
364+
hyperv_export
365+
fi
356366
rm -f "dist/${appliance}"
357367
cd dist && chmod +r * && cd ..
358368
cd dist && md5sum * > md5sum.txt && cd ..
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
### Localization
19+
# Locale sets language and country.
20+
d-i debian-installer/locale string en_US.UTF-8
21+
d-i debian-installer/country string IN
22+
23+
# Keyboard selection.
24+
d-i keymap select us
25+
d-i keyboard-configuration/xkb-keymap select us
26+
27+
### Network configuration
28+
d-i netcfg/choose_interface select auto
29+
d-i netcfg/get_hostname string systemvm
30+
d-i netcfg/get_domain string apache.org
31+
d-i netcfg/wireless_wep string
32+
33+
d-i hw-detect/load_firmware boolean true
34+
35+
### Mirror settings
36+
d-i mirror/country string manual
37+
d-i mirror/http/hostname string deb.debian.org
38+
d-i mirror/http/directory string /debian
39+
d-i mirror/http/proxy string
40+
41+
### Apt setup
42+
d-i apt-setup/cdrom/set-first false
43+
d-i apt-setup/security-updates boolean true
44+
d-i apt-setup/services-select multiselect security, updates
45+
d-i apt-setup/security_host string security.debian.org
46+
d-i apt-setup/local0/source boolean false
47+
d-i apt-setup/multiarch string i386
48+
d-i apt-setup/backports boolean true
49+
d-i apt-setup/contrib boolean true
50+
d-i apt-setup/multiverse boolean true
51+
d-i apt-setup/universe boolean true
52+
53+
### Clock and time zone setup
54+
d-i clock-setup/utc boolean true
55+
d-i time/zone string UTC
56+
d-i clock-setup/ntp boolean true
57+
58+
### Partitioning
59+
d-i partman-auto/disk string /dev/vda
60+
d-i partman-auto/method string regular
61+
d-i partman-auto/expert_recipe string \
62+
boot-root :: \
63+
538 538 1075 free \
64+
$iflabel{ gpt } \
65+
$reusemethod{ } \
66+
method{ efi } \
67+
format{ } \
68+
. \
69+
400 60 400 ext2 \
70+
$primary{ } $bootable{ } \
71+
method{ format } format{ } \
72+
use_filesystem{ } filesystem{ ext2 } \
73+
mountpoint{ /boot } \
74+
. \
75+
256 1000 256 linux-swap \
76+
method{ swap } format{ } \
77+
. \
78+
2240 40 4000 ext4 \
79+
method{ format } format{ } \
80+
use_filesystem{ } filesystem{ ext4 } \
81+
mountpoint{ / } \
82+
.
83+
84+
d-i partman-md/confirm boolean true
85+
d-i partman-partitioning/confirm_write_new_label boolean true
86+
d-i partman/choose_partition select finish
87+
d-i partman/confirm boolean true
88+
d-i partman/confirm_nooverwrite boolean true
89+
grub-efi-arm64 grub2/force_efi_extra_removable boolean true
90+
d-i partman-partitioning/choose_label select gpt
91+
d-i partman-partitioning/default_label string gpt
92+
93+
### Base system installation
94+
# ...
95+
96+
### Account setup
97+
d-i passwd/root-login boolean false
98+
d-i passwd/root-password password password
99+
d-i passwd/root-password-again password password
100+
d-i passwd/user-fullname string Cloud User
101+
d-i passwd/username string cloud
102+
d-i passwd/user-password password cloud
103+
d-i passwd/user-password-again password cloud
104+
d-i user-setup/encrypt-home boolean false
105+
d-i user-setup/allow-password-weak boolean true
106+
d-i passwd/user-default-groups string audio cdrom video admin
107+
108+
### Package selection
109+
tasksel tasksel/first multiselect ssh-server
110+
d-i pkgsel/include string openssh-server ntp acpid sudo bzip2 openssl
111+
# Allowed values: none, safe-upgrade, full-upgrade
112+
d-i pkgsel/upgrade select full-upgrade
113+
d-i pkgsel/update-policy select none
114+
115+
popularity-contest popularity-contest/participate boolean false
116+
117+
### Boot loader installation
118+
d-i grub-installer/only_debian boolean true
119+
d-i grub-installer/bootdev string default
120+
d-i finish-install/reboot_in_progress note
121+
122+
#### Advanced options

tools/appliance/systemvmtemplate/scripts/install_systemvm_packages.sh

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function install_packages() {
8787
apt_clean
8888

8989
# 32 bit architecture support for vhd-util
90-
if [ "${arch}" != "i386" ]; then
90+
if [[ "${arch}" != "i386" && "${arch}" != "arm64" ]]; then
9191
dpkg --add-architecture i386
9292
apt-get update
9393
${apt_get} install libuuid1:i386 libc6:i386
@@ -96,17 +96,25 @@ function install_packages() {
9696
# Install docker and containerd for CKS
9797
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
9898
apt-key fingerprint 0EBFCD88
99-
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
99+
if [ "${arch}" == "arm64" ]; then
100+
add-apt-repository "deb [arch=arm64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
101+
elif [ "${arch}" == "amd64" ]; then
102+
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
103+
else
104+
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
105+
fi
100106
apt-get update
101107
${apt_get} install containerd.io
102108

103109
apt_clean
104110

105-
install_vhd_util
106-
# Install xenserver guest utilities as debian repos don't have it
107-
wget https://mirrors.kernel.org/ubuntu/pool/main/x/xe-guest-utilities/xe-guest-utilities_7.10.0-0ubuntu1_amd64.deb
108-
dpkg -i xe-guest-utilities_7.10.0-0ubuntu1_amd64.deb
109-
rm -f xe-guest-utilities_7.10.0-0ubuntu1_amd64.deb
111+
if [ "${arch}" != "arm64" ]; then
112+
install_vhd_util
113+
# Install xenserver guest utilities as debian repos don't have it
114+
wget https://mirrors.kernel.org/ubuntu/pool/main/x/xe-guest-utilities/xe-guest-utilities_7.10.0-0ubuntu1_amd64.deb
115+
dpkg -i xe-guest-utilities_7.10.0-0ubuntu1_amd64.deb
116+
rm -f xe-guest-utilities_7.10.0-0ubuntu1_amd64.deb
117+
fi
110118
}
111119

112120
return 2>/dev/null || install_packages
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
"_license": "Apache License 2.0",
3+
"builders": [
4+
{
5+
"accelerator": "kvm",
6+
"boot_command": [
7+
"c<wait>",
8+
"linux /install.a64/vmlinuz <wait>",
9+
"preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed_aarch64.cfg <wait>",
10+
"debian-installer=en_US.UTF-8 <wait>",
11+
"auto <wait>",
12+
"language=en locale=en_US.UTF-8 <wait>",
13+
"kbd-chooser/method=us <wait>",
14+
"keyboard-configuration/xkb-keymap=us <wait>",
15+
"netcfg/get_hostname=systemvm <wait>",
16+
"netcfg/get_domain=apache.org <wait>",
17+
"country=IN keymap=us <wait>",
18+
"fb=false <wait>",
19+
"debconf/frontend=noninteractive <wait>",
20+
"console-setup/ask_detect=false <wait>",
21+
"console-keymaps-at/keymap=us <wait>",
22+
"---",
23+
"<enter><wait>",
24+
"initrd /install.a64/initrd.gz",
25+
"<enter><wait>",
26+
"boot<enter><wait>"
27+
],
28+
"boot_wait": "180s",
29+
"disk_interface": "virtio",
30+
"cdrom_interface": "virtio-scsi",
31+
"disk_size": "5000M",
32+
"format": "qcow2",
33+
"headless": true,
34+
"http_directory": "http",
35+
"iso_checksum": "sha512:4980197fa30646a43df2672d98500a182d6636422e39e809d986551356f4d24b1ffab6d745331369b27f2e9a5326f020ba141df5772ac2c6328c08cce73de7e8",
36+
"iso_url": "https://cdimage.debian.org/mirror/cdimage/archive/11.10.0/arm64/iso-cd/debian-11.10.0-arm64-netinst.iso",
37+
"net_device": "virtio-net",
38+
"output_directory": "../dist",
39+
"qemu_binary": "qemu-system-aarch64",
40+
"qemuargs": [
41+
[
42+
"-m",
43+
"500M"
44+
],
45+
[
46+
"-machine",
47+
"virt"
48+
],
49+
[
50+
"-cpu",
51+
"host"
52+
],
53+
[
54+
"-smp",
55+
"1"
56+
],
57+
[ "-pflash", "/usr/share/AAVMF/AAVMF_CODE.fd" ],
58+
[ "-monitor", "none" ],
59+
[ "-enable-kvm" ],
60+
[ "-boot", "strict=off" ]
61+
],
62+
"shutdown_command": "sudo halt -p",
63+
"ssh_password": "cloud",
64+
"ssh_timeout": "120m",
65+
"ssh_username": "cloud",
66+
"type": "qemu",
67+
"vm_name": "systemvmtemplate"
68+
}
69+
],
70+
"description": "CloudStack SystemVM template",
71+
"provisioners": [
72+
{
73+
"execute_command": "echo 'cloud' | sudo -u root -S bash {{.Path}}",
74+
"scripts": [
75+
"scripts/apt_upgrade.sh",
76+
"scripts/configure_grub.sh",
77+
"scripts/configure_locale.sh",
78+
"scripts/configure_networking.sh",
79+
"scripts/configure_acpid.sh",
80+
"scripts/install_systemvm_packages.sh",
81+
"scripts/configure_conntrack.sh",
82+
"scripts/authorized_keys.sh",
83+
"scripts/configure_persistent_config.sh",
84+
"scripts/configure_login.sh",
85+
"../cloud_scripts_shar_archive.sh",
86+
"scripts/configure_systemvm_services.sh",
87+
"scripts/cleanup.sh",
88+
"scripts/finalize.sh"
89+
],
90+
"type": "shell"
91+
}
92+
]
93+
}

0 commit comments

Comments
 (0)