This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch 4.19
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.19 by this push:
     new f8385a48da2 Add systemvmtemplate arm64 build support (#9437)
f8385a48da2 is described below

commit f8385a48da207e1522ce473586471ec931bae168
Author: Rohit Yadav <rohit.ya...@shapeblue.com>
AuthorDate: Fri Jul 26 13:38:03 2024 +0530

    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 <rohit.ya...@shapeblue.com>
    
    * try different machine cpu
    
    Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com>
    
    * don't accelerate KVM for different arch (arm64 vm on amd64 host)
    
    Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com>
    
    * fix building arm64 on x86
    
    Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com>
    
    * Update README.md
    
    ---------
    
    Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com>
    Co-authored-by: StepBee <step...@bienek.org>
---
 tools/appliance/README.md                          | 13 ++++++--
 tools/appliance/build.sh                           | 22 +++++++++----
 .../http/{preseed.cfg => preseed_aarch64.cfg}      |  9 ++++++
 .../http/{preseed.cfg => preseed_x86_64.cfg}       |  0
 .../scripts/install_systemvm_packages.sh           | 22 ++++++++-----
 ...n => template-base_aarch64-target_aarch64.json} | 36 ++++++++++++++++------
 ...on => template-base_x86_64-target_aarch64.json} | 36 ++++++++++++++++------
 ...son => template-base_x86_64-target_x86_64.json} |  2 +-
 8 files changed, 105 insertions(+), 35 deletions(-)

diff --git a/tools/appliance/README.md b/tools/appliance/README.md
index e9293d6373b..bc5b2014a59 100644
--- a/tools/appliance/README.md
+++ b/tools/appliance/README.md
@@ -25,7 +25,8 @@ CentOS based built-in user VM template.
 
 # Setting up Tools and Environment
 
-- Install packer and latest KVM, qemu on a Linux machine
+- Install packer (v1.8.x, v1.9.x tested) and latest KVM, qemu on a Linux x86
+  machine (Ubuntu 20.04 tested)
 - Install tools for exporting appliances: qemu-img, ovftool, faketime, 
sharutils
 - Build and install `vhd-util` as described in build.sh or use pre-built
   binaries at:
@@ -33,10 +34,18 @@ CentOS based built-in user VM template.
       http://packages.shapeblue.com/systemvmtemplate/vhd-util
       http://packages.shapeblue.com/systemvmtemplate/libvhd.so.1.0
 
+- For building ARM64 systemvm template on amd64 systems, please also install:
+  qemu-utils qemu-system-arm qemu-efi-aarch64
+
 # How to build appliances
 
 Just run build.sh, it will export archived appliances for KVM, XenServer,
 VMWare and HyperV in `dist` directory:
 
-    bash build.sh systemvmtemplate
+    bash build.sh <name> <version> <arch>
+    bash build.sh systemvmtemplate 4.19.1.0 x86_64
+    bash build.sh systemvmtemplate 4.19.1.0 aarch64
+
+For building builtin x86_64 template run:
+
     bash build.sh builtin
diff --git a/tools/appliance/build.sh b/tools/appliance/build.sh
index 1c83f9aba51..4865842d17b 100755
--- a/tools/appliance/build.sh
+++ b/tools/appliance/build.sh
@@ -27,6 +27,8 @@ Usage:
      (or use command line arg, default systemvmtemplate)
    * Set \$version to provide version to apply to built appliance
      (or use command line arg, default empty)
+   * Set \$target_arch to provide target architecture
+     (or use command line arg, default to current architecture. Currently 
x86_64 and aarch64 are implemented)
    * Set \$BUILD_NUMBER to provide build number to apply to built appliance
      (or use command line arg, default empty)
    * Set \$DEBUG=1 to enable debug logging
@@ -85,12 +87,18 @@ if [[ ! -z "${JENKINS_HOME}" ]]; then
   DEBUG=1
 fi
 
+# get current system architecture
+base_arch=`arch`
+
 # which packer definition to use
 appliance="${1:-${appliance:-systemvmtemplate}}"
 
 # optional version tag to put into the image filename
 version="${2:-${version:-}}"
 
+# which architecture to build the template for
+target_arch="${3:-${target_arch:-${base_arch}}}"
+
 # optional (jenkins) build number tag to put into the image filename
 BUILD_NUMBER="${4:-${BUILD_NUMBER:-}}"
 
@@ -105,7 +113,7 @@ elif [ ! -z "${BUILD_NUMBER}" ]; then
   version_tag="-${BUILD_NUMBER}"
 fi
 
