Skip to content

Commit

Permalink
Add SLES15 aarch64 support along with
Browse files Browse the repository at this point in the history
some minor README updates.
  • Loading branch information
alanbach committed Jan 20, 2025
1 parent 88fc213 commit b60e703
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 26 deletions.
42 changes: 36 additions & 6 deletions sles15/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,52 @@ PACKER_LOG ?= 0
export PACKER_LOG
ISO ?= SLE-15-SP4-Full-x86_64-GM-Media1.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: sles15.tar.gz

$(eval $(call check_packages_deps))

sles15.tar.gz: check-deps clean
${PACKER} init sles.pkr.hcl && ${PACKER} build -var "sles15_iso_path=${ISO}" -var timeout=${TIMEOUT} -on-error=ask sles.pkr.hcl

clean:
${RM} -rf output-sles15 sles15.tar.gz

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

sles15.tar.gz: check-deps clean OVMF_VARS.fd SIZE_VARS.fd
${PACKER} init sles.pkr.hcl && ${PACKER} build \
-var sles15_iso_path=${ISO} \
-var architecture=${ARCH} \
-var timeout=${TIMEOUT} \
-var ovmf_suffix=${OVMF_SFX} \
-var timeout=${TIMEOUT} -on-error=ask sles.pkr.hcl

clean:
${RM} -rf *.fd output-sles15 sles15.tar.gz
27 changes: 16 additions & 11 deletions sles15/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

## Introduction

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

## Prerequisites (to create the image)

* 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.8.0 or newer
* The [SLES 15-SP4 DVD ISO](https://www.suse.com/download/sles/)
* The [SLES 15 DVD ISO](https://www.suse.com/download/sles/)

## Requirements (to deploy the image)

Expand All @@ -18,27 +18,24 @@ The Packer template in this directory creates a SLES 15 AMD64 image for use with

## Customizing the Image

The deployment image may be customized by modifying `http/sles15.xml`. See the [AutoYaST documentation](https://documentation.suse.com/sles/15-SP4/html/SLES-all/book-autoyast.html) for more information.
The deployment image may be customized by modifying `http/sles15.xml.pkrtpl.hcl`. See the [AutoYaST documentation](https://documentation.suse.com/sles/15/html/SLES-all/book-autoyast.html) for more information.

## Building the image using a proxy

The Packer template pulls all packages from the DVD ISO. To use a proxy during the installation you need to check the [AutoYaST documentation](https://documentation.suse.com/sles/15-SP4/html/SLES-all/book-autoyast.html).
The Packer template pulls all packages from the DVD ISO. To use a proxy during the installation you need to check the [AutoYaST documentation](https://documentation.suse.com/sles/15/html/SLES-all/book-autoyast.html).

## Building an image

You can easily build the image using the Makefile:

```shell
make ISO=/PATH/TO/SLE-15-SP4-Full-x86_64-GM-Media1.iso
make ISO=/PATH/TO/SLE-15-SP6-Full-x86_64-GM-Media1.iso ARCH=x86_64
```

Alternatively you can manually run packer. Your current working directory must
be in `packer-maas/sles15`, where this file is located. Once in packer-maas/sles15
you can generate an image with:
To build arm64 images:

```shell
packer init
PACKER_LOG=1 packer build -var 'sles15_iso_path=/PATH/TO/SLE-15-SP4-Full-x86_64-GM-Media1.iso' .
make ISO=/PATH/TO/SLE-15-SP6-Full-aarch64-GM-Media1.iso ARCH=aarch64
```

Note: `sles.pkr.hcl` is configured to run Packer in headless mode. Only Packer
Expand All @@ -50,6 +47,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 SLES.

#### TIMEOUT

The timeout to apply when building the image. The default value is set to 1h.
Expand All @@ -58,7 +63,7 @@ The timeout to apply when building the image. The default value is set to 1h.

```shell
maas $PROFILE boot-resources create \
name='suse/sles15.4' title='SLES 15-SP4' \
name='suse/sles15' title='SLES 15' \
architecture='amd64/generic' filetype='tgz' \
content@=sles15.tar.gz
```
Expand Down
9 changes: 5 additions & 4 deletions sles15/http/sles15.xml → sles15/http/sles15.xml.pkrtpl.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@
<os_prober>false</os_prober>
<timeout config:type="integer">8</timeout>
</global>
<loader_type>grub2</loader_type>
<loader_type>grub2-efi</loader_type>
</bootloader>
<firewall>
<enable_firewall config:type="boolean">false</enable_firewall>
<start_firewall config:type="boolean">false</start_firewall>
</firewall>
<general>
<ask-list config:type="list" />
<self_update config:type="boolean">false</self_update>
<mode>
<final_halt config:type="boolean">true</final_halt>
<halt config:type="boolean">true</halt>
<confirm config:type="boolean">false</confirm>
<second_stage config:type="boolean">false</second_stage>
</mode>
<proposals config:type="list" />
<signature-handling>
Expand Down Expand Up @@ -180,8 +182,7 @@
<package>tar</package>
<package>wget</package>
<package>xfsprogs</package>
<package>grub2-i386-pc</package>
<package>grub2-x86_64-efi</package>
${GRUB_PKGS}
<package>grub2-branding-SLE</package>
</packages>
<patterns config:type="list">
Expand Down
77 changes: 72 additions & 5 deletions sles15/sles.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
packer {
required_version = ">= 1.7.0"
required_version = ">= 1.11.0"
required_plugins {
qemu = {
version = "~> 1.0"
Expand All @@ -25,18 +25,85 @@ variable "timeout" {
description = "Timeout for building the image"
}

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

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

locals {
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"
}
grub_pkgs = {
"x86_64" = "<package>grub2-i386-pc</package><package>grub2-x86_64-efi</package>"
"aarch64" = "<package>grub2-arm64-efi</package>"
}
}

source "qemu" "sles15" {
boot_command = ["<esc><enter><wait>", "linux netdevice=eth0 netsetup=dhcp install=cd:/<wait>", " lang=en_US autoyast=http://{{ .HTTPIP }}:{{ .HTTPPort }}/sles15.xml<wait>", " textmode=1<wait>", "<enter><wait>"]
boot_wait = "3s"
boot_command = ["<esc>", "e", "<down><down><down><down>", "<end><wait>", "<spacebar>", "netdevice=eth0 vga=normal netsetup=dhcp install=cd:/ lang=en_US autoyast=http://{{ .HTTPIP }}:{{ .HTTPPort }}/sles15.xml textmode=1<wait>","<leftCtrlOn>x<leftCtrlOff>"]
boot_wait = "15s"
communicator = "none"
disk_size = "4G"
format = "qcow2"
headless = true
http_directory = "http"
iso_checksum = "none"
iso_url = var.sles15_iso_path
cdrom_interface = "virtio-scsi"
memory = 4096
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"],
["-device", "virtio-scsi-pci"],
["-netdev", "user,id=net0"],
["-device", "virtio-blk-pci,drive=drive0,bootindex=0"],
["-device", "scsi-cd,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-sles15/packer-sles15,if=none,id=drive0,cache=writeback,discard=ignore,format=qcow2"],
["-drive", "file=${var.sles15_iso_path},if=none,id=cdrom0,media=cdrom"]
]
shutdown_timeout = var.timeout
http_content = {
"/sles15.xml" = templatefile("${path.root}/http/sles15.xml.pkrtpl.hcl",
{
GRUB_PKGS = "${lookup(local.grub_pkgs, var.architecture, "")}"
}
)
}
}

build {
Expand Down

0 comments on commit b60e703

Please sign in to comment.