1280879Scperciva#!/bin/sh 2280879Scperciva# 3280879Scperciva# $FreeBSD: stable/10/release/tools/ec2.conf 326264 2017-11-27 15:12:14Z gjb $ 4280879Scperciva# 5280879Scperciva 6280879Scperciva# Packages to install into the image we're creating. This is a deliberately 7280879Scperciva# minimalist set, providing only the packages necessary to bootstrap further 8280879Scperciva# package installation as specified via EC2 user-data. 9280879Scpercivaexport VM_EXTRA_PACKAGES="ec2-scripts firstboot-freebsd-update firstboot-pkgs" 10280879Scperciva 11280879Scperciva# Set to a list of third-party software to enable in rc.conf(5). 12280879Scpercivaexport VM_RC_LIST="ec2_configinit ec2_fetchkey ec2_ephemeralswap ec2_loghostkey firstboot_freebsd_update firstboot_pkgs" 13280879Scperciva 14280879Scperciva# Build with a 1.5 GB UFS partition; the growfs rc.d script will expand 15280879Scperciva# the partition to fill the root disk after the EC2 instance is launched. 16280879Scperciva# Note that if this is set to <N>G, we will end up with an <N+1> GB disk 17280879Scperciva# image since VMSIZE is the size of the UFS partition, not the disk which 18280879Scperciva# it resides within. 19280879Scpercivaexport VMSIZE=1536M 20280879Scperciva 21280879Scperciva# No swap space; the ec2_ephemeralswap rc.d script will allocate swap 22280879Scperciva# space on EC2 ephemeral disks. (If they exist -- the T2 low-cost instances 23280879Scperciva# and the C4 compute-optimized instances don't have ephemeral disks. But 24280879Scperciva# it would be silly to bloat the image and increase costs for every instance 25280879Scperciva# just for those two families, especially since instances ranging in size 26280879Scperciva# from 1 GB of RAM to 60 GB of RAM would need different sizes of swap space 27280879Scperciva# anyway.) 28280879Scpercivaexport NOSWAP=YES 29280879Scperciva 30280879Scpercivavm_extra_pre_umount() { 31280879Scperciva # The firstboot_pkgs rc.d script will download the repository 32280879Scperciva # catalogue and install or update pkg when the instance first 33280879Scperciva # launches, so these files would just be replaced anyway; removing 34280879Scperciva # them from the image allows it to boot faster. 35318963Sgjb chroot ${DESTDIR} env ASSUME_ALWAYS_YES=yes \ 36318963Sgjb /usr/sbin/pkg delete -f -y pkg 37280879Scperciva rm ${DESTDIR}/var/db/pkg/repo-*.sqlite 38280879Scperciva 39280879Scperciva # The size of the EC2 root disk can be configured at instance launch 40280879Scperciva # time; expand our filesystem to fill the disk. 41280879Scperciva echo 'growfs_enable="YES"' >> ${DESTDIR}/etc/rc.conf 42280879Scperciva 43280879Scperciva # EC2 instances use DHCP to get their network configuration. 44280879Scperciva echo 'ifconfig_DEFAULT="SYNCDHCP"' >> ${DESTDIR}/etc/rc.conf 45280879Scperciva 46280879Scperciva # Unless the system has been configured via EC2 user-data, the user 47280879Scperciva # will need to SSH in to do anything. 48280879Scperciva echo 'sshd_enable="YES"' >> ${DESTDIR}/etc/rc.conf 49280879Scperciva 50280879Scperciva # The AWS CLI tools are generally useful, and small enough that they 51280879Scperciva # will download quickly; but users will often override this setting 52280879Scperciva # via EC2 user-data. 53280879Scperciva echo 'firstboot_pkgs_list="awscli"' >> ${DESTDIR}/etc/rc.conf 54280879Scperciva 55280879Scperciva # The EC2 console is output-only, so while printing a backtrace can 56280879Scperciva # be useful, there's no point dropping into a debugger or waiting 57280879Scperciva # for a keypress. 58280879Scperciva echo 'debug.trace_on_panic=1' >> ${DESTDIR}/etc/sysctl.conf 59280879Scperciva echo 'debug.debugger_on_panic=0' >> ${DESTDIR}/etc/sysctl.conf 60280879Scperciva echo 'kern.panic_reboot_wait_time=0' >> ${DESTDIR}/etc/sysctl.conf 61280879Scperciva 62280879Scperciva # The console is not interactive, so we might as well boot quickly. 63280879Scperciva echo 'autoboot_delay="-1"' >> ${DESTDIR}/boot/loader.conf 64280879Scperciva echo 'beastie_disable="YES"' >> ${DESTDIR}/boot/loader.conf 65280879Scperciva 66302931Scperciva # EC2 has two consoles: An emulated serial port ("system log"), 67302931Scperciva # which has been present since 2006; and a VGA console ("instance 68302931Scperciva # screenshot") which was introduced in 2016. 69302931Scperciva echo 'boot_multicons="YES"' >> ${DESTDIR}/boot/loader.conf 70280879Scperciva 71280879Scperciva # Some older EC2 hardware used a version of Xen with a bug in its 72280879Scperciva # emulated serial port. It is not clear if EC2 still has any such 73280879Scperciva # nodes, but apply the workaround just in case. 74280879Scperciva echo 'hw.broken_txfifo="1"' >> ${DESTDIR}/boot/loader.conf 75280879Scperciva 76280879Scperciva # The first time the AMI boots, the installed "first boot" scripts 77280879Scperciva # should be allowed to run: 78280879Scperciva # * ec2_configinit (download and process EC2 user-data) 79280879Scperciva # * ec2_fetchkey (arrange for SSH using the EC2-provided public key) 80280879Scperciva # * growfs (expand the filesystem to fill the provided disk) 81280879Scperciva # * firstboot_freebsd_update (install critical updates) 82280879Scperciva # * firstboot_pkgs (install packages) 83280879Scperciva touch ${DESTDIR}/firstboot 84280879Scperciva 85326264Sgjb rm -f ${DESTDIR}/etc/resolv.conf 86326264Sgjb 87280879Scperciva return 0 88280879Scperciva} 89