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

Fixes for vmware-esxi builder and any builders that the fuse scripts. #131

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
316c44d
Change to lazy unmount
ThinGuy Aug 31, 2023
75d8cb5
Don't check hardware/CPUs during packer image creation
ThinGuy Aug 31, 2023
956a29e
Update vmware-esxi.pkr.hcl
ThinGuy Aug 31, 2023
7d441f3
Missing trailing "." for packer init
ThinGuy Aug 31, 2023
8f3eb48
Update fuse-nbd
ThinGuy Aug 31, 2023
df9cb08
Update fuse-tar-root
ThinGuy Aug 31, 2023
45b98f7
Have fusermount perform lazy unmounts to prevent image build hanging …
ThinGuy Aug 31, 2023
564891b
Change directory to $HOME before performing cleanup functipon
ThinGuy Aug 31, 2023
2e2e5bc
Fix Requirements and packages
ThinGuy Aug 31, 2023
2c160d3
Make pre-reqs clearer
ThinGuy Aug 31, 2023
b9e9c69
Enable ssh and ESXi shell by default
ThinGuy Aug 31, 2023
9fc46c5
Cleanup package requirements.
ThinGuy Aug 31, 2023
1f1a5c6
Add note for snap-based MAAS users related to image location for uploads
ThinGuy Aug 31, 2023
b5871cc
Set minimum packer version and use packer qmeu pluging
ThinGuy Aug 31, 2023
0d5c0e6
Set min packer to 1.9, set updated qemu plugin, change cpu arg to max
ThinGuy Aug 31, 2023
66cd434
Change libnbd-bin to libnbd0 for focal and bionic
ThinGuy Aug 31, 2023
d62e566
Use correct version of libnbd based on Ubuntu release
ThinGuy Aug 31, 2023
4c4511e
Use correct version of libnbd depending on Ubuntu release
ThinGuy Aug 31, 2023
001e308
Fix tab issue
ThinGuy Aug 31, 2023
d57589b
Fix tabs
ThinGuy Aug 31, 2023
406d8dd
Use correct version of libnbd based on ubuntu release
ThinGuy Aug 31, 2023
d0b924c
If fuse fs still mounted, force unmount
ThinGuy Sep 1, 2023
a029356
force umount if fuse fs still mounted, remove "Exit immediately" shel…
ThinGuy Sep 1, 2023
2c8fc47
Add trailing period (represents *.json or *.hcl) to packer init command
ThinGuy Sep 1, 2023
afd0a89
Add how install packer from hashicorp repositories
ThinGuy Sep 1, 2023
b3175b6
Attempt to fix non-zero exit code
ThinGuy Sep 1, 2023
9761506
Fix non-zero exit code
ThinGuy Sep 1, 2023
6f13830
Fix missing double quotes in boot_cmd string
ThinGuy Sep 1, 2023
1126242
Fix missing double quote at end of systemMediaSize=min
ThinGuy Sep 1, 2023
2dbf2f8
cleanup boot_command by using <spacebar> characters
ThinGuy Sep 1, 2023
58d1c11
Remove "Exit Immediately" shell option and turn on verbose for post p…
ThinGuy Sep 1, 2023
a9c8918
Backout packer/qemu definitions due to duplicated lines in other hcl
ThinGuy Sep 1, 2023
153586b
Test if $TMP_DIR/boot is mounted and only unmount if necessary.
ThinGuy Sep 2, 2023
1b2b9e8
Test if $dev (${TMP_DIR}/p*) is mounted and only unmount if necessary.
ThinGuy Sep 2, 2023
910723f
Test if ${ROOT_MOUNT}{,dev} are mounted and unmount if necessary.
ThinGuy Sep 2, 2023
946d881
Remove "Exit immediately" shell, enable verbose
ThinGuy Sep 2, 2023
9438dcf
Enable verbose output for post.sh
ThinGuy Sep 2, 2023
093c017
Instruct tar to exclude Unix sockets
ThinGuy Sep 8, 2023
f1902eb
Use DEBIAN_FRONTEND=noninteractive to prevent debconf from trying to …
ThinGuy Sep 8, 2023
cbfbee7
Use DEBIAN_FRONTEND=noninteractive so debconf does not try to use Dialog
ThinGuy Sep 8, 2023
a80d04a
Use DEBIAN_FRONTEND=noninteractive to prevent debconf from using Dialog
ThinGuy Sep 8, 2023
b842bed
Use DEBIAN_FRONTEND=noninteractive to prevent debconf from using Dialog
ThinGuy Sep 8, 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
6 changes: 5 additions & 1 deletion rhel9/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@if [ $(shell lsb_release -sr|cut -d. -f1) -le 20 ];then \
@if [ $(shell lsb_release -sr|cut -d. -f1) -ge 22 ];then \
dpkg -s libnbd-bin nbdkit packer fuse2fs > /dev/null; \
else \
dpkg -s libnbd0 nbdkit packer fuse2fs > /dev/null; \
fi

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
Expand Down
11 changes: 9 additions & 2 deletions rhel9/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep the reference to Packer install page. It's easier to keep docs up to date if we rely on external resources.


