Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 Oct 2013 15:58:23 -0700
From:      Colin Percival <cperciva@freebsd.org>
To:        FreeBSD current <freebsd-current@freebsd.org>,  freebsd-rc@freebsd.org
Subject:   RFC: support for "first boot" rc.d scripts
Message-ID:  <525B258F.3030403@freebsd.org>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------040902090405000607020909
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hi all,

I've attached a very simple patch which makes /etc/rc:

1. Skip any rc.d scripts with the "firstboot" keyword if /var/db/firstboot
does not exist,

2. If /var/db/firstboot and /var/db/firstboot-reboot exist after running rc.d
scripts, reboot.

3. Delete /var/db/firstboot (and firstboot-reboot) after the first boot.

The purpose of this is to support "run on first boot" rc.d scripts.  These can
be useful for both virtual machines and embedded systems; unlike conventional
desktops and servers, these may have a lengthy gap between "installing" and
"turning on" the system.

As examples of what such scripts could do:

* In Amazon EC2, I use a "first boot" script to download an SSH public key
from EC2 so that users can log in to newly provisioned EC2 instances.

* Now that (starting from 10.0-BETA1) it is possible to use FreeBSD Update
to update everything on EC2 instances, I'm planning on writing a script which
runs 'freebsd-update fetch install' when the system first boots, and then
reboots if there were updates installed.  (I imagine this would be useful
to other embedded / VM providers too.)

* Once packages are provided (properly) for 10.0 I'd like to allow people to
specify a list of packages they want installed onto an EC2 instance and have
them downloaded and installed when the EC2 instance launches.

I'd like to get this into HEAD in the near future in the hope that I can
convince re@ that this is a simple enough (and safe enough) change to merge
before 10.0-RELEASE.

Comments?

-- 
Colin Percival
Security Officer Emeritus, FreeBSD | The power to serve
Founder, Tarsnap | www.tarsnap.com | Online backups for the truly paranoid

--------------040902090405000607020909
Content-Type: text/plain; charset=us-ascii;
 name="firstboot.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="firstboot.patch"

Index: etc/rc
===================================================================
--- etc/rc	(revision 256432)
+++ etc/rc	(working copy)
@@ -81,6 +81,9 @@
 		skip="$skip -s nojailvnet"
 	fi
 fi
+if ! [ -e /var/db/firstboot ]; then
+	skip="$skip -s firstboot"
+fi
 
 # Do a first pass to get everything up to $early_late_divider so that
 # we can do a second pass that includes $local_startup directories
@@ -116,6 +119,13 @@
 	run_rc_script ${_rc_elem} ${_boot}
 done
 
+if [ -e /var/db/firstboot ]; then
+	rm /var/db/firstboot
+	if [ -e /var/db/firstboot-reboot ]; then
+		rm /var/db/firstboot-reboot
+		kill -INT 1
+	fi
+fi
 echo ''
 date
 exit 0

--------------040902090405000607020909--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?525B258F.3030403>