HardenedBSD/release/tools/azure.conf
Colin Percival 0b1c5628c7 release: Rework vm_extra_pre_umount
The vm_extra_pre_umount function in vmimage.subr served two purposes:
It removed /etc/resolv.conf and /qemu (if cross-building), and it
provided a function for cloudware to override in order to make cloud
specific changes to the filesystem before constructing a disk image.

This resulted in a number of bugs:
1. When cross-building, the emulator binary was left as /qemu in the
Azure, GCE, Openstack and Vagrant images.
2. The build host's resolv.conf was left as /etc/resolv.conf in the
basic-ci and basic-cloudinit images.
3. When building GCE images, a Google-specific resolv.conf file was
constructed, and then deleted before the disk image was created.

Move the bits needed for running code inside a VM staging directory
from vm_install_base into a new vm_emulation_setup routine, and move
the corresponding cleanup bits from vm_extra_pre_umount to a new
vm_emulation_cleanup routine.

Remove the /qemu and /etc/resolv.conf cleanups from the cloudware
configuration files (where they exist) since we will now be running
vm_emulation_cleanup to remove those even when vm_extra_pre_umount
has been overridden.

Override vm_emulation_cleanup in gce.conf since in that one case (and
*only* that one case) we don't want to clean up resolv.conf (since it
was constructed for the VM image rather than copied from the host).

releng/14.1 candidate.

MFC after:	1 week
Sponsored by:	https://www.patreon.com/cperciva
2024-05-06 13:40:47 -07:00

58 lines
1.6 KiB
Bash

#!/bin/sh
#
#
# Convention of Linux type VM on Azure is 30G
export VMSIZE=30g
# Set to a list of packages to install.
export VM_EXTRA_PACKAGES="azure-agent python python3 firstboot-freebsd-update firstboot-pkgs"
# Set to a list of third-party software to enable in rc.conf(5).
export VM_RC_LIST="ntpd sshd waagent firstboot_freebsd_update firstboot_pkgs"
# No swap space; waagent will allocate swap space on the resource disk.
# See ResourceDisk.EnableSwap and ResourceDisk.SwapSizeMB in waagent.conf
export NOSWAP=YES
# https://learn.microsoft.com/en-us/partner-center/marketplace/azure-vm-certification-faq#vm-images-must-have-1-mb-of-free-space
export VM_BOOTPARTSOFFSET=1M
vm_extra_pre_umount() {
mount -t devfs devfs ${DESTDIR}/dev
# The firstboot_pkgs rc.d script will download the repository
# catalogue and install or update pkg when the instance first
# launches, so these files would just be replaced anyway; removing
# them from the image allows it to boot faster.
chroot ${DESTDIR} ${EMULATOR} env ASSUME_ALWAYS_YES=yes \
/usr/sbin/pkg delete -f -y pkg
rm ${DESTDIR}/var/db/pkg/repo-*.sqlite
chroot ${DESTDIR} ${EMULATOR} pw usermod root -h -
umount ${DESTDIR}/dev
cat << EOF >> ${DESTDIR}/etc/rc.conf
ifconfig_hn0="SYNCDHCP"
ntpd_sync_on_start="YES"
EOF
cat << EOF >> ${DESTDIR}/boot/loader.conf
autoboot_delay="-1"
beastie_disable="YES"
loader_logo="none"
hw.memtest.tests="0"
console="comconsole efi vidconsole"
comconsole_speed="115200"
boot_multicons="YES"
boot_serial="YES"
mlx4en_load="YES"
mlx5en_load="YES"
EOF
touch ${DESTDIR}/firstboot
return 0
}