diff --git a/rhel9/Makefile b/rhel9/Makefile index 2173dc79..b481bc1d 100644 --- a/rhel9/Makefile +++ b/rhel9/Makefile @@ -10,7 +10,11 @@ export PACKER_LOG KS_PROXY all: rhel9.tar.gz check-deps: - dpkg -s libnbd-bin nbdkit packer fuse2fs > /dev/null + @if [ $(shell lsb_release -sr|cut -d. -f1) -le 20 ];then \ + dpkg -s libnbd0 nbdkit packer fuse2fs > /dev/null; \ + elif [ $(shell lsb_release -sr|cut -d. -f1) -gt 20 ];then \ + dpkg -s libnbd-bin nbdkit packer fuse2fs > /dev/null; \ + fi rhel9.tar.gz: check-deps clean http/rhel9.ks ${SUDO} ${PACKER} init rhel9.pkr.hcl && ${SUDO} ${PACKER} build -var "rhel9_iso_path=${ISO}" rhel9.pkr.hcl diff --git a/rhel9/README.md b/rhel9/README.md index 0a837b54..2cc7b1bb 100644 --- a/rhel9/README.md +++ b/rhel9/README.md @@ -8,7 +8,14 @@ The Packer template in this directory creates a RHEL 9 AMD64 image for use with * 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 +* packer - from Hashicorp repository, v1.9.0 or newer + +```shell +wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/hashicorp-archive-keyring.gpg +echo "deb [signed-by=/etc/apt/trusted.gpg.d/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list +sudo apt update && sudo apt install packer +``` + * The [RHEL 9 DVD ISO](https://developers.redhat.com/products/rhel/download) ## Requirements (to deploy the image) @@ -43,7 +50,7 @@ be in packer-maas/rhel9, where this file is located. Once in packer-maas/rhel9 you can generate an image with: ```shell -sudo packer init +sudo packer init . sudo PACKER_LOG=1 packer build -var 'rhel9_iso_path=/PATH/TO/rhel-baseos-9.1-x86_64-dvd.iso' . ``` diff --git a/rhel9/rhel9.pkr.hcl b/rhel9/rhel9.pkr.hcl index 6f09ab4b..22e3e176 100644 --- a/rhel9/rhel9.pkr.hcl +++ b/rhel9/rhel9.pkr.hcl @@ -1,8 +1,8 @@ packer { - required_version = ">= 1.7.0" + required_version = ">= 1.9.0" required_plugins { qemu = { - version = "~> 1.0" + version = ">= 1.0.9" source = "github.com/hashicorp/qemu" } } @@ -20,7 +20,7 @@ variable "rhel9_iso_path" { } source "qemu" "rhel9" { - boot_command = [" ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/rhel9.ks ", "console=ttyS0 inst.cmdline", ""] + boot_command = ["", "", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/rhel9.ks", "", "console=ttyS0", "", "inst.cmdline", ""] boot_wait = "3s" communicator = "none" disk_size = "4G" @@ -28,8 +28,8 @@ source "qemu" "rhel9" { http_directory = "http" iso_checksum = "none" iso_url = var.rhel9_iso_path - memory = 2048 - qemuargs = [["-serial", "stdio"], ["-cpu", "host"]] + memory = 4096 + qemuargs = [["-serial", "stdio"], ["-cpu", "max"]] shutdown_timeout = "1h" } @@ -43,6 +43,6 @@ build { "source ../scripts/fuse-nbd", "source ../scripts/fuse-tar-root" ] - inline_shebang = "/bin/bash -e" + inline_shebang = "/bin/bash -x" } } diff --git a/scripts/fuse-nbd b/scripts/fuse-nbd index a5ae1744..5e3f76e8 100644 --- a/scripts/fuse-nbd +++ b/scripts/fuse-nbd @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash -x # # fuse-nbd - Mount Packer image for customization # @@ -18,7 +18,7 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -set -ex +set -x PACKER_OUTPUT=output-${SOURCE:-qemu}/packer-${SOURCE:-qemu} IMG_FMT=${IMG_FMT:-qcow2} @@ -32,10 +32,13 @@ sync -f ${PACKER_OUTPUT} TMP_DIR=$(mktemp -d /tmp/packer-maas-XXXX) cleanup() { + cd; for dev in $(ls -d ${TMP_DIR}/p*); do - fusermount -u ${dev} + fusermount -z -u ${dev} + if grep -qs "${dev} " /proc/mounts; then umount -f ${dev} ; else true ; fi done rm -rf "${TMP_DIR}" + return 0; } trap cleanup EXIT @@ -45,7 +48,7 @@ function mount_part() { FUSEDRV=${3:-fuse2fs} DEV=${TMP_DIR}/p${PART} [ -d ${MOUNTPOINT} ] || mkdir -p ${MOUNTPOINT} - mkdir ${DEV} + mkdir -p ${DEV} nbdfuse ${DEV} \ --command nbdkit -s nbd \ socket=$(pwd)/qemu-img.sock \ @@ -69,4 +72,4 @@ qemu-nbd --socket=$(pwd)/qemu-img.sock \ --shared=10 \ ${PACKER_OUTPUT} & -mkdir "${TMP_DIR}/root" +mkdir -p "${TMP_DIR}/root" diff --git a/scripts/fuse-tar-root b/scripts/fuse-tar-root index 426da16d..4fa9d769 100644 --- a/scripts/fuse-tar-root +++ b/scripts/fuse-tar-root @@ -31,7 +31,7 @@ if [ -d curtin ] || [ -d "$CURTIN_HOOKS" ]; then fi echo "Creating MAAS image ${OUTPUT}..." -tar -Sczpf "${OUTPUT}" --acls --selinux --xattrs -C $ROOT_MOUNT . +tar -Sczpf "${OUTPUT}" --acls --selinux --xattrs --exclude='agent.*' --exclude='*.socket' -C $ROOT_MOUNT . if [ -n "$MANIFEST" ]; then echo "Creating manifest..." @@ -39,8 +39,10 @@ if [ -n "$MANIFEST" ]; then mount -o bind /dev "${ROOT_MOUNT}/dev" chroot "${ROOT_MOUNT}" rpm -qa | sort -u -o $MANIFEST umount "${ROOT_MOUNT}/dev" + if grep -qs "${ROOT_MOUNT}/dev " /proc/mounts; then umount -f ${ROOT_MOUNT}/dev ; else true ; fi fi sync -fusermount -u "${ROOT_MOUNT}" +fusermount -z -u "${ROOT_MOUNT}" +if grep -qs "${ROOT_MOUNT} " /proc/mounts; then umount -f ${ROOT_MOUNT} ; else true ; fi echo 'Done' diff --git a/ubuntu/Makefile b/ubuntu/Makefile index e9a3d042..4d0c2b99 100644 --- a/ubuntu/Makefile +++ b/ubuntu/Makefile @@ -8,8 +8,11 @@ SUDO ?= sudo all: custom-cloudimg.tar.gz check-deps: - dpkg -s libnbd-bin nbdkit packer fuse2fs cloud-image-utils ovmf > /dev/null - + @if [ $(shell lsb_release -sr|cut -d. -f1) -le 20 ];then \ + dpkg -s libnbd0 nbdkit packer fuse2fs fusefat cloud-image-utils ovmf > /dev/null; \ + elif [ $(shell lsb_release -sr|cut -d. -f1) -gt 20 ];then \ + dpkg -s libnbd-bin nbdkit packer fuse2fs fusefat cloud-image-utils ovmf > /dev/null; \ + fi lint: packer validate . packer fmt -check -diff . diff --git a/ubuntu/scripts/cleanup.sh b/ubuntu/scripts/cleanup.sh index e8957450..1a4d92d7 100644 --- a/ubuntu/scripts/cleanup.sh +++ b/ubuntu/scripts/cleanup.sh @@ -19,5 +19,5 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -apt-get autoremove --purge -yq -apt-get clean -yq +DEBIAN_FRONTEND=noninteractive apt-get autoremove --purge -yq +DEBIAN_FRONTEND=noninteractive apt-get clean -yq diff --git a/ubuntu/scripts/curtin.sh b/ubuntu/scripts/curtin.sh index 4505247e..c371f895 100644 --- a/ubuntu/scripts/curtin.sh +++ b/ubuntu/scripts/curtin.sh @@ -19,7 +19,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -apt-get install -y jq +DEBIAN_FRONTEND=noninteractive apt-get install -y jq mkdir -p /curtin # install scripts diff --git a/ubuntu/scripts/install-custom-packages b/ubuntu/scripts/install-custom-packages index 00189567..7ae520b8 100644 --- a/ubuntu/scripts/install-custom-packages +++ b/ubuntu/scripts/install-custom-packages @@ -39,8 +39,8 @@ dpkg -l 'linux-image-*' 'linux-headers-*' | awk '/^ii/{print $2}' | xargs apt-ge echo "install new kernel" tar xzvf "${PKG_TGZ}" -C "${WORKDIR}" DEBS=$(find "${WORKDIR}" -name '*.deb') -apt-get install -y --no-install-recommends ${DEBS} -apt-get install --fix-broken +DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ${DEBS} +DEBIAN_FRONTEND=noninteractive apt-get install --fix-broken echo "purge unused packages" -apt-get autoremove -y +DEBIAN_FRONTEND=noninteractive apt-get autoremove -y diff --git a/ubuntu/scripts/networking.sh b/ubuntu/scripts/networking.sh index 9f0539ac..d68718b5 100644 --- a/ubuntu/scripts/networking.sh +++ b/ubuntu/scripts/networking.sh @@ -19,7 +19,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -apt-get install -qy netplan.io cloud-init +DEBIAN_FRONTEND=noninteractive apt-get install -qy netplan.io cloud-init cat > /etc/sysctl.d/99-cloudimg-ipv6.conf < /var/log/maas.log set +e # Enable SSH -# vim-cmd hostsvc/enable_ssh -# vim-cmd hostsvc/start_ssh +vim-cmd hostsvc/enable_ssh +vim-cmd hostsvc/start_ssh # Enable ESXi shell -# vim-cmd hostsvc/enable_esx_shell -# vim-cmd hostsvc/start_esx_shell +vim-cmd hostsvc/enable_esx_shell +vim-cmd hostsvc/start_esx_shell # Track whether any network configuration failed. failed=0 diff --git a/vmware-esxi/Makefile b/vmware-esxi/Makefile index d774447c..3956af9f 100644 --- a/vmware-esxi/Makefile +++ b/vmware-esxi/Makefile @@ -10,7 +10,11 @@ VENV := .ve all: vmware-esxi.dd.gz check-deps: - dpkg -s libnbd-bin nbdkit packer fusefat > /dev/null + @if [ $(shell lsb_release -sr|cut -d. -f1) -le 20 ];then \ + dpkg -s libnbd0 nbdkit packer fuse2fs fusefat > /dev/null; \ + elif [ $(shell lsb_release -sr|cut -d. -f1) -gt 20 ];then \ + dpkg -s libnbd-bin nbdkit packer fuse2fs fusefat > /dev/null; \ + fi scripts.tar.xz: export TMP_DIR=$$(mktemp -d /tmp/packer-maas-XXXX);\ @@ -42,4 +46,4 @@ format: $(VENV) clean: ${SUDO} ${RM} -rf output-esxi vmware-esxi.dd vmware-esxi.dd.gz $(VENV) -.INTERMEDIATE: scripts.tar.xz \ No newline at end of file +.INTERMEDIATE: scripts.tar.xz diff --git a/vmware-esxi/README.md b/vmware-esxi/README.md index 9b384fdf..e43f712a 100644 --- a/vmware-esxi/README.md +++ b/vmware-esxi/README.md @@ -2,21 +2,43 @@ ## Introduction -[MAAS](https://maas.io) 2.5 and above has the ability to deploy VMware ESXi as a custom image. [MAAS](https://maas.io) cannot directly deploy the VMware ESXi ISO, a specialized image must be created from the ISO. Canonical has created a Packer template to automatically do this for you. +[MAAS](https://maas.io) 3.3 and above has the ability to deploy VMware ESXi as a custom image. [MAAS](https://maas.io) cannot directly deploy the VMware ESXi ISO, a specialized image must be created from the ISO. Canonical has created a Packer template to automatically do this for you. + +## Hardware Prerequisites (to create the images) + +* A machine running Ubuntu 18.04 or 20.04 with the ability to run KVM virtual machines. +* Dual core x86_64 processor supporting hardware virtualization with at least 8GB of RAM and 32GB of disk space available. + +## Package Prerequisites (to create the images) + +* build-essential +* fuse2fs +* fusefat +* libnbd0 +* libosinfo-bin +* libvirt-daemon +* libvirt-daemon-system +* nbdfuse +* nbdkit +* ovmf +* python3-dev +* python3-pip +* qemu-block-extra +* qemu-system-x86 +* qemu-utils +* packer - from Hashicorp repository, v1.9.0 or newer -## Prerequisites (to create the images) +```shell +wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/hashicorp-archive-keyring.gpg +echo "deb [signed-by=/etc/apt/trusted.gpg.d/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list +sudo apt update && sudo apt install packer +``` -* A machine running Ubuntu 18.04+ with the ability to run KVM virtual machines. -* Dual core x86_64 processor supporting hardware virtualization with at least 4GB of RAM and 32GB of disk space available. -* qemu-kvm -* qemu-utils, libnbd-bin, nbdkit and fusefat -* Python Pip -* [Packer](https://www.packer.io/intro/getting-started/install.html), v1.7.0 or newer * The VMware ESXi installation ISO must be downloaded manually. You can download it [here.](https://www.vmware.com/go/get-free-esxi) ## Requirements (to deploy the image) -* [MAAS](https://maas.io) 2.5 or above, [MAAS](https://maas.io) 2.6 required for storage configuration +* [MAAS](https://maas.io) 3.3 or above VMware ESXi has a specific set of [hardware requirements](https://www.vmware.com/resources/compatibility/search.php) which are more stringent than MAAS. @@ -35,7 +57,7 @@ make ISO=/path/to/VMware-VMvisor-Installer-8.0b-21203435.x86_64.iso Alternatively you can manually run packer. Your current working directory must be in packer-maas/vmware-esxi, where this file is located. Once in packer-maas/vmware-esxi you can generate an image with: ```shell -sudo packer init +sudo packer init . sudo PACKER_LOG=1 packer build -var 'vmware_esxi_iso_path=/path/to/VMware-VMvisor-Installer-8.0b-21203435.x86_64.iso' . ``` @@ -44,6 +66,7 @@ Note: vmware-esxi.pkr.hcl is configured to run Packer in headless mode. Only Pac Installation is non-interactive. ## Uploading an image to MAAS +_Note: If using snap-based MAAS, the image to be uploaded needs reside under your home directory._ ```shell maas $PROFILE boot-resources create \ diff --git a/vmware-esxi/post.sh b/vmware-esxi/post.sh index c8f91f2d..f264d95b 100644 --- a/vmware-esxi/post.sh +++ b/vmware-esxi/post.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/sh -x echo 'Adding curtin-hooks to image...' mount_part 1 $TMP_DIR/boot fusefat @@ -9,4 +9,5 @@ cp -v scripts.tar.xz $TMP_DIR/boot/curtin/ echo 'Unmounting image...' sync -f $TMP_DIR/boot -fusermount -u $TMP_DIR/boot +fusermount -z -u $TMP_DIR/boot +if grep -qs "$TMP_DIR/boot " /proc/mounts; then umount -f $TMP_DIR/boot ; else true ; fi diff --git a/vmware-esxi/vmware-esxi.pkr.hcl b/vmware-esxi/vmware-esxi.pkr.hcl index 70aab673..a78d1708 100644 --- a/vmware-esxi/vmware-esxi.pkr.hcl +++ b/vmware-esxi/vmware-esxi.pkr.hcl @@ -1,8 +1,8 @@ packer { - required_version = ">= 1.7.0" + required_version = ">= 1.9.0" required_plugins { qemu = { - version = "~> 1.0" + version = ">= 1.0.9" source = "github.com/hashicorp/qemu" } } @@ -14,7 +14,7 @@ variable "vmware_esxi_iso_path" { } source "qemu" "esxi" { - boot_command = ["", "O", " ks=cdrom:/KS.CFG", " cpuUniformityHardCheckPanic=FALSE", "systemMediaSize=min", " com1_Port=0x3f8 tty2Port=com1", ""] + boot_command = ["", "O", "", "ks=cdrom:/KS.CFG", "", "cpuUniformityHardCheckPanic=FALSE", "", "systemMediaSize=min", "", "com1_Port=0x3f8", "", "tty2Port=com1", ""] boot_wait = "3s" cd_files = ["./KS.CFG"] cd_label = "kickstart" @@ -25,9 +25,9 @@ source "qemu" "esxi" { headless = true iso_checksum = "none" iso_url = var.vmware_esxi_iso_path - memory = 4096 + memory = 8192 net_device = "vmxnet3" - qemuargs = [["-cpu", "host"], ["-smp", "2,sockets=2,cores=1,threads=1"], ["-serial", "stdio"]] + qemuargs = [["-cpu", "max"], ["-smp", "2,sockets=2,cores=1,threads=1"], ["-serial", "stdio"]] shutdown_timeout = "1h" }