underpost 2.95.3 → 2.96.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +2 -2
  2. package/baremetal/commission-workflows.json +44 -0
  3. package/baremetal/packer-workflows.json +13 -0
  4. package/bin/deploy.js +6 -26
  5. package/cli.md +40 -43
  6. package/conf.js +4 -1
  7. package/examples/{QUICK-REFERENCE.md → static-page/QUICK-REFERENCE.md} +0 -18
  8. package/examples/{README.md → static-page/README.md} +3 -44
  9. package/examples/{STATIC-GENERATOR-GUIDE.md → static-page/STATIC-GENERATOR-GUIDE.md} +0 -50
  10. package/examples/{ssr-components → static-page/ssr-components}/CustomPage.js +0 -13
  11. package/examples/{static-config-simple.json → static-page/static-config-example.json} +1 -1
  12. package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
  13. package/manifests/deployment/dd-test-development/deployment.yaml +2 -2
  14. package/package.json +1 -1
  15. package/packer/images/Rocky9Amd64/Makefile +62 -0
  16. package/packer/images/Rocky9Amd64/QUICKSTART.md +113 -0
  17. package/packer/images/Rocky9Amd64/README.md +122 -0
  18. package/packer/images/Rocky9Amd64/http/rocky9.ks.pkrtpl.hcl +114 -0
  19. package/packer/images/Rocky9Amd64/rocky9.pkr.hcl +160 -0
  20. package/packer/scripts/fuse-nbd +64 -0
  21. package/packer/scripts/fuse-tar-root +63 -0
  22. package/scripts/maas-setup.sh +13 -2
  23. package/scripts/maas-upload-boot-resource.sh +183 -0
  24. package/scripts/packer-init-vars-file.sh +30 -0
  25. package/scripts/packer-setup.sh +52 -0
  26. package/src/cli/baremetal.js +262 -65
  27. package/src/cli/cloud-init.js +11 -5
  28. package/src/cli/cron.js +161 -29
  29. package/src/cli/db.js +59 -92
  30. package/src/cli/env.js +24 -3
  31. package/src/cli/index.js +18 -58
  32. package/src/cli/repository.js +178 -0
  33. package/src/cli/run.js +2 -3
  34. package/src/cli/static.js +99 -194
  35. package/src/client/services/default/default.management.js +7 -0
  36. package/src/index.js +1 -1
  37. package/src/server/backup.js +4 -53
  38. package/src/server/conf.js +3 -4
  39. package/examples/static-config-example.json +0 -183
  40. package/src/client/ssr/pages/404.js +0 -12
  41. package/src/client/ssr/pages/500.js +0 -12
  42. package/src/client/ssr/pages/maintenance.js +0 -14
  43. package/src/client/ssr/pages/offline.js +0 -21
