MAAS custom image

From UNamur InfoSec
Jump to navigation Jump to search

How to manually build custom MAAS image for Raspberry Pi

MAAS supports multiple ways of building a custom image for deployment. We can use the official MAAS Image builder application [1], MAAS packer templates [2]. However, MAAS Image builder applications require the user to be subscribed to Ubuntu Advantage to download, and MAAS packer repository only provides AMD64 architecture templates at the moment.

Luckily, MAAS also supports tgz image type (tar and gunzip format), thus, it is possible for us to manually build a custom ARM64 image from Ubuntu cloud image file.

How to build custom ARM64 image

  • Download Ubuntu cloud image file

We will use the Ubuntu 21.10 ARM64 root tar xz file. We can download it from this link [3].

wget https://cloud-images.ubuntu.com/impish/current/impish-server-cloudimg-arm64-root.tar.xz
  • Extract or mount the image file

We can extract the tar.xz file with the following command, we use the “-p” option to preserve the file permission.

mkdir impish_arm64_root
sudo tar -xpf impish-server-cloudimg-arm64-root.tar.xz -C impish_arm64_root

Chroot and install custom packages We use chroot to change the current root directory in order to install packages to our custom image, we mount /run to fix DNS issues.

sudo mount -o bind /run impish_arm64_root/run
sudo chroot impish_arm64_root
apt-get install xxx # install any package
  • Archive and compress the image file

After we made changes, we can exit chroot and archive the image file from it.

exit
sudo umount impish_arm64_root/run
sudo tar -cpzf custom_impish_arm64.tgz -C impish_arm64_root/ .
  • Upload to MAAS with MAAS-cli

After we have archived the image file, we can use MAAS-cli to login and upload the image to the MAAS server. We can get the api_key from the settings page of MAAS web UI.

maas login admin http://localhost:5240/MAAS/api/2.0 <api_key> 
maas admin boot-resources create name='custom/custom_impish_arm64' title='custom_imish_arm64' architecture='arm64/generic' base_image=ubuntu/focal filetype='tgz' content@=custom_impish_arm64.tgz

References:

[1] https://maas.io/docs/image-builder

[2] https://github.com/canonical/packer-maas

[3] https://cloud-images.ubuntu.com/impish/current/impish-server-cloudimg-arm64-root.tar.xz