xref: /freebsd/release/tools/ec2.conf (revision 714a6d436819d446e01d1e4741fbe1089a23fe57)
1fada6e23SColin Percival#!/bin/sh
2fada6e23SColin Percival
340ff0753SColin Percival# Package which should be installed onto all EC2 AMIs:
4fada6e23SColin Percival# * ebsnvme-id, which is very minimal and provides important EBS-specific
5fada6e23SColin Percival# functionality,
640ff0753SColin Percivalexport VM_EXTRA_PACKAGES="${VM_EXTRA_PACKAGES} ebsnvme-id"
7fada6e23SColin Percival
8fada6e23SColin Percival# Services which should be enabled by default in rc.conf(5).
9fada6e23SColin Percivalexport VM_RC_LIST="dev_aws_disk ntpd"
10fada6e23SColin Percival
112dac89aeSColin Percival# Build with a 7.9 GB partition; the growfs rc.d script will expand
12fada6e23SColin Percival# the partition to fill the root disk after the EC2 instance is launched.
13fada6e23SColin Percival# Note that if this is set to <N>G, we will end up with an <N+1> GB disk
14fada6e23SColin Percival# image since VMSIZE is the size of the filesystem partition, not the disk
15fada6e23SColin Percival# which it resides within.
162dac89aeSColin Percivalexport VMSIZE=8000m
17fada6e23SColin Percival
18fada6e23SColin Percival# No swap space; it doesn't make sense to provision any as part of the disk
19fada6e23SColin Percival# image when we could be launching onto a system with anywhere between 0.5
20fada6e23SColin Percival# and 4096 GB of RAM.
21fada6e23SColin Percivalexport NOSWAP=YES
22fada6e23SColin Percival
23fada6e23SColin Percivalec2_common() {
24fada6e23SColin Percival	# Delete the pkg package and the repo database; they will likely be
25fada6e23SColin Percival	# long out of date before the EC2 instance is launched.
26fada6e23SColin Percival	mount -t devfs devfs ${DESTDIR}/dev
27fada6e23SColin Percival	chroot ${DESTDIR} ${EMULATOR} env ASSUME_ALWAYS_YES=yes \
28fada6e23SColin Percival		/usr/sbin/pkg delete -f -y pkg
29fada6e23SColin Percival	umount ${DESTDIR}/dev
30fada6e23SColin Percival	rm ${DESTDIR}/var/db/pkg/repo-*.sqlite
31fada6e23SColin Percival
32fada6e23SColin Percival	# Turn off IPv6 Duplicate Address Detection; the EC2 networking
33fada6e23SColin Percival	# configuration makes it unnecessary.
34fada6e23SColin Percival	echo 'net.inet6.ip6.dad_count=0' >> ${DESTDIR}/etc/sysctl.conf
35fada6e23SColin Percival
36fada6e23SColin Percival	# Booting quickly is more important than giving users a chance to
37fada6e23SColin Percival	# access the boot loader via the serial port.
38fada6e23SColin Percival	echo 'autoboot_delay="-1"' >> ${DESTDIR}/boot/loader.conf
39fada6e23SColin Percival	echo 'beastie_disable="YES"' >> ${DESTDIR}/boot/loader.conf
40fada6e23SColin Percival
41*714a6d43SColin Percival	# The EFI RNG on Graviton 2 is particularly slow if we ask for the
42*714a6d43SColin Percival	# default 2048 bytes of entropy; ask for 64 bytes instead.
43*714a6d43SColin Percival	echo 'entropy_efi_seed_size="64"' >> ${DESTDIR}/boot/loader.conf
44*714a6d43SColin Percival
45fada6e23SColin Percival	# Tell gptboot not to wait 3 seconds for a keypress which will
46fada6e23SColin Percival	# never arrive.
47fada6e23SColin Percival	printf -- "-n\n" > ${DESTDIR}/boot.config
48fada6e23SColin Percival
49fada6e23SColin Percival	# The emulated keyboard attached to EC2 instances is inaccessible to
50fada6e23SColin Percival	# users, and there is no mouse attached at all; disable to keyboard
51fada6e23SColin Percival	# and the keyboard controller (to which the mouse would attach, if
52fada6e23SColin Percival	# one existed) in order to save time in device probing.
53fada6e23SColin Percival	echo 'hint.atkbd.0.disabled=1' >> ${DESTDIR}/boot/loader.conf
54fada6e23SColin Percival	echo 'hint.atkbdc.0.disabled=1' >> ${DESTDIR}/boot/loader.conf
55fada6e23SColin Percival
56fada6e23SColin Percival	# EC2 has two consoles: An emulated serial port ("system log"),
57fada6e23SColin Percival	# which has been present since 2006; and a VGA console ("instance
58fada6e23SColin Percival	# screenshot") which was introduced in 2016.
59fada6e23SColin Percival	echo 'boot_multicons="YES"' >> ${DESTDIR}/boot/loader.conf
60fada6e23SColin Percival
61fada6e23SColin Percival	# Some older EC2 hardware used a version of Xen with a bug in its
62fada6e23SColin Percival	# emulated serial port.  It is not clear if EC2 still has any such
63fada6e23SColin Percival	# nodes, but apply the workaround just in case.
64fada6e23SColin Percival	echo 'hw.broken_txfifo="1"' >> ${DESTDIR}/boot/loader.conf
65fada6e23SColin Percival
66fada6e23SColin Percival	# Load the kernel module for the Amazon "Elastic Network Adapter"
67fada6e23SColin Percival	echo 'if_ena_load="YES"' >> ${DESTDIR}/boot/loader.conf
68fada6e23SColin Percival
69fada6e23SColin Percival	# Use the "nda" driver for accessing NVMe disks rather than the
70fada6e23SColin Percival	# historical "nvd" driver.
71fada6e23SColin Percival	echo 'hw.nvme.use_nvd="0"' >> ${DESTDIR}/boot/loader.conf
72fada6e23SColin Percival
73fada6e23SColin Percival	# Disable KbdInteractiveAuthentication according to EC2 requirements.
74fada6e23SColin Percival	sed -i '' -e \
75fada6e23SColin Percival		's/^#KbdInteractiveAuthentication yes/KbdInteractiveAuthentication no/' \
76fada6e23SColin Percival		${DESTDIR}/etc/ssh/sshd_config
77fada6e23SColin Percival
780aabcd75SColin Percival	# RSA host keys are obsolete and also very slow to generate
790aabcd75SColin Percival	echo 'sshd_rsa_enable="NO"' >> ${DESTDIR}/etc/rc.conf
800aabcd75SColin Percival
81fada6e23SColin Percival	# Use FreeBSD Update mirrors hosted in AWS
82fada6e23SColin Percival	sed -i '' -e 's/update.FreeBSD.org/aws.update.FreeBSD.org/' \
83fada6e23SColin Percival		${DESTDIR}/etc/freebsd-update.conf
84fada6e23SColin Percival
85fada6e23SColin Percival	# Use the NTP service provided by Amazon
86fada6e23SColin Percival	sed -i '' -e 's/^pool/#pool/' \
87fada6e23SColin Percival		-e '1,/^#server/s/^#server.*/server 169.254.169.123 iburst/' \
88fada6e23SColin Percival		${DESTDIR}/etc/ntp.conf
89fada6e23SColin Percival
90fada6e23SColin Percival	# Provide a map for accessing Elastic File System mounts
91fada6e23SColin Percival	cat > ${DESTDIR}/etc/autofs/special_efs <<'EOF'
92fada6e23SColin Percival#!/bin/sh
93fada6e23SColin Percival
94fada6e23SColin Percivalif [ $# -eq 0 ]; then
95fada6e23SColin Percival        # No way to know which EFS filesystems exist and are
96fada6e23SColin Percival        # accessible to this EC2 instance.
97fada6e23SColin Percival        exit 0
98fada6e23SColin Percivalfi
99fada6e23SColin Percival
100fada6e23SColin Percival# Provide instructions on how to mount the requested filesystem.
101fada6e23SColin PercivalFS=$1
102fada6e23SColin PercivalREGION=`fetch -qo- http://169.254.169.254/latest/meta-data/placement/availability-zone | sed -e 's/[a-z]$//'`
103fada6e23SColin Percivalecho "-nfsv4,minorversion=1,oneopenown ${FS}.efs.${REGION}.amazonaws.com:/"
104fada6e23SColin PercivalEOF
105fada6e23SColin Percival	chmod 755 ${DESTDIR}/etc/autofs/special_efs
106fada6e23SColin Percival
107fada6e23SColin Percival	# The first time the AMI boots, run "first boot" scripts.
108fada6e23SColin Percival	touch ${DESTDIR}/firstboot
109fada6e23SColin Percival
110fada6e23SColin Percival	return 0
111fada6e23SColin Percival}
112f961ddb2SColin Percival
113f961ddb2SColin Percivalec2_base_networking () {
114f961ddb2SColin Percival	# EC2 instances use DHCP to get their network configuration.  IPv6
115f961ddb2SColin Percival	# requires accept_rtadv.
116f961ddb2SColin Percival	echo 'ifconfig_DEFAULT="SYNCDHCP accept_rtadv"' >> ${DESTDIR}/etc/rc.conf
117f961ddb2SColin Percival
118f961ddb2SColin Percival	# The EC2 DHCP server can be trusted to know whether an IP address is
119f961ddb2SColin Percival	# assigned to us; we don't need to ARP to check if anyone else is using
120f961ddb2SColin Percival	# the address before we start using it.
121f961ddb2SColin Percival	echo 'dhclient_arpwait="NO"' >> ${DESTDIR}/etc/rc.conf
122f961ddb2SColin Percival
123f961ddb2SColin Percival	# Enable IPv6 on all interfaces, and spawn DHCPv6 via rtsold
124f961ddb2SColin Percival	echo 'ipv6_activate_all_interfaces="YES"' >> ${DESTDIR}/etc/rc.conf
125f961ddb2SColin Percival	echo 'rtsold_enable="YES"' >> ${DESTDIR}/etc/rc.conf
126f961ddb2SColin Percival	echo 'rtsold_flags="-M /usr/local/libexec/rtsold-M -a"' >> ${DESTDIR}/etc/rc.conf
127f961ddb2SColin Percival
128f961ddb2SColin Percival	# Provide a script which rtsold can use to launch DHCPv6
129f961ddb2SColin Percival	mkdir -p ${DESTDIR}/usr/local/libexec
130f961ddb2SColin Percival	cat > ${DESTDIR}/usr/local/libexec/rtsold-M <<'EOF'
131f961ddb2SColin Percival#!/bin/sh
132f961ddb2SColin Percival
133f961ddb2SColin Percival/usr/local/sbin/dhclient -6 -nw -N -cf /dev/null $1
134f961ddb2SColin PercivalEOF
135f961ddb2SColin Percival	chmod 755 ${DESTDIR}/usr/local/libexec/rtsold-M
136f961ddb2SColin Percival
137f961ddb2SColin Percival	return 0
138f961ddb2SColin Percival}
139