@@ -0,0 +1,113 @@
1
+ # Quick Start Guide - Rocky9 MAAS Image Build
2
+
3
+ ## Prerequisites Check
4
+
5
+ Run these commands to verify your system is ready:
6
+
7
+ ```bash
8
+ # Check hardware virtualization
9
+ egrep -c '(vmx|svm)' /proc/cpuinfo # Should be > 0
10
+
11
+ # Check libvirt
12
+ systemctl status libvirtd
13
+
14
+ # Check QEMU
15
+ qemu-system-x86_64 --version
16
+
17
+ # Check Packer
18
+ packer version
19
+ ```
20
+
21
+ ## Build Commands
22
+
23
+ ```bash
24
+ # From the engine root directory
25
+ cd /home/dd/engine
26
+
27
+ # Option 1: Build and Upload (recommended)
28
+ node bin baremetal --dev --packer-workflow-id Rocky9Amd64 --packer-maas-image-build
29
+
30
+ # Option 2: Upload Only (skip rebuild, use existing artifact)
31
+ node bin baremetal --dev --packer-workflow-id Rocky9Amd64 --packer-maas-image-upload
32
+
33
+ # Option 3: Manual build
34
+ cd packer/images/Rocky9Amd64
35
+ packer init .
36
+ PACKER_LOG=1 packer build .
37
+ ```
38
+
39
+ ## Build Process Timeline
40
+
41
+ - **Download ISO**: ~5-10 minutes (1.3GB)
42
+ - **VM Installation**: ~20-40 minutes
43
+ - **Post-processing**: ~5-10 minutes
44
+ - **Total**: ~30-60 minutes
45
+
46
+ ## Output
47
+
48
+ The build produces:
49
+ - `rocky9.tar.gz` - The MAAS-ready image (~1.2GB)
50
+
51
+ ## Upload to MAAS
52
+
53
+ After successful build, upload happens automatically. To re-upload:
54
+
55
+ ```bash
56
+ # Option 1: Use the CLI (recommended, includes MAAS profile auto-detection)
57
+ node bin baremetal --dev --packer-workflow-id Rocky9Amd64 --packer-maas-image-upload
58
+
59
+ # Option 2: Use the upload script directly
60
+ ./scripts/maas-upload-boot-resource.sh maas \
61
+ custom/rocky9 \
62
+ "Rocky 9 Custom" \
63
+ amd64/generic \
64
+ rhel/9 \
65
+ tgz \
66
+ packer/images/Rocky9Amd64/rocky9.tar.gz
67
+ ```
68
+
69
+ ### Upload-Only Flag Benefits
70
+
71
+ The `--packer-maas-image-upload` flag allows you to:
72
+ - ⚡ **Skip rebuild** - Saves 30-60 minutes
73
+ - 💾 **Reuse artifacts** - Uses existing 1.2GB tarball
74
+ - 🔄 **Retry uploads** - Re-upload if upload failed
75
+ - 🎯 **Test uploads** - Upload to different MAAS instances
76
+
77
+ ## Common Issues
78
+
79
+ ### "No checksum found"
80
+ ✅ Fixed - ISO URL now uses Rocky-9-latest naming
81
+
82
+ ### "qemu-system-x86_64 not found"
83
+ ✅ Fixed - Symlink created to /usr/libexec/qemu-kvm
84
+
85
+ ### "OVMF_CODE.fd not found"
86
+ ✅ Fixed - OVMF symlinks created
87
+
88
+ ### Build hangs or times out
89
+ - Check system resources (RAM, CPU)
90
+ - Verify network connectivity
91
+ - Check logs: `packer_cache/` and console output
92
+
93
+ ## Monitoring Build Progress
94
+
95
+ Watch the Packer output for:
96
+ ```
97
+ ==> qemu.rocky9: Downloading ISO...
98
+ ==> qemu.rocky9: Starting HTTP server on port...
99
+ ==> qemu.rocky9: Starting VM...
100
+ ==> qemu.rocky9: Waiting for shutdown...
101
+ ==> qemu.rocky9: Converting image...
102
+ ```
103
+
104
+ ## Clean Up After Build
105
+
106
+ ```bash
107
+ # Remove build artifacts (keep only the tarball)
108
+ cd packer/images/Rocky9Amd64
109
+ rm -rf output-rocky9 packer_cache x86_64_VARS.fd
110
+
111
+ # Disconnect NBD devices if build failed
112
+ for i in {0..15}; do sudo qemu-nbd -d /dev/nbd${i} 2>/dev/null; done
113
+ ```
@@ -0,0 +1,122 @@
1
+ # Rocky 9 Packer template for MAAS
2
+
3
+ ## Introduction
4
+
5
+ The Packer template in this directory creates a Rocky 9 AMD64/ARM64 image for use with MAAS.
6
+
7
+ ## Prerequisites to create the image
8
+
9
+ * A machine running Ubuntu 22.04+ with the ability to run KVM virtual machines.
10
+ * qemu-utils, libnbd-bin, nbdkit and fuse2fs
11
+ * qemu-system
12
+ * qemu-system-modules-spice (If building on Ubuntu 24.04 LTS "Noble")
13
+ * ovmf
14
+ * cloud-image-utils
15
+ * parted
16
+ * [Packer.](https://www.packer.io/intro/getting-started/install.html), v1.11.0 or newer
17
+
18
+ ## Requirements to deploy the image
19
+
20
+ * [MAAS](https://maas.io) 3.3 or later, as that version introduces support for Rocky
21
+ * [Curtin](https://launchpad.net/curtin) 22.1. If you have a MAAS with an earlier Curtin version, you can [patch](https://code.launchpad.net/~xnox/curtin/+git/curtin/+merge/415604) distro.py to deploy Rocky.
22
+
23
+ ## Customizing the image
24
+
25
+ You can customize the deployment image by modifying http/rocky.ks. See the [RHEL kickstart documentation](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/performing_an_advanced_rhel_installation/kickstart-commands-and-options-reference_installing-rhel-as-an-experienced-user#part-or-partition_kickstart-commands-for-handling-storage) for more information.
26
+
27
+ ## Building the image using a proxy
28
+
29
+ The Packer template downloads the Rocky ISO image from the Internet. You can tell Packer to use a proxy by setting the HTTP_PROXY environment variable to point to your proxy server. You can also redefine rocky_iso_url to a local file. If you want to skip the base image integrity check, set iso_checksum_type to none and remove iso_checksum.
30
+
31
+ To use a proxy during the installation define the `KS_PROXY` variable in the environment, as bellow:
32
+
33
+ ```shell
34
+ export KS_PROXY="\"${HTTP_PROXY}\""
35
+ ```
36
+
37
+ # Building the image using a kickstart mirror
38
+
39
+ To tell Packer to use a specific mirror set the `KS_MIRROR` environment variable
40
+ poiniting to the mirror URL.
41
+
42
+ ```shell
43
+ export KS_MIRROR="https://dl.rockylinux.org/pub/rocky/9"
44
+ ```
45
+
46
+ ## Building an image
47
+
48
+ You can build the image using the Makefile:
49
+
50
+ ```shell
51
+ make
52
+ ```
53
+
54
+ You can also manually run packer. Set your current working directory to packer-maas/rocky9, where this file resides, and generate an image with:
55
+
56
+ ```shell
57
+ packer init
58
+ PACKER_LOG=1 packer build .
59
+ ```
60
+
61
+ The installation runs in a non-interactive mode.
62
+
63
+ Note: rocky9.pkr.hcl runs Packer in headless mode, with the serial port output from qemu redirected to stdio to give feedback on image creation process. If you wish to see more, change the value of `headless` to `false` in rocky9.pkr.hcl, remove `[ "-serial", "stdio" ]` from `qemuargs` section and select `View`, then `serial0` in the qemu window that appears during build. This lets you watch progress of the image build script. Press `ctrl-b 2` to switch to shell to explore more, and `ctrl-b 1` to go back to log view.
64
+
65
+ ### Makefile Parameters
66
+
67
+ #### ARCH
68
+
69
+ Defaults to x86_64 to build AMD64 compatible images. In order to build ARM64 images, use ARCH=aarch64
70
+
71
+ #### TIMEOUT
72
+
73
+ The timeout to apply when building the image. The default value is set to 1h.
74
+
75
+ ## Uploading an image to MAAS
76
+
77
+ ```shell
78
+ maas $PROFILE boot-resources create name='custom/rocky9' \
79
+ title='Rocky 9 Custom' architecture='amd64/generic' \
80
+ base_image='rhel/9' filetype='tgz' \
81
+ content@=rocky9.tar.gz
82
+ ```
83
+
84
+ For ARM64, use:
85
+
86
+ ```shell
87
+ maas $PROFILE boot-resources create name='custom/rocky9' \
88
+ title='Rocky 9 Custom' architecture='arm64/generic' \
89
+ base_image='rhel/9' filetype='tgz' \
90
+ content@=rocky9.tar.gz
91
+ ```
92
+
93
+ 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.
94
+
95
+ ```
96
+ #cloud-config
97
+ debconf_selections:
98
+ maas: |
99
+ {{for line in str(curtin_preseed).splitlines()}}
100
+ {{line}}
101
+ {{endfor}}
102
+
103
+ extract_commands:
104
+ grub_install: curtin in-target -- cp -v /boot/efi/EFI/rocky/shimaa64.efi /boot/efi/EFI/rocky/shimx64.efi
105
+
106
+ late_commands:
107
+ maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null']
108
+ bootloader_01: ["curtin", "in-target", "--", "cp", "-v", "/boot/efi/EFI/rocky/shimaa64.efi", "/boot/efi/EFI/BOOT/bootaa64.efi"]
109
+ bootloader_02: ["curtin", "in-target", "--", "cp", "-v", "/boot/efi/EFI/rocky/grubaa64.efi", "/boot/efi/EFI/BOOT/"]
110
+ ```
111
+
112
+ This file needs to be saved on Region Controllers under /var/snap/maas/current/preseeds/curtin_userdata_custom_arm64_generic_rocky9 or /etc/maas/preseeds/curtin_userdata_custom_arm64_generic_rocky9. The last portion of this file must match the image name uploaded in MAAS.
113
+
114
+ ## Default username
115
+
116
+ MAAS uses cloud-init to create ```cloud-user``` account using the ssh keys configured for the MAAS admin user (e.g. imported from Launchpad). Log in to the machine:
117
+
118
+ ```shell
119
+ ssh -i ~/.ssh/<your_identity_file> cloud-user@<machine-ip-address>
120
+ ```
121
+
122
+ Next to that, the kickstart script creates an account with both username and password set to ```rocky```. Note that the default sshd configuration in Rocky 9 disallows password-based authentication when logging in via ssh, so trying `ssh rocky@<machine-ip-address>` will fail. Password-based authentication can be enabled by having `PasswordAuthentication yes` in /etc/ssh/sshd_config after logging in with ```cloud-user```. Perhaps there is a way to make that change using kickstart script, but it is not obvious as ```anaconda```, the installer, makes its own changes to sshd_config file during installation. If you know how to do this, a PR is welcome.
@@ -0,0 +1,114 @@
1
+ url ${KS_OS_REPOS} ${KS_PROXY}
2
+ repo --name="AppStream" ${KS_APPSTREAM_REPOS} ${KS_PROXY}
3
+ repo --name="Extras" ${KS_EXTRAS_REPOS} ${KS_PROXY}
4
+
5
+ eula --agreed
6
+
7
+ # Turn off after installation
8
+ poweroff
9
+
10
+ # Do not start the Inital Setup app
11
+ firstboot --disable
12
+
13
+ # System language, keyboard and timezone
14
+ lang en_US.UTF-8
15
+ keyboard us
16
+ timezone UTC --utc
17
+
18
+ # Set the first NIC to acquire IPv4 address via DHCP
19
+ network --device eth0 --bootproto=dhcp
20
+ # Enable firewal, let SSH through
21
+ firewall --enabled --service=ssh
22
+ # Enable SELinux with default enforcing policy
23
+ selinux --enforcing
24
+
25
+ # Do not set up XX Window System
26
+ skipx
27
+
28
+ # Initial disk setup
29
+ # Use the first paravirtualized disk
30
+ ignoredisk --only-use=vda
31
+ # No need for bootloader
32
+ bootloader --disabled
33
+ # Wipe invalid partition tables
34
+ zerombr
35
+ # Erase all partitions and assign default labels
36
+ clearpart --all --initlabel
37
+ # Initialize the primary root partition with ext4 filesystem
38
+ part / --size=1 --grow --asprimary --fstype=ext4
39
+
40
+ # Set root password
41
+ rootpw --plaintext password
42
+
43
+ # Add a user named packer
44
+ user --groups=wheel --name=rocky --password=rocky --plaintext --gecos="rocky"
45
+
46
+ %post --erroronfail
47
+ # workaround anaconda requirements and clear root password
48
+ passwd -d root
49
+ passwd -l root
50
+
51
+ # Clean up install config not applicable to deployed environments.
52
+ for f in resolv.conf fstab; do
53
+ rm -f /etc/$f
54
+ touch /etc/$f
55
+ chown root:root /etc/$f
56
+ chmod 644 /etc/$f
57
+ done
58
+
59
+ rm -f /etc/sysconfig/network-scripts/ifcfg-[^lo]*
60
+
61
+ # Kickstart copies install boot options. Serial is turned on for logging with
62
+ # Packer which disables console output. Disable it so console output is shown
63
+ # during deployments
64
+ sed -i 's/^GRUB_TERMINAL=.*/GRUB_TERMINAL_OUTPUT="console"/g' /etc/default/grub
65
+ sed -i '/GRUB_SERIAL_COMMAND="serial"/d' /etc/default/grub
66
+ sed -ri 's/(GRUB_CMDLINE_LINUX=".*)\s+console=ttyS0(.*")/\1\2/' /etc/default/grub
67
+ sed -i 's/GRUB_ENABLE_BLSCFG=.*/GRUB_ENABLE_BLSCFG=false/g' /etc/default/grub
68
+
69
+ dnf clean all
70
+
71
+ # Passwordless sudo for the user 'rocky'
72
+ echo "rocky ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/rocky
73
+ chmod 440 /etc/sudoers.d/rocky
74
+
75
+ #---- Optional - Install your SSH key ----
76
+ # mkdir -m0700 /home/rocky/.ssh/
77
+ #
78
+ # cat <<EOF >/home/rocky/.ssh/authorized_keys
79
+ # ssh-rsa <your_public_key_here> you@your.domain
80
+ # EOF
81
+ #
82
+ ### set permissions
83
+ # chmod 0600 /home/rocky/.ssh/authorized_keys
84
+ #
85
+ #### fix up selinux context
86
+ # restorecon -R /home/rocky/.ssh/
87
+
88
+ %end
89
+
90
+ %packages --ignoremissing
91
+ @core
92
+ bash-completion
93
+ cloud-init
94
+ cloud-utils-growpart
95
+ rsync
96
+ tar
97
+ patch
98
+ yum-utils
99
+ grub2-pc
100
+ grub2-efi-*
101
+ shim-*
102
+ grub2-efi-*-modules
103
+ efibootmgr
104
+ dosfstools
105
+ lvm2
106
+ mdadm
107
+ device-mapper-multipath
108
+ iscsi-initiator-utils
109
+ -plymouth
110
+ # Remove ALSA firmware
111
+ -a*-firmware
112
+ # Remove Intel wireless firmware
113
+ -i*-firmware
114
+ %end
@@ -0,0 +1,160 @@
1
+ packer {
2
+ required_version = ">= 1.11.0"
3
+ required_plugins {
4
+ qemu = {
5
+ version = ">= 1.1.0, < 1.1.2"
6
+ source = "github.com/hashicorp/qemu"
7
+ }
8
+ }
9
+ }
10
+
11
+ variable "filename" {
12
+ type = string
13
+ default = "rocky9.tar.gz"
14
+ description = "The filename of the tarball to produce"
15
+ }
16
+
17
+ variable ks_proxy {
18
+ type = string
19
+ default = "${env("KS_PROXY")}"
20
+ }
21
+
22
+ variable ks_mirror {
23
+ type = string
24
+ default = "${env("KS_MIRROR")}"
25
+ }
26
+
27
+ variable "timeout" {
28
+ type = string
29
+ default = "1h"
30
+ description = "Timeout for building the image"
31
+ }
32
+
33
+ variable "architecture" {
34
+ type = string
35
+ default = "amd64"
36
+ description = "The architecture to build the image for (amd64 or arm64)"
37
+ }
38
+
39
+ variable "host_is_arm" {
40
+ type = bool
41
+ default = false
42
+ description = "The host architecture is aarch64"
43
+ }
44
+
45
+ variable "ovmf_suffix" {
46
+ type = string
47
+ default = ""
48
+ description = "Suffix for OVMF CODE and VARS files. Newer systems such as Noble use _4M."
49
+ }
50
+
51
+ variable "headless" {
52
+ type = bool
53
+ default = true
54
+ description = "Run packer in headless mode"
55
+ }
56
+
57
+ locals {
58
+ iso_arch_map = {
59
+ "amd64" = "x86_64"
60
+ "x86_64" = "x86_64"
61
+ "arm64" = "aarch64"
62
+ "aarch64" = "aarch64"
63
+ }
64
+ iso_arch = lookup(local.iso_arch_map, var.architecture, "x86_64")
65
+
66
+ qemu_arch = {
67
+ "amd64" = "x86_64"
68
+ "x86_64" = "x86_64"
69
+ "arm64" = "aarch64"
70
+ "aarch64" = "aarch64"
71
+ }
72
+ uefi_imp = {
73
+ "amd64" = "OVMF"
74
+ "x86_64" = "OVMF"
75
+ "arm64" = "AAVMF"
76
+ "aarch64" = "AAVMF"
77
+ }
78
+ uefi_sfx = {
79
+ "amd64" = "${var.ovmf_suffix}"
80
+ "x86_64" = "${var.ovmf_suffix}"
81
+ "arm64" = ""
82
+ "aarch64" = ""
83
+ }
84
+ qemu_machine = {
85
+ "amd64" = "accel=kvm"
86
+ "x86_64" = "accel=kvm"
87
+ "arm64" = var.host_is_arm ? "virt,accel=kvm" : "virt"
88
+ "aarch64" = var.host_is_arm ? "virt,accel=kvm" : "virt"
89
+ }
90
+ qemu_cpu = {
91
+ "amd64" = "host"
92
+ "x86_64" = "host"
93
+ "arm64" = var.host_is_arm ? "host" : "max"
94
+ "aarch64" = var.host_is_arm ? "host" : "max"
95
+ }
96
+
97
+ ks_proxy = var.ks_proxy != "" ? "--proxy=${var.ks_proxy}" : ""
98
+ ks_os_repos = var.ks_mirror != "" ? "--url=${var.ks_mirror}/BaseOS/${local.iso_arch}/os" : "--mirrorlist='http://mirrors.rockylinux.org/mirrorlist?arch=${local.iso_arch}&repo=BaseOS-9'"
99
+ ks_appstream_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/AppStream/${local.iso_arch}/os" : "--mirrorlist='https://mirrors.rockylinux.org/mirrorlist?release=9&arch=${local.iso_arch}&repo=AppStream-9'"
100
+ ks_extras_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/extras/${local.iso_arch}/os" : "--mirrorlist='https://mirrors.rockylinux.org/mirrorlist?arch=${local.iso_arch}&repo=extras-9'"
101
+ }
102
+
103
+ source "qemu" "rocky9" {
104
+ boot_command = ["<up><wait>", "e", "<down><down><down><left>", " console=ttyS0 inst.cmdline inst.text inst.ks=http://{{.HTTPIP}}:{{.HTTPPort}}/rocky9.ks <f10>"]
105
+ boot_wait = "5s"
106
+ communicator = "none"
107
+ disk_size = "45G"
108
+ format = "qcow2"
109
+ headless = var.headless
110
+ iso_checksum = "file:http://download.rockylinux.org/pub/rocky/9/isos/${local.iso_arch}/CHECKSUM"
111
+ iso_url = "http://download.rockylinux.org/pub/rocky/9/isos/${local.iso_arch}/Rocky-9-latest-${local.iso_arch}-boot.iso"
112
+ iso_target_path = "packer_cache/Rocky-9-latest-${local.iso_arch}-boot.iso"
113
+ memory = 2048
114
+ cores = 4
115
+ qemu_binary = "qemu-system-${lookup(local.qemu_arch, var.architecture, "")}"
116
+ qemuargs = [
117
+ ["-serial", "stdio"],
118
+ ["-boot", "strict=off"],
119
+ ["-device", "qemu-xhci"],
120
+ ["-device", "usb-kbd"],
121
+ ["-device", "virtio-net-pci,netdev=net0"],
122
+ ["-netdev", "user,id=net0"],
123
+ ["-device", "virtio-blk-pci,drive=drive0,bootindex=0"],
124
+ ["-device", "virtio-blk-pci,drive=cdrom0,bootindex=1"],
125
+ ["-machine", "${lookup(local.qemu_machine, var.architecture, "")}"],
126
+ ["-cpu", "${lookup(local.qemu_cpu, var.architecture, "")}"],
127
+ ["-device", "virtio-gpu-pci"],
128
+ ["-global", "driver=cfi.pflash01,property=secure,value=off"],
129
+ ["-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"],
130
+ ["-drive", "if=pflash,format=raw,unit=1,id=ovmf_vars,file=${local.iso_arch}_VARS.fd"],
131
+ ["-drive", "file=output-rocky9/packer-rocky9,if=none,id=drive0,cache=writeback,discard=ignore,format=qcow2"],
132
+ ["-drive", "file=packer_cache/Rocky-9-latest-${local.iso_arch}-boot.iso,if=none,id=cdrom0,media=cdrom"]
133
+ ]
134
+ shutdown_timeout = var.timeout
135
+ http_content = {
136
+ "/rocky9.ks" = templatefile("${path.root}/http/rocky9.ks.pkrtpl.hcl",
137
+ {
138
+ KS_PROXY = local.ks_proxy,
139
+ KS_OS_REPOS = local.ks_os_repos,
140
+ KS_APPSTREAM_REPOS = local.ks_appstream_repos,
141
+ KS_EXTRAS_REPOS = local.ks_extras_repos
142
+ }
143
+ )
144
+ }
145
+ }
146
+
147
+ build {
148
+ sources = ["source.qemu.rocky9"]
149
+
150
+ post-processor "shell-local" {
151
+ inline = [
152
+ "SOURCE=${source.name}",
153
+ "OUTPUT=${var.filename}",
154
+ "source ../../scripts/fuse-nbd",
155
+ "source ../../scripts/fuse-tar-root",
156
+ "rm -rf output-${source.name}",
157
+ ]
158
+ inline_shebang = "/bin/bash -e"
159
+ }
160
+ }
@@ -0,0 +1,64 @@
1
+ #!/bin/bash -e
2
+ # vi: ts=4 expandtab
3
+ #
4
+ # Script to mount a qcow2 image using NBD (Network Block Device)
5
+ # This is part of the MAAS image build process
6
+
7
+ OUTPUT_DIR="output-${SOURCE}"
8
+ OUTPUT_QCOW2="${OUTPUT_DIR}/packer-${SOURCE}"
9
+
10
+ if [ ! -f "${OUTPUT_QCOW2}" ]; then
11
+ echo "ERROR: ${OUTPUT_QCOW2} not found"
12
+ exit 1
13
+ fi
14
+
15
+ # Load NBD kernel module if not already loaded
16
+ if ! lsmod | grep -q nbd; then
17
+ modprobe nbd
18
+ fi
19
+
20
+ # Find an available NBD device
21
+ for i in {0..15}; do
22
+ if [ ! -e "/sys/class/block/nbd${i}/pid" ]; then
23
+ NBD_DEV="/dev/nbd${i}"
24
+ break
25
+ fi
26
+ done
27
+
28
+ if [ -z "${NBD_DEV}" ]; then
29
+ echo "ERROR: No available NBD devices found"
30
+ exit 1
31
+ fi
32
+
33
+ # Connect the QCOW2 image to the NBD device
34
+ qemu-nbd -c "${NBD_DEV}" -f qcow2 -r "${OUTPUT_QCOW2}"
35
+
36
+ # Wait for the device to be ready
37
+ sleep 2
38
+ udevadm settle
39
+
40
+ # Find the root partition (usually the largest partition)
41
+ ROOT_PART=""
42
+ MAX_SIZE=0
43
+
44
+ for part in "${NBD_DEV}"p*; do
45
+ if [ -b "${part}" ]; then
46
+ SIZE=$(blockdev --getsize64 "${part}" 2>/dev/null || echo 0)
47
+ if [ "${SIZE}" -gt "${MAX_SIZE}" ]; then
48
+ MAX_SIZE=${SIZE}
49
+ ROOT_PART="${part}"
50
+ fi
51
+ fi
52
+ done
53
+
54
+ if [ -z "${ROOT_PART}" ]; then
55
+ # If no partitions found, try the whole device
56
+ ROOT_PART="${NBD_DEV}"
57
+ fi
58
+
59
+ echo "Using NBD device: ${NBD_DEV}"
60
+ echo "Root partition: ${ROOT_PART}"
61
+
62
+ # Export variables for use in subsequent scripts
63
+ export NBD_DEV
64
+ export ROOT_PART
@@ -0,0 +1,63 @@
1
+ #!/bin/bash -e
2
+ # vi: ts=4 expandtab
3
+ #
4
+ # Script to extract root filesystem from NBD device to tarball for MAAS
5
+ # This is part of the MAAS image build process
6
+
7
+ if [ -z "${NBD_DEV}" ]; then
8
+ echo "ERROR: NBD_DEV not set. Run fuse-nbd first."
9
+ exit 1
10
+ fi
11
+
12
+ if [ -z "${ROOT_PART}" ]; then
13
+ echo "ERROR: ROOT_PART not set. Run fuse-nbd first."
14
+ exit 1
15
+ fi
16
+
17
+ if [ -z "${OUTPUT}" ]; then
18
+ echo "ERROR: OUTPUT not set."
19
+ exit 1
20
+ fi
21
+
22
+ # Create temporary mount point
23
+ MOUNT_POINT=$(mktemp -d /tmp/packer-maas-mount.XXXXXX)
24
+
25
+ cleanup() {
26
+ echo "Cleaning up..."
27
+ if mountpoint -q "${MOUNT_POINT}"; then
28
+ umount "${MOUNT_POINT}" || true
29
+ fi
30
+ if [ -n "${NBD_DEV}" ] && [ -b "${NBD_DEV}" ]; then
31
+ qemu-nbd -d "${NBD_DEV}" || true
32
+ fi
33
+ if [ -d "${MOUNT_POINT}" ]; then
34
+ rmdir "${MOUNT_POINT}" || true
35
+ fi
36
+ }
37
+
38
+ trap cleanup EXIT
39
+
40
+ # Mount the root partition
41
+ echo "Mounting ${ROOT_PART} to ${MOUNT_POINT}..."
42
+ mount -o ro "${ROOT_PART}" "${MOUNT_POINT}"
43
+
44
+ # Create tarball from the mounted filesystem
45
+ echo "Creating tarball ${OUTPUT}..."
46
+ tar -czf "${OUTPUT}" -C "${MOUNT_POINT}" \
47
+ --exclude='./dev/*' \
48
+ --exclude='./proc/*' \
49
+ --exclude='./sys/*' \
50
+ --exclude='./tmp/*' \
51
+ --exclude='./run/*' \
52
+ --exclude='./mnt/*' \
53
+ --exclude='./media/*' \
54
+ --exclude='./lost+found' \
55
+ --exclude='./boot/efi/*' \
56
+ --numeric-owner \
57
+ .
58
+
59
+ echo "Tarball created successfully: ${OUTPUT}"
60
+ echo "Size: $(du -h "${OUTPUT}" | cut -f1)"
61
+
62
+ # Cleanup will be called by trap
63
+ exit 0
@@ -99,7 +99,18 @@ echo "Configuring DHCP for fabric-1 (untagged VLAN)..."
99
99
  SUBNET_CIDR="192.168.1.0/24"
100
100
  SUBNET_ID=$(maas "$MAAS_ADMIN_USERNAME" subnets read | jq -r '.[] | select(.cidr == "'"$SUBNET_CIDR"'") | .id')
101
101
  FABRIC_ID=$(maas "$MAAS_ADMIN_USERNAME" fabrics read | jq -r '.[] | select(.name == "fabric-1") | .id')
102
- RACK_CONTROLLER_ID=$(maas "$MAAS_ADMIN_USERNAME" rack-controllers read | jq -r '.[] | select(.ip_addresses[] == "'"$IP_ADDRESS"'") | .system_id')
102
+ RACK_CONTROLLER_ID=$(maas "$MAAS_ADMIN_USERNAME" rack-controllers read | jq -r '[.[] | select(.ip_addresses[] == "'"$IP_ADDRESS"'") | .system_id] | .[0]')
103
+
104
+ if [ -z "$RACK_CONTROLLER_ID" ] || [ "$RACK_CONTROLLER_ID" == "null" ]; then
105
+ echo "Warning: Could not find Rack Controller by IP $IP_ADDRESS. Attempting to use the first available Rack Controller..."
106
+ RACK_CONTROLLER_ID=$(maas "$MAAS_ADMIN_USERNAME" rack-controllers read | jq -r '.[0].system_id')
107
+ fi
108
+
109
+ if [ -z "$RACK_CONTROLLER_ID" ] || [ "$RACK_CONTROLLER_ID" == "null" ]; then
110
+ echo "Error: Could not find any Rack Controller."
111
+ exit 1
112
+ fi
113
+
103
114
  START_IP="192.168.1.191"
104
115
  END_IP="192.168.1.254"
105
116
 
@@ -110,7 +121,7 @@ fi
110
121
 
111
122
  # Create a Dynamic IP Range for enlistment, commissioning, and deployment
112
123
  echo "Creating dynamic IP range from $START_IP to $END_IP..."
113
- maas "$MAAS_ADMIN_USERNAME" ipranges create type=dynamic start_ip="$START_IP" end_ip="$END_IP"
124
+ maas "$MAAS_ADMIN_USERNAME" ipranges create type=dynamic start_ip="$START_IP" end_ip="$END_IP" || echo "Dynamic IP range likely already exists or conflicts. Proceeding..."
114
125
 
115
126
  # Enable DHCP on the untagged VLAN (VLAN tag 0)
116
127
  echo "Enabling DHCP on VLAN 0 for fabric-1 (ID: $FABRIC_ID)..."