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