Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debian: Added support for versions 10, 11 and 12 #162

Merged
merged 22 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
19b3e63
Add a make example to build cloudimg based images.
alanbach Nov 9, 2023
c9711b2
Increase the base disk size from 4G to 6G
alanbach Nov 9, 2023
4feb7fe
Revert previous commit.
alanbach Nov 9, 2023
1139a1c
Increase the base disk size from 4G to 6G
alanbach Nov 9, 2023
f91a642
Some minor housekeeping, updated copyright
alanbach Nov 10, 2023
322c205
Added experimental support for Debian
alanbach Nov 13, 2023
c4555f3
More clean-ups related to Debian support implementation.
alanbach Nov 14, 2023
e93a142
Sync ubuntu/README.md with ustream.
alanbach Nov 14, 2023
e3dd09a
Merge branch 'canonical:main' into PR-24
alanbach Nov 20, 2023
a26a952
Reflect the correct tar.gz name in clean.
alanbach Nov 20, 2023
4933cc5
Removed unused debian/scripts/curtin-hooks
alanbach Nov 20, 2023
fd0c03f
Moved scripts out of debian/scripts/cloudimg to
alanbach Nov 20, 2023
1562011
Fixed a typo in README.md
alanbach Nov 20, 2023
1999430
Added a note to work around potential preseed file
alanbach Nov 20, 2023
fce56f5
Removed packages/ as it is not being used. Refer to
alanbach Nov 20, 2023
c73c803
Convert base64 script creation into human readable.
alanbach Nov 20, 2023
0a0cd67
Dynamically calculate target architecture during runtime.
alanbach Nov 20, 2023
319fc01
Added essential-packages.sh to cover anything
alanbach Nov 20, 2023
8e2db9d
Actually remove packages/ directory.
alanbach Nov 20, 2023
dae2cc6
Completed implementing arm64 support.
alanbach Nov 20, 2023
ce54e58
Deleted obsolete curtin_userdata_custom
alanbach Nov 21, 2023
2809adf
Updated root README.md to include Debian templates.
alanbach Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Read more about how [custom images](https://maas.io/docs/how-to-customise-images
| CentOS 7 | Stable | >= 2.3 |
| CentOS 8 | EOL | >= 2.7 |
| CentOS 8 Stream | Beta | >= 3.2 |
| Debian 10 | Beta | >= 3.3 |
| Debian 11 | Beta | >= 3.3 |
| Debian 12 | Beta | >= 3.3 |
| OL8 | Beta | >= 3.5 |
| OL9 | Beta | >= 3.5 |
| RHEL 7 | EOL | >= 2.3 |
Expand Down
67 changes: 67 additions & 0 deletions debian/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/make -f

include ../scripts/check.mk

PACKER ?= packer
PACKER_LOG ?= 0
export PACKER_LOG

SERIES ?= bullseye
BOOT ?= uefi
ARCH ?= amd64

ifeq ($(strip $(SERIES)),buster)
VERSION = 10
else ifeq ($(strip $(SERIES)),bullseye)
VERSION = 11
else ifeq ($(strip $(SERIES)),bookworm)
VERSION = 12
else
VERSION = 11
endif

# Safeguard
ifeq ($(strip $(ARCH)),arm64)
boot = uefi
endif

.PHONY: all clean

all: debian

$(eval $(call check_packages_deps,cloud-image-utils ovmf,cloud-image-utils ovmf))

lint:
packer validate .
packer fmt -check -diff .

format:
packer fmt .

OVMF_VARS.fd: /usr/share/OVMF/OVMF_VARS.fd
cp -v $< $@

debian: check-deps clean
${PACKER} init . && ${PACKER} build \
-var debian_series=${SERIES} \
-var debian_version=${VERSION} \
-var architecture=${ARCH} \
-var boot_mode=${BOOT} .

clean:
${RM} -rf output-* debian-custom-*.gz \
seeds-cloudimg.iso \
OVMF_VARS.fd \
AAVMF_VARS.fd

CUSTOM_PKGS:=${wildcard packages/*.deb}

packages/custom-packages.tar.gz: ${CUSTOM_PKGS}
ifeq ($(strip $(CUSTOM_PKGS)),)
tar czf $@ -C packages -T /dev/null
else
tar czf $@ -C packages ${notdir $^}
endif

.INTERMEDIATE: OVMF_VARS.fd packages/custom-packages.tar.gz \
seeds-cloudimg.iso
147 changes: 147 additions & 0 deletions debian/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Debian Packer Templates for MAAS

## Introduction

The Packer templates in this directory creates Debian images for use with MAAS.

## Prerequisites (to create the image)

* A machine running Ubuntu 18.04+ with the ability to run KVM virtual machines.
* qemu-utils, libnbd-bin, nbdkit and fuse2fs
* qemu-system
* ovmf
* cloud-image-utils
* [Packer](https://www.packer.io/intro/getting-started/install.html), v1.7.0 or newer

## Requirements (to deploy the image)

* [MAAS](https://maas.io) 3.2+
* [Curtin](https://launchpad.net/curtin) 21.0+
* [A Custom Preseed for Debian (Important - See below)]

## Supported Debian Versions

The builds and deployment has been tested on MAAS 3.3.5 with Jammy ephemeral images,
in BIOS and UEFI modes. The process currently works with the following Debian series:

* Debian 10 (Buster)
* Debian 11 (Bullseye)
* Debian 12 (Bookworm)

## Supported Architectures

Currently amd64 (x86_64) and arm64 (aarch64) architectures are supported with aemd64
being the default.

## Known Issues

* UEFI images fro Debian 10 (Buster) and 11 (Bullseye) are usable on both BIOS and
UEFI systems. However for Debian 12 (Bookworm) explicit images are required to
support BIOS and UEFI modes. See BOOT make parameter for more details.


## debian-cloudimg.pkr.hcl

This template builds a tgz image from the official Debian cloud images. This
results in an image that is very close to the ones that are on
<https://images.maas.io/>.

### Building the image

The build the image you give the template a script which has all the
customizations:

```shell
packer init .
packer build -var customize_script=my-changes.sh -var debian_series=bullseye \
-var debian_version=11 .
```

`my-changes.sh` is a script you write which customizes the image from within
the VM. For example, you can install packages using `apt-get`, call out to
ansible, or whatever you want.

Using make:

```shell
make debian SERIES=bullseye
```

#### Accessing external files from you script

If you want to put or use some files in the image, you can put those in the `http` directory.

Whatever file you put there, you can access from within your script like this:

```shell
wget http://${PACKER_HTTP_IP}:${PACKER_HTTP_PORT}:/my-file
```

### Installing a kernel

If you do want to force an image to always use a specific kernel, you can
include it in the image.

The easiest way of doing this is to use the `kernel` parameter:

```shell
packer init .
packer build -var kernel=linux-image-amd64 -var customize_script=my-changes.sh .
```

You can also install the kernel manually in your `my-changes.sh` script.

### Custom Preseed for Debian

As mentioned above, Debian images require a custom preseed file to be present in the
preseeds directory of MAAS region controllers.

When used snaps, the path is /var/snap/maas/current/preseeds/curtin_userdata_custom

Example ready to use preesed files has been included with this repository. Please
see curtin_userdata_custom_amd64 and curtin_userdata_custom_arm64.

Please be aware that this could potentially create a conflict with the rest of custom
images present in your setup, hence a through investigation and testing might be
required prior to deployment.

To work around a conflict, it is possible to name the preseed file something similar to
curtin_userdata_custom_amd64_generic_debian-10 assuming the architecture was set to
amd64/generic and the uploaded name was set to custom/debian-10.

### Makefile Parameters

#### PACKER_LOG

Enable (1) or Disable (0) verbose packer logs. The default value is set to 0.

#### SERIES

Specify the Debian Series to build. The default value is set to bullseye.

#### BOOT

Supported boot mode baked into the image. The default is set to uefi. Please
see the Known Issues section for more details. This parameter is only valid
for amd64 architecture.

#### ARCH

Target image architecture. Supported values are amd64 (default) and arm64.

### Default Username

The default username is ```debian```

## Uploading images to MAAS

TGZ image

```shell
maas admin boot-resources create \
name='custom/debian-12' \
title='Debian 12 Custom' \
architecture='amd64/generic' \
filetype='tgz' \
content@=debian-custom-cloudimg.tar.gz
```
24 changes: 24 additions & 0 deletions debian/curtin_userdata_custom_amd64
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#cloud-config
kernel:
fallback-package: linux-image-amd64
package: linux-image-amd64

apt:
preserve_sources_list: true

debconf_selections:
maas: |
{{for line in str(curtin_preseed).splitlines()}}
{{line}}
{{endfor}}

late_commands:
maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null']
late_1: mount --bind $TARGET_MOUNT_POINT /mnt
late_2: grep -A2 datasource /etc/cloud/cloud.cfg.d/91_kernel_cmdline_url.cfg | sed 's/curtin//' | tee /mnt/etc/cloud/cloud.cfg.d/debian.cfg
late_3: sed -i '[email protected]/[email protected]/debian@g;s@archive@deb@g;s@ubuntu@debian@g;s@Ubuntu@Debian@g;' /mnt/etc/cloud/cloud.cfg
late_4: debver=$(cat /mnt/etc/debian_version | awk -F. '{print $1}'); if [ ${debver} -eq 10 ]; then rel="buster"; elif [ ${debver} -eq 11 ]; then rel="bullseye"; elif [ ${debver} -eq 12 ]; then rel="bookworm"; fi; sed -i s/stable/${rel}/g /mnt/etc/apt/sources.list;
late_5: sed -i '/^set -e/{n;N;d}' /mnt/etc/kernel/postinst.d/zz-update-grub
late_6: rm -f /usr/local/bin/dpkg-query
late_7: rm -f /usr/local/bin/netplan

24 changes: 24 additions & 0 deletions debian/curtin_userdata_custom_arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#cloud-config
kernel:
fallback-package: linux-image-arm64
package: linux-image-arm64

apt:
preserve_sources_list: true

debconf_selections:
maas: |
{{for line in str(curtin_preseed).splitlines()}}
{{line}}
{{endfor}}

late_commands:
maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null']
late_1: mount --bind $TARGET_MOUNT_POINT /mnt
late_2: grep -A2 datasource /etc/cloud/cloud.cfg.d/91_kernel_cmdline_url.cfg | sed 's/curtin//' | tee /mnt/etc/cloud/cloud.cfg.d/debian.cfg
late_3: sed -i '[email protected]/[email protected]/debian@g;s@archive@deb@g;s@ubuntu@debian@g;s@Ubuntu@Debian@g;' /mnt/etc/cloud/cloud.cfg
late_4: debver=$(cat /mnt/etc/debian_version | awk -F. '{print $1}'); if [ ${debver} -eq 10 ]; then rel="buster"; elif [ ${debver} -eq 11 ]; then rel="bullseye"; elif [ ${debver} -eq 12 ]; then rel="bookworm"; fi; sed -i s/stable/${rel}/g /mnt/etc/apt/sources.list;
late_5: sed -i '/^set -e/{n;N;d}' /mnt/etc/kernel/postinst.d/zz-update-grub
late_6: rm -f /usr/local/bin/dpkg-query
late_7: rm -f /usr/local/bin/netplan

Loading