Skip to content

Commit

Permalink
Add aarch64 support to RHEL8 template (#286)
Browse files Browse the repository at this point in the history
The updated RHEL8 packer-maas template to support aarch64 builds and
deployments.
  • Loading branch information
alanbach authored Dec 19, 2024
1 parent f07eb93 commit b8ed17a
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 25 deletions.
42 changes: 38 additions & 4 deletions rhel8/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,53 @@ include ../scripts/check.mk

PACKER ?= packer
PACKER_LOG ?= 0
ISO ?= ${RHEL8_ISO_PATH}
ISO ?= rhel-baseos-8.0-x86_64-dvd.iso
TIMEOUT ?= 1h
ARCH ?= x86_64

ifeq ($(wildcard /usr/share/OVMF/OVMF_CODE.fd),)
OVMF_SFX ?= _4M
else
OVMF_SFX ?=
endif

export PACKER_LOG

# Fallback
ifeq ($(strip $(ARCH)),amd64)
ARCH = x86_64
endif

.PHONY: all clean

all: rhel8.tar.gz

$(eval $(call check_packages_deps))

rhel8.tar.gz: check-deps clean
${PACKER} init rhel8.pkr.hcl && ${PACKER} build -var "rhel8_iso_path=${ISO}" -var timeout=${TIMEOUT} rhel8.pkr.hcl
lint:
packer validate .
packer fmt -check -diff .

format:
packer fmt .

OVMF_VARS.fd: /usr/share/OVMF/OVMF_VARS${OVMF_SFX}.fd
cp -v $< ${ARCH}_VARS.fd

SIZE_VARS.fd:
ifeq ($(strip $(ARCH)),aarch64)
truncate -s 64m ${ARCH}_VARS.fd
else
truncate -s 2m ${ARCH}_VARS.fd
endif

rhel8.tar.gz: check-deps clean OVMF_VARS.fd SIZE_VARS.fd
${PACKER} init rhel8.pkr.hcl && ${PACKER} build \
-var architecture=${ARCH} \
-var ovmf_suffix=${OVMF_SFX} \
-var "rhel8_iso_path=${ISO}" \
-var timeout=${TIMEOUT} \
rhel8.pkr.hcl

clean:
${RM} -rf output-rhel8 rhel8.tar.gz
${RM} -rf *.fd output-rhel8 rhel8.tar.gz
54 changes: 45 additions & 9 deletions rhel8/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

## Introduction

The Packer template in this directory creates a RHEL 8 AMD64 image for use with MAAS.
The Packer template in this directory creates a RHEL 8 AMD64/ARM64 image for use with MAAS.

## Prerequisites (to create the image)

* A machine running Ubuntu 18.04+ with the ability to run KVM virtual machines.
* A machine running Ubuntu 22.04+ with the ability to run KVM virtual machines.
* qemu-utils, libnbd-bin, nbdkit and fuse2fs
* [Packer](https://www.packer.io/intro/getting-started/install.html), v1.7.0 or newer
* [Packer](https://www.packer.io/intro/getting-started/install.html), v1.8.0 or newer
* The [RHEL 8 DVD ISO](https://developers.redhat.com/products/rhel/download)

## Requirements (to deploy the image)

* [MAAS](https://maas.io) 2.3+, [MAAS](https://maas.io) 2.7+ recommended
* [Curtin](https://launchpad.net/curtin) 19.3-792+
* [MAAS](https://maas.io) 3.3+
* [Curtin](https://launchpad.net/curtin) 22.1+

## Customizing the Image

The deployment image may be customized by modifying http/rhel8.ks. See the [CentOS kickstart documentation](https://docs.centos.org/en-US/centos/install-guide/Kickstart2/) for more information.
The deployment image may be customized by modifying http/rhel8.ks.pkrtpl.hcl. See the [CentOS kickstart documentation](https://docs.centos.org/en-US/centos/install-guide/Kickstart2/) for more information.

## Building the image using a proxy

Expand All @@ -35,7 +35,7 @@ export KS_PROXY=$HTTP_PROXY
You can easily build the image using the Makefile:

```shell
make ISO=/PATH/TO/rhel-8.3-x86_64-dvd.iso
make ISO=/PATH/TO/rhel-baseos-8.0-x86_64-dvd.iso
```

Alternatively you can manually run packer. Your current working directory must
Expand All @@ -44,7 +44,7 @@ you can generate an image with:

```shell
packer init
PACKER_LOG=1 packer build -var 'rhel8_iso_path=/PATH/TO/rhel-8.3-x86_64-dvd.iso' .
PACKER_LOG=1 packer build -var 'rhel8_iso_path=/PATH/TO/rhel-baseos-8.0-x86_64-dvd.iso' .
```

Note: rhel8.pkr.hcl is configured to run Packer in headless mode. Only Packer
Expand All @@ -56,6 +56,14 @@ Installation is non-interactive.

### Makefile Parameters

#### ARCH

Defaults to x86_64 to build AMD64 compatible images. In order to build ARM64 images, use ARCH=aarch64

### ISO

The path to the installation ISO image for RHEL.

#### TIMEOUT

The timeout to apply when building the image. The default value is set to 1h.
Expand All @@ -64,11 +72,39 @@ The timeout to apply when building the image. The default value is set to 1h.

```shell
maas $PROFILE boot-resources create \
name='rhel/8-custom' title='RHEL 8 Custom' \
name='rhel/rhel8' title='RHEL 8 Custom' \
architecture='amd64/generic' filetype='tgz' \
content@=rhel8.tar.gz
```

For ARM64, use:

```shell
maas $PROFILE boot-resources create \
name='rhel/rhel8' title='RHEL 8 Custom' \
architecture='arm64/generic' filetype='tgz' \
content@=rhel8.tar.gz
```

Please note that, currently due to lack of support in curtin, deploying ARM64 images needs a preseed file. This is due to [LP# 2090874](https://bugs.launchpad.net/curtin/+bug/2090874) and currently is in the process of getting fixed.

```
#cloud-config
debconf_selections:
maas: |
{{for line in str(curtin_preseed).splitlines()}}
{{line}}
{{endfor}}
extract_commands:
grub_install: curtin in-target -- cp -v /boot/efi/EFI/redhat/shimaa64.efi /boot/efi/EFI/redhat/shimx64.efi
late_commands:
maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null']
```

This file needs to be saved on Region Controllers under /var/snap/maas/current/preseeds/curtin_userdata_rhel_arm64_generic_rhel8 or /etc/maas/preseeds/curtin_userdata_rhel_arm64_generic_rhel8. The last portion of this file must match the image name uploaded in MAAS.

## Default Username

The default username is ```cloud-user```
18 changes: 11 additions & 7 deletions rhel8/http/rhel8.ks.pkrtpl.hcl
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
cdrom
#cdrom
harddrive --partition=vdb --dir=/
poweroff
eula --agreed
firewall --enabled --service=ssh
firstboot --disable
ignoredisk --only-use=vda
lang en_US.UTF-8
keyboard us
network --device eth0 --bootproto=dhcp
firewall --enabled --service=ssh
selinux --enforcing
timezone UTC --isUtc
bootloader --location=mbr --driveorder="vda" --timeout=1
timezone UTC --utc
rootpw --plaintext password

repo --name="AppStream" ${KS_APPSTREAM_REPOS} ${KS_PROXY}

ignoredisk --only-use=vda
bootloader --disabled
zerombr
clearpart --all --initlabel
part / --size=1 --grow --asprimary --fstype=ext4
Expand Down Expand Up @@ -44,7 +46,7 @@ sed -i 's/GRUB_ENABLE_BLSCFG=.*/GRUB_ENABLE_BLSCFG=false/g' /etc/default/grub
dnf clean all
%end

%packages
%packages --ignoremissing
@core
bash-completion
cloud-init
Expand All @@ -56,9 +58,11 @@ tar
# grub2-efi-x64 ships grub signed for UEFI secure boot. If grub2-efi-x64-modules
# is installed grub will be generated on deployment and unsigned which breaks
# UEFI secure boot.
grub2-efi-x64
grub2-pc
grub2-efi-*
shim-*
grub2-efi-*-modules
efibootmgr
shim-x64
dosfstools
lvm2
mdadm
Expand Down
61 changes: 56 additions & 5 deletions rhel8/rhel8.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,72 @@ variable "timeout" {
description = "Timeout for building the image"
}

variable "architecture" {
type = string
default = "amd64"
description = "The architecture to build the image for (amd64 or arm64)"
}

variable "ovmf_suffix" {
type = string
default = ""
description = "Suffix for OVMF CODE and VARS files. Newer systems such as Noble use _4M."
}

locals {
ks_proxy = var.ks_proxy != "" ? "--proxy=${var.ks_proxy}" : ""
qemu_arch = {
"x86_64" = "x86_64"
"aarch64" = "aarch64"
}
uefi_imp = {
"x86_64" = "OVMF"
"aarch64" = "AAVMF"
}
uefi_sfx = {
"x86_64" = "${var.ovmf_suffix}"
"aarch64" = ""
}
qemu_machine = {
"x86_64" = "accel=kvm"
"aarch64" = "virt"
}
qemu_cpu = {
"x86_64" = "host"
"aarch64" = "max"
}
ks_proxy = var.ks_proxy != "" ? "--proxy=${var.ks_proxy}" : ""
}


source "qemu" "rhel8" {
boot_command = ["<up><tab> ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/rhel8.ks ", "console=ttyS0 inst.cmdline", "<enter>"]
boot_wait = "3s"
boot_command = ["<up><wait>", "e", "<down><down><down><left>", " console=ttyS0 inst.cmdline inst.text inst.ks=http://{{.HTTPIP}}:{{.HTTPPort}}/rhel8.ks <f10>"]
boot_wait = "5s"
communicator = "none"
disk_size = "4G"
headless = true
iso_checksum = "none"
iso_url = var.rhel8_iso_path
memory = 2048
qemuargs = [["-serial", "stdio"], ["-cpu", "host"]]
cores = 4
qemu_binary = "qemu-system-${lookup(local.qemu_arch, var.architecture, "")}"
qemuargs = [
["-serial", "stdio"],
["-boot", "strict=off"],
["-device", "qemu-xhci"],
["-device", "usb-kbd"],
["-device", "virtio-net-pci,netdev=net0"],
["-netdev", "user,id=net0"],
["-device", "virtio-blk-pci,drive=drive0,bootindex=0"],
["-device", "virtio-blk-pci,drive=cdrom0,bootindex=1"],
["-machine", "${lookup(local.qemu_machine, var.architecture, "")}"],
["-cpu", "${lookup(local.qemu_cpu, var.architecture, "")}"],
["-device", "virtio-gpu-pci"],
["-global", "driver=cfi.pflash01,property=secure,value=off"],
["-drive", "if=pflash,format=raw,unit=0,id=ovmf_code,readonly=on,file=/usr/share/${lookup(local.uefi_imp, var.architecture, "")}/${lookup(local.uefi_imp, var.architecture, "")}_CODE${lookup(local.uefi_sfx, var.architecture, "")}.fd"],
["-drive", "if=pflash,format=raw,unit=1,id=ovmf_vars,file=${var.architecture}_VARS.fd"],
["-drive", "file=output-rhel8/packer-rhel8,if=none,id=drive0,cache=writeback,discard=ignore,format=qcow2"],
["-drive", "file=${var.rhel8_iso_path},if=none,id=cdrom0,media=cdrom"]
]
shutdown_timeout = var.timeout
http_content = {
"/rhel8.ks" = templatefile("${path.root}/http/rhel8.ks.pkrtpl.hcl",
Expand All @@ -59,7 +111,6 @@ source "qemu" "rhel8" {
}
)
}

}

build {
Expand Down

0 comments on commit b8ed17a

Please sign in to comment.