xref: /freebsd/release/tools/vagrant.conf (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# The default of 3GB is too small for Vagrant, so override the size here.
7export VMSIZE=8g
8
9# Packages to install into the image we're creating.  This is a deliberately
10# minimalist set, providing only the packages necessary to bootstrap.
11export VM_EXTRA_PACKAGES="${VM_EXTRA_PACKAGES} shells/bash \
12	firstboot-freebsd-update firstboot-pkgs"
13
14# Set to a list of third-party software to enable in rc.conf(5).
15export VM_RC_LIST="firstboot_freebsd_update firstboot_pkgs growfs"
16
17vagrant_common () {
18	# The firstboot_pkgs rc.d script will download the repository
19	# catalogue and install or update pkg when the instance first
20	# launches, so these files would just be replaced anyway; removing
21	# them from the image allows it to boot faster.
22	env ASSUME_ALWAYS_YES=yes pkg -c ${DESTDIR} clean -y -a
23	env ASSUME_ALWAYS_YES=yes pkg -c ${DESTDIR} delete -f -y pkg
24	rm ${DESTDIR}/var/db/pkg/repo-*.sqlite
25
26	# Vagrant instances use DHCP to get their network configuration.
27	echo 'ifconfig_DEFAULT="SYNCDHCP"' >> ${DESTDIR}/etc/rc.conf
28
29	# Enable sshd by default
30	echo 'sshd_enable="YES"' >> ${DESTDIR}/etc/rc.conf
31	# Disable DNS lookups by default to make SSH connect quickly
32	echo 'UseDNS no' >> ${DESTDIR}/etc/ssh/sshd_config
33
34	# Disable sendmail
35	echo 'sendmail_enable="NO"' >> ${DESTDIR}/etc/rc.conf
36	echo 'sendmail_submit_enable="NO"' >> ${DESTDIR}/etc/rc.conf
37	echo 'sendmail_outbound_enable="NO"' >> ${DESTDIR}/etc/rc.conf
38	echo 'sendmail_msp_queue_enable="NO"' >> ${DESTDIR}/etc/rc.conf
39
40	# Create the vagrant user with a password of vagrant
41	/usr/sbin/pw -R ${DESTDIR} \
42		groupadd vagrant -g 1001
43	chroot ${DESTDIR} mkdir -p /home/vagrant
44	/usr/sbin/pw -R ${DESTDIR} \
45		useradd vagrant \
46		-m -M 0755 -w yes -n vagrant -u 1001 -g 1001 -G 0 \
47		-c 'Vagrant User' -d '/home/vagrant' -s '/bin/csh'
48
49	# Change root's password to vagrant
50	echo 'vagrant' | /usr/sbin/pw -R ${DESTDIR} \
51		usermod root -h 0
52
53	# Configure sudo to allow the vagrant user
54	echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> ${DESTDIR}/usr/local/etc/sudoers
55
56	# Configure the vagrant ssh key
57	mkdir ${DESTDIR}/home/vagrant/.ssh
58	chmod 700 ${DESTDIR}/home/vagrant/.ssh
59	echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > ${DESTDIR}/home/vagrant/.ssh/authorized_keys
60	chown -R 1001 ${DESTDIR}/home/vagrant/.ssh
61	chmod 600 ${DESTDIR}/home/vagrant/.ssh/authorized_keys
62
63	# Reboot quickly, Don't wait at the panic screen
64	echo 'debug.trace_on_panic=1' >> ${DESTDIR}/etc/sysctl.conf
65	echo 'debug.debugger_on_panic=0' >> ${DESTDIR}/etc/sysctl.conf
66	echo 'kern.panic_reboot_wait_time=0' >> ${DESTDIR}/etc/sysctl.conf
67
68	# The console is not interactive, so we might as well boot quickly.
69	echo 'autoboot_delay="-1"' >> ${DESTDIR}/boot/loader.conf
70
71	# The first time the VM boots, the installed "first boot" scripts
72	# should be allowed to run:
73	# * growfs (expand the filesystem to fill the provided disk)
74	# * firstboot_freebsd_update (install critical updates)
75	# * firstboot_pkgs (install packages)
76	touch ${DESTDIR}/firstboot
77
78	return 0
79}
80