ec2.conf revision 318963
11541Srgrimes#!/bin/sh
21541Srgrimes#
31541Srgrimes# $FreeBSD: stable/10/release/tools/ec2.conf 318963 2017-05-26 19:02:46Z gjb $
41541Srgrimes#
51541Srgrimes
61541Srgrimes# Packages to install into the image we're creating.  This is a deliberately
71541Srgrimes# minimalist set, providing only the packages necessary to bootstrap further
81541Srgrimes# package installation as specified via EC2 user-data.
91541Srgrimesexport VM_EXTRA_PACKAGES="ec2-scripts firstboot-freebsd-update firstboot-pkgs"
101541Srgrimes
111541Srgrimes# Set to a list of third-party software to enable in rc.conf(5).
121541Srgrimesexport VM_RC_LIST="ec2_configinit ec2_fetchkey ec2_ephemeralswap ec2_loghostkey firstboot_freebsd_update firstboot_pkgs"
131541Srgrimes
141541Srgrimes# Build with a 1.5 GB UFS partition; the growfs rc.d script will expand
151541Srgrimes# the partition to fill the root disk after the EC2 instance is launched.
161541Srgrimes# Note that if this is set to <N>G, we will end up with an <N+1> GB disk
171541Srgrimes# image since VMSIZE is the size of the UFS partition, not the disk which
181541Srgrimes# it resides within.
191541Srgrimesexport VMSIZE=1536M
201541Srgrimes
211541Srgrimes# No swap space; the ec2_ephemeralswap rc.d script will allocate swap
221541Srgrimes# space on EC2 ephemeral disks.  (If they exist -- the T2 low-cost instances
231541Srgrimes# and the C4 compute-optimized instances don't have ephemeral disks.  But
241541Srgrimes# it would be silly to bloat the image and increase costs for every instance
251541Srgrimes# just for those two families, especially since instances ranging in size
261541Srgrimes# from 1 GB of RAM to 60 GB of RAM would need different sizes of swap space
271541Srgrimes# anyway.)
281541Srgrimesexport NOSWAP=YES
291541Srgrimes
301541Srgrimesvm_extra_pre_umount() {
311541Srgrimes	# The firstboot_pkgs rc.d script will download the repository
321541Srgrimes	# catalogue and install or update pkg when the instance first
331541Srgrimes	# launches, so these files would just be replaced anyway; removing
348876Srgrimes	# them from the image allows it to boot faster.
351541Srgrimes	chroot ${DESTDIR} env ASSUME_ALWAYS_YES=yes \
361541Srgrimes		/usr/sbin/pkg delete -f -y pkg
371541Srgrimes	rm ${DESTDIR}/var/db/pkg/repo-*.sqlite
381541Srgrimes
391541Srgrimes	# The size of the EC2 root disk can be configured at instance launch
408876Srgrimes	# time; expand our filesystem to fill the disk.
418876Srgrimes	echo 'growfs_enable="YES"' >> ${DESTDIR}/etc/rc.conf
421541Srgrimes
431541Srgrimes	# EC2 instances use DHCP to get their network configuration.
441541Srgrimes	echo 'ifconfig_DEFAULT="SYNCDHCP"' >> ${DESTDIR}/etc/rc.conf
458876Srgrimes
461541Srgrimes	# Unless the system has been configured via EC2 user-data, the user
471541Srgrimes	# will need to SSH in to do anything.
481541Srgrimes	echo 'sshd_enable="YES"' >> ${DESTDIR}/etc/rc.conf
491541Srgrimes
501541Srgrimes	# The AWS CLI tools are generally useful, and small enough that they
511541Srgrimes	# will download quickly; but users will often override this setting
521541Srgrimes	# via EC2 user-data.
531541Srgrimes	echo 'firstboot_pkgs_list="awscli"' >> ${DESTDIR}/etc/rc.conf
541541Srgrimes
558876Srgrimes	# The EC2 console is output-only, so while printing a backtrace can
561541Srgrimes	# be useful, there's no point dropping into a debugger or waiting
571541Srgrimes	# for a keypress.
581541Srgrimes	echo 'debug.trace_on_panic=1' >> ${DESTDIR}/etc/sysctl.conf
591541Srgrimes	echo 'debug.debugger_on_panic=0' >> ${DESTDIR}/etc/sysctl.conf
601541Srgrimes	echo 'kern.panic_reboot_wait_time=0' >> ${DESTDIR}/etc/sysctl.conf
611541Srgrimes
621541Srgrimes	# The console is not interactive, so we might as well boot quickly.
631541Srgrimes	echo 'autoboot_delay="-1"' >> ${DESTDIR}/boot/loader.conf
641541Srgrimes	echo 'beastie_disable="YES"' >> ${DESTDIR}/boot/loader.conf
651541Srgrimes
661541Srgrimes	# EC2 has two consoles: An emulated serial port ("system log"),
671541Srgrimes	# which has been present since 2006; and a VGA console ("instance
681541Srgrimes	# screenshot") which was introduced in 2016.
691541Srgrimes	echo 'boot_multicons="YES"' >> ${DESTDIR}/boot/loader.conf
701541Srgrimes
711541Srgrimes	# Some older EC2 hardware used a version of Xen with a bug in its
721541Srgrimes	# emulated serial port.  It is not clear if EC2 still has any such
731541Srgrimes	# nodes, but apply the workaround just in case.
741541Srgrimes	echo 'hw.broken_txfifo="1"' >> ${DESTDIR}/boot/loader.conf
751541Srgrimes
761541Srgrimes	# The first time the AMI boots, the installed "first boot" scripts
771541Srgrimes	# should be allowed to run:
781541Srgrimes	# * ec2_configinit (download and process EC2 user-data)
791541Srgrimes	# * ec2_fetchkey (arrange for SSH using the EC2-provided public key)
801541Srgrimes	# * growfs (expand the filesystem to fill the provided disk)
818449Sbde	# * firstboot_freebsd_update (install critical updates)
821541Srgrimes	# * firstboot_pkgs (install packages)
831541Srgrimes	touch ${DESTDIR}/firstboot
848449Sbde
851541Srgrimes	return 0
861541Srgrimes}
871541Srgrimes