```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)
Expand Down Expand Up @@ -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' .
```

Expand Down
12 changes: 6 additions & 6 deletions rhel9/rhel9.pkr.hcl
Original file line number Diff line number Diff line change
@@ -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"
}
}
Expand All @@ -20,16 +20,16 @@ variable "rhel9_iso_path" {
}

source "qemu" "rhel9" {
boot_command = ["<up><tab> ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/rhel9.ks ", "console=ttyS0 inst.cmdline", "<enter>"]
boot_command = ["<up><tab>", "<spacebar>", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/rhel9.ks", "<spacebar>", "console=ttyS0", "<spacebar>", "inst.cmdline", "<enter>"]
boot_wait = "3s"
communicator = "none"
disk_size = "4G"
headless = true
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"
}

Expand All @@ -43,6 +43,6 @@ build {
"source ../scripts/fuse-nbd",
"source ../scripts/fuse-tar-root"
]
inline_shebang = "/bin/bash -e"
inline_shebang = "/bin/bash -x"
}
}
13 changes: 8 additions & 5 deletions scripts/fuse-nbd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -e
#!/bin/bash -x
#
# fuse-nbd - Mount Packer image for customization
#
Expand All @@ -18,7 +18,7 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -ex
set -x

PACKER_OUTPUT=output-${SOURCE:-qemu}/packer-${SOURCE:-qemu}
IMG_FMT=${IMG_FMT:-qcow2}
Expand All @@ -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

Expand All @@ -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 \
Expand All @@ -69,4 +72,4 @@ qemu-nbd --socket=$(pwd)/qemu-img.sock \
--shared=10 \
${PACKER_OUTPUT} &

mkdir "${TMP_DIR}/root"
mkdir -p "${TMP_DIR}/root"
4 changes: 3 additions & 1 deletion scripts/fuse-tar-root
Original file line number Diff line number Diff line change
Expand Up @@ -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'
7 changes: 5 additions & 2 deletions ubuntu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see suggestion in the RHEL makefile above

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 .
Expand Down
10 changes: 5 additions & 5 deletions vmware-esxi/KS.CFG
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ vmaccepteula
# If changed be sure to update the vcenter script below.
rootpw password123!

install --firstdisk
install --firstdisk --ignoreprereqwarnings --ignoreprereqerrors --forceunsupportedinstall

# Sets VMware ESXi licensing key. If not included installs in
# evaluation mode.
Expand All @@ -27,12 +27,12 @@ exec &> /var/log/maas.log
set +e

# Enable SSH
# vim-cmd hostsvc/enable_ssh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should keep this disabled, it may pose a security risk for some users and we don't have a good way to alert them of this change.

# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, keep this disabled

vim-cmd hostsvc/start_esx_shell

# Track whether any network configuration failed.
failed=0
Expand Down
8 changes: 6 additions & 2 deletions vmware-esxi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see suggestion in the makefiles above

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);\
Expand Down Expand Up @@ -42,4 +46,4 @@ format: $(VENV)
clean:
${SUDO} ${RM} -rf output-esxi vmware-esxi.dd vmware-esxi.dd.gz $(VENV)

.INTERMEDIATE: scripts.tar.xz
.INTERMEDIATE: scripts.tar.xz
43 changes: 33 additions & 10 deletions vmware-esxi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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' .
```

Expand All @@ -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 \
Expand Down
5 changes: 3 additions & 2 deletions vmware-esxi/post.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/sh -x

echo 'Adding curtin-hooks to image...'
mount_part 1 $TMP_DIR/boot fusefat
Expand All @@ -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
10 changes: 5 additions & 5 deletions vmware-esxi/vmware-esxi.pkr.hcl
Original file line number Diff line number Diff line change
@@ -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"
}
}
Expand All @@ -14,7 +14,7 @@ variable "vmware_esxi_iso_path" {
}

source "qemu" "esxi" {
boot_command = ["<enter><wait>", "<leftShift>O", " ks=cdrom:/KS.CFG", " cpuUniformityHardCheckPanic=FALSE", "systemMediaSize=min", " com1_Port=0x3f8 tty2Port=com1", "<enter>"]
boot_command = ["<enter><wait>", "<leftShift>O", "<spacebar>", "ks=cdrom:/KS.CFG", "<spacebar>", "cpuUniformityHardCheckPanic=FALSE", "<spacebar>", "systemMediaSize=min", "<spacebar>", "com1_Port=0x3f8", "<spacebar>", "tty2Port=com1", "<enter>"]
boot_wait = "3s"
cd_files = ["./KS.CFG"]
cd_label = "kickstart"
Expand All @@ -25,9 +25,9 @@ source "qemu" "esxi" {
headless = true
iso_checksum = "none"
iso_url = var.vmware_esxi_iso_path
memory = 4096
memory = 8192
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it this really necessary?

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"
}

Expand Down