xref: /freebsd/release/tools/gce.conf (revision 315ee00f)
1#!/bin/sh
2#
3#
4
5# The default of 3GB is too small for GCE, so override the size here.
6export VMSIZE=20g
7
8# Set to a list of packages to install.
9export VM_EXTRA_PACKAGES="${VM_EXTRA_PACKAGES} firstboot-freebsd-update \
10	firstboot-pkgs google-cloud-sdk panicmail sudo \
11	sysutils/py-google-compute-engine lang/python \
12	lang/python3"
13
14# Set to a list of third-party software to enable in rc.conf(5).
15export VM_RC_LIST="ntpd sshd growfs \
16	firstboot_pkgs firstboot_freebsd_update google_startup \
17	google_accounts_daemon google_clock_skew_daemon \
18	google_instance_setup google_network_daemon"
19
20vm_extra_install_base() {
21	echo 'search google.internal' > ${DESTDIR}/etc/resolv.conf
22	echo 'nameserver 169.254.169.254' >> ${DESTDIR}/etc/resolv.conf
23	echo 'nameserver 8.8.8.8' >> ${DESTDIR}/etc/resolv.conf
24}
25
26vm_extra_pre_umount() {
27	# Enable growfs on every boot, not only the first, as as instance's disk can
28	# be enlarged post-creation
29	sed -i -e '/KEYWORD: firstboot/d' /etc/rc.d/growfs
30
31	cat << EOF >> ${DESTDIR}/etc/rc.conf
32dumpdev="AUTO"
33ifconfig_DEFAULT="SYNCDHCP mtu 1460"
34ntpd_sync_on_start="YES"
35# need to fill in something here
36#firstboot_pkgs_list=""
37panicmail_autosubmit="YES"
38EOF
39
40	cat << EOF >> ${DESTDIR}/boot/loader.conf
41autoboot_delay="-1"
42beastie_disable="YES"
43loader_logo="none"
44hw.memtest.tests="0"
45console="comconsole,vidconsole"
46hw.vtnet.mq_disable=1
47kern.timecounter.hardware=ACPI-safe
48aesni_load="YES"
49nvme_load="YES"
50EOF
51
52	echo '169.254.169.254 metadata.google.internal metadata' >> \
53		${DESTDIR}/etc/hosts
54
55        # overwrite ntp.conf
56	cat << EOF > ${DESTDIR}/etc/ntp.conf
57server metadata.google.internal iburst
58
59restrict default kod nomodify notrap nopeer noquery
60restrict -6 default kod nomodify notrap nopeer noquery
61
62restrict 127.0.0.1
63restrict -6 ::1
64restrict 127.127.1.0
65EOF
66
67	cat << EOF >> ${DESTDIR}/etc/syslog.conf
68*.err;kern.warning;auth.notice;mail.crit                /dev/console
69EOF
70
71	cat << EOF >> ${DESTDIR}/etc/ssh/sshd_config
72KbdInteractiveAuthentication no
73X11Forwarding no
74AcceptEnv LANG
75AllowAgentForwarding no
76ClientAliveInterval 420
77EOF
78
79	cat << EOF >> ${DESTDIR}/etc/crontab
800       3       *       *       *       root    /usr/sbin/freebsd-update cron
81EOF
82
83	cat << EOF >> ${DESTDIR}/etc/sysctl.conf
84net.inet.icmp.drop_redirect=1
85net.inet.ip.redirect=0
86net.inet.tcp.blackhole=2
87net.inet.udp.blackhole=1
88kern.ipc.soacceptqueue=1024
89debug.trace_on_panic=1
90debug.debugger_on_panic=0
91EOF
92
93	# To meet GCE marketplace requirements, extract the src.txz and
94	# ports.txz distributions to the target virtual machine disk image
95	# and fetch the sources for the third-party software installed on
96	# the image.
97	if [ ! -c "${DESTDIR}/dev/null" ]; then
98		mkdir -p ${DESTDIR}/dev
99		mount -t devfs devfs ${DESTDIR}/dev
100	fi
101	if [ -e "${DESTDIR}/../ftp/src.txz" ]; then
102		tar fxJ ${DESTDIR}/../ftp/src.txz -C ${DESTDIR}
103	fi
104	if [ -e "${DESTDIR}/../ftp/ports.txz" ]; then
105		tar fxJ ${DESTDIR}/../ftp/ports.txz -C ${DESTDIR}
106		_INSTALLED_PACKAGES=$(chroot ${DESTDIR} pkg info -o -q -a)
107		for PACKAGE in ${_INSTALLED_PACKAGES}; do
108			chroot ${DESTDIR} \
109				make -C /usr/ports/${PACKAGE} fetch
110		done
111	fi
112	if [ -c "${DESTDIR}/dev/null" ]; then
113		umount_loop ${DESTDIR}/dev
114	fi
115
116	## XXX: Verify this is needed.  I do not see this requirement
117	## in the docs, and it impairs the ability to boot-test a copy
118	## of the image prior to packaging for upload to GCE.
119	#sed -E -i '' 's/^([^#].*[[:space:]])on/\1off/' ${DESTDIR}/etc/ttys
120
121	touch ${DESTDIR}/firstboot
122
123	rm -f ${DESTDIR}/etc/resolv.conf
124
125	return 0
126}
127