-appliance_build_name=${appliance}${version_tag}
+appliance_build_name="${appliance}${version_tag}-${target_arch}"
 
 ###
 ### Generic helper functions
@@ -218,7 +226,7 @@ function prepare() {
 
 function packer_build() {
   log INFO "building new image with packer"
-  cd ${appliance_build_name} && packer build template.json && cd ..
+  cd ${appliance_build_name} && packer build 
template-base_${base_arch}-target_${target_arch}.json && cd ..
 }
 
 function stage_vmx() {
@@ -349,10 +357,12 @@ function main() {
 
   # process the disk at dist
   kvm_export
-  ovm_export
-  xen_server_export
-  vmware_export
-  hyperv_export
+  if [ "${target_arch}" == "x86_64" ]; then
+    ovm_export
+    xen_server_export
+    vmware_export
+    hyperv_export
+  fi
   rm -f "dist/${appliance}"
   cd dist && chmod +r * && cd ..
   cd dist && md5sum * > md5sum.txt && cd ..
diff --git a/tools/appliance/systemvmtemplate/http/preseed.cfg 
b/tools/appliance/systemvmtemplate/http/preseed_aarch64.cfg
similarity index 88%
copy from tools/appliance/systemvmtemplate/http/preseed.cfg
copy to tools/appliance/systemvmtemplate/http/preseed_aarch64.cfg
index ae71ed5c063..5262603deaa 100644
--- a/tools/appliance/systemvmtemplate/http/preseed.cfg
+++ b/tools/appliance/systemvmtemplate/http/preseed_aarch64.cfg
@@ -60,6 +60,12 @@ d-i partman-auto/disk string /dev/vda
 d-i partman-auto/method string regular
 d-i partman-auto/expert_recipe string                         \
       boot-root ::                                            \
+              538 538 1075 free                               \
+                      $iflabel{ gpt }                         \
+                      $reusemethod{ }                         \
+                      method{ efi }                           \
+                      format{ }                               \
+              .                                               \
               400 60 400 ext2                                 \
                       $primary{ } $bootable{ }                \
                       method{ format } format{ }              \
@@ -80,6 +86,9 @@ d-i partman-partitioning/confirm_write_new_label boolean true
 d-i partman/choose_partition select finish
 d-i partman/confirm boolean true
 d-i partman/confirm_nooverwrite boolean true
+grub-efi-arm64  grub2/force_efi_extra_removable boolean true
+d-i partman-partitioning/choose_label select gpt
+d-i partman-partitioning/default_label string gpt
 
 ### Base system installation
 # ...
diff --git a/tools/appliance/systemvmtemplate/http/preseed.cfg 
b/tools/appliance/systemvmtemplate/http/preseed_x86_64.cfg
similarity index 100%
rename from tools/appliance/systemvmtemplate/http/preseed.cfg
rename to tools/appliance/systemvmtemplate/http/preseed_x86_64.cfg
diff --git 
a/tools/appliance/systemvmtemplate/scripts/install_systemvm_packages.sh 
b/tools/appliance/systemvmtemplate/scripts/install_systemvm_packages.sh
index 3b4ef653728..ebf53dfc2d3 100644
--- a/tools/appliance/systemvmtemplate/scripts/install_systemvm_packages.sh
+++ b/tools/appliance/systemvmtemplate/scripts/install_systemvm_packages.sh
@@ -87,7 +87,7 @@ function install_packages() {
   apt_clean
 
   # 32 bit architecture support for vhd-util
-  if [ "${arch}" != "i386" ]; then
+  if [[ "${arch}" != "i386" && "${arch}" != "arm64" ]]; then
     dpkg --add-architecture i386
     apt-get update
     ${apt_get} install libuuid1:i386 libc6:i386
@@ -96,17 +96,25 @@ function install_packages() {
   # Install docker and containerd for CKS
   curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
   apt-key fingerprint 0EBFCD88
-  add-apt-repository "deb [arch=amd64] 
https://download.docker.com/linux/debian $(lsb_release -cs) stable"
+  if [ "${arch}" == "arm64" ]; then
+    add-apt-repository "deb [arch=arm64] 
https://download.docker.com/linux/debian $(lsb_release -cs) stable"
+  elif [ "${arch}" == "amd64" ]; then
+    add-apt-repository "deb [arch=amd64] 
https://download.docker.com/linux/debian $(lsb_release -cs) stable"
+  else
+    add-apt-repository "deb [arch=amd64] 
https://download.docker.com/linux/debian $(lsb_release -cs) stable"
+  fi
   apt-get update
   ${apt_get} install containerd.io
 
   apt_clean
 
-  install_vhd_util
-  # Install xenserver guest utilities as debian repos don't have it
-  wget 
https://mirrors.kernel.org/ubuntu/pool/main/x/xe-guest-utilities/xe-guest-utilities_7.10.0-0ubuntu1_amd64.deb
-  dpkg -i xe-guest-utilities_7.10.0-0ubuntu1_amd64.deb
-  rm -f xe-guest-utilities_7.10.0-0ubuntu1_amd64.deb
+  if [ "${arch}" != "arm64" ]; then
+    install_vhd_util
+    # Install xenserver guest utilities as debian repos don't have it
+    wget 
https://mirrors.kernel.org/ubuntu/pool/main/x/xe-guest-utilities/xe-guest-utilities_7.10.0-0ubuntu1_amd64.deb
+    dpkg -i xe-guest-utilities_7.10.0-0ubuntu1_amd64.deb
+    rm -f xe-guest-utilities_7.10.0-0ubuntu1_amd64.deb
+  fi
 }
 
 return 2>/dev/null || install_packages
diff --git a/tools/appliance/systemvmtemplate/template.json 
b/tools/appliance/systemvmtemplate/template-base_aarch64-target_aarch64.json
similarity index 72%
copy from tools/appliance/systemvmtemplate/template.json
copy to 
tools/appliance/systemvmtemplate/template-base_aarch64-target_aarch64.json
index 6a7022a50f9..4d8a540a396 100644
--- a/tools/appliance/systemvmtemplate/template.json
+++ b/tools/appliance/systemvmtemplate/template-base_aarch64-target_aarch64.json
@@ -4,9 +4,9 @@
     {
       "accelerator": "kvm",
       "boot_command": [
-        "<esc><wait>",
-        "install <wait>",
-        "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg <wait>",
+        "c<wait>",
+        "linux /install.a64/vmlinuz <wait>",
+        "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed_aarch64.cfg 
<wait>",
         "debian-installer=en_US.UTF-8 <wait>",
         "auto <wait>",
         "language=en locale=en_US.UTF-8 <wait>",
@@ -19,31 +19,49 @@
         "debconf/frontend=noninteractive <wait>",
         "console-setup/ask_detect=false <wait>",
         "console-keymaps-at/keymap=us <wait>",
-        "<enter><wait>"
+       "---",
+        "<enter><wait>",
+       "initrd /install.a64/initrd.gz",
+       "<enter><wait>",
+       "boot<enter><wait>"
       ],
-      "boot_wait": "5s",
+      "boot_wait": "180s",
       "disk_interface": "virtio",
+      "cdrom_interface": "virtio-scsi",
       "disk_size": "5000M",
       "format": "qcow2",
       "headless": true,
       "http_directory": "http",
-      "iso_checksum": 
"sha512:7ef909042308510e42e2da38fa2815e4f39292b07026fc8cf1b12f3148e7329da7d24b01914fc7449895ee08a38f567f1e09c5f7a9bfaa65bb454ebfd0439f91",
-      "iso_url": 
"https://cdimage.debian.org/mirror/cdimage/archive/11.10.0/amd64/iso-cd/debian-11.10.0-amd64-netinst.iso";,
+      "iso_checksum": 
"sha512:4980197fa30646a43df2672d98500a182d6636422e39e809d986551356f4d24b1ffab6d745331369b27f2e9a5326f020ba141df5772ac2c6328c08cce73de7e8",
+      "iso_url": 
"https://cdimage.debian.org/mirror/cdimage/archive/11.10.0/arm64/iso-cd/debian-11.10.0-arm64-netinst.iso";,
       "net_device": "virtio-net",
       "output_directory": "../dist",
+      "qemu_binary": "qemu-system-aarch64",
       "qemuargs": [
         [
           "-m",
           "500M"
         ],
+       [
+          "-machine",
+          "virt"
+        ],
+       [
+          "-cpu",
+          "host"
+        ],
         [
           "-smp",
           "1"
-        ]
+        ],
+       [ "-pflash", "/usr/share/AAVMF/AAVMF_CODE.fd" ],
+       [ "-monitor", "none" ],
+       [ "-enable-kvm" ],
+       [ "-boot", "strict=off" ]
       ],
       "shutdown_command": "sudo halt -p",
       "ssh_password": "cloud",
-      "ssh_timeout": "30m",
+      "ssh_timeout": "120m",
       "ssh_username": "cloud",
       "type": "qemu",
       "vm_name": "systemvmtemplate"
diff --git a/tools/appliance/systemvmtemplate/template.json 
b/tools/appliance/systemvmtemplate/template-base_x86_64-target_aarch64.json
similarity index 70%
copy from tools/appliance/systemvmtemplate/template.json
copy to 
tools/appliance/systemvmtemplate/template-base_x86_64-target_aarch64.json
index 6a7022a50f9..4763d1e3e82 100644
--- a/tools/appliance/systemvmtemplate/template.json
+++ b/tools/appliance/systemvmtemplate/template-base_x86_64-target_aarch64.json
@@ -2,11 +2,10 @@
   "_license": "Apache License 2.0",
   "builders": [
     {
-      "accelerator": "kvm",
       "boot_command": [
-        "<esc><wait>",
-        "install <wait>",
-        "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg <wait>",
+        "c<wait>",
+        "linux /install.a64/vmlinuz <wait>",
+        "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed_aarch64.cfg 
<wait>",
         "debian-installer=en_US.UTF-8 <wait>",
         "auto <wait>",
         "language=en locale=en_US.UTF-8 <wait>",
@@ -19,31 +18,48 @@
         "debconf/frontend=noninteractive <wait>",
         "console-setup/ask_detect=false <wait>",
         "console-keymaps-at/keymap=us <wait>",
-        "<enter><wait>"
+        "---",
+        "<enter><wait>",
+        "initrd /install.a64/initrd.gz",
+        "<enter><wait>",
+        "boot<enter><wait>"
       ],
-      "boot_wait": "5s",
+      "boot_wait": "60s",
       "disk_interface": "virtio",
+      "cdrom_interface": "virtio-scsi",
       "disk_size": "5000M",
       "format": "qcow2",
       "headless": true,
       "http_directory": "http",
-      "iso_checksum": 
"sha512:7ef909042308510e42e2da38fa2815e4f39292b07026fc8cf1b12f3148e7329da7d24b01914fc7449895ee08a38f567f1e09c5f7a9bfaa65bb454ebfd0439f91",
-      "iso_url": 
"https://cdimage.debian.org/mirror/cdimage/archive/11.10.0/amd64/iso-cd/debian-11.10.0-amd64-netinst.iso";,
+      "iso_checksum": 
"sha512:4980197fa30646a43df2672d98500a182d6636422e39e809d986551356f4d24b1ffab6d745331369b27f2e9a5326f020ba141df5772ac2c6328c08cce73de7e8",
+      "iso_url": 
"https://cdimage.debian.org/mirror/cdimage/archive/11.10.0/arm64/iso-cd/debian-11.10.0-arm64-netinst.iso";,
       "net_device": "virtio-net",
       "output_directory": "../dist",
+      "qemu_binary": "qemu-system-aarch64",
       "qemuargs": [
         [
           "-m",
           "500M"
         ],
+        [
+          "-machine",
+          "virt"
+        ],
+        [
+          "-cpu",
+          "cortex-a72"
+        ],
         [
           "-smp",
           "1"
-        ]
+        ],
+        [ "-bios", "/usr/share/qemu-efi-aarch64/QEMU_EFI.fd" ],
+        [ "-monitor", "none" ],
+        [ "-boot", "strict=off" ]
       ],
       "shutdown_command": "sudo halt -p",
       "ssh_password": "cloud",
-      "ssh_timeout": "30m",
+      "ssh_timeout": "120m",
       "ssh_username": "cloud",
       "type": "qemu",
       "vm_name": "systemvmtemplate"
diff --git a/tools/appliance/systemvmtemplate/template.json 
b/tools/appliance/systemvmtemplate/template-base_x86_64-target_x86_64.json
similarity index 99%
rename from tools/appliance/systemvmtemplate/template.json
rename to 
tools/appliance/systemvmtemplate/template-base_x86_64-target_x86_64.json
index 6a7022a50f9..2a307f8ba7c 100644
--- a/tools/appliance/systemvmtemplate/template.json
+++ b/tools/appliance/systemvmtemplate/template-base_x86_64-target_x86_64.json
@@ -6,7 +6,7 @@
       "boot_command": [
         "<esc><wait>",
         "install <wait>",
-        "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg <wait>",
+        "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed_x86_64.cfg 
<wait>",
         "debian-installer=en_US.UTF-8 <wait>",
         "auto <wait>",
         "language=en locale=en_US.UTF-8 <wait>",

Reply via email to