Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Mar 2013 13:50:50 +0000 (UTC)
From:      Nathan Whitehorn <nwhitehorn@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r248240 - in stable/9: release usr.sbin/bsdinstall usr.sbin/bsdinstall/partedit usr.sbin/bsdinstall/scripts
Message-ID:  <201303131350.r2DDoo7G044118@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: nwhitehorn
Date: Wed Mar 13 13:50:50 2013
New Revision: 248240
URL: http://svnweb.freebsd.org/changeset/base/248240

Log:
  MFC r245700,245701,245702,245706,245707,245758,245759,245760,245792,245796,
  245980,246013:
  
  Automated installation support for bsdinstall.

Added:
  stable/9/usr.sbin/bsdinstall/partedit/scripted.c
     - copied, changed from r245700, head/usr.sbin/bsdinstall/partedit/scripted.c
  stable/9/usr.sbin/bsdinstall/scripts/script
     - copied, changed from r245702, head/usr.sbin/bsdinstall/scripts/script
Modified:
  stable/9/release/rc.local
  stable/9/usr.sbin/bsdinstall/bsdinstall.8
  stable/9/usr.sbin/bsdinstall/partedit/Makefile
  stable/9/usr.sbin/bsdinstall/partedit/part_wizard.c
  stable/9/usr.sbin/bsdinstall/partedit/partedit.c
  stable/9/usr.sbin/bsdinstall/partedit/partedit.h
  stable/9/usr.sbin/bsdinstall/scripts/Makefile
  stable/9/usr.sbin/bsdinstall/scripts/wlanconfig
Directory Properties:
  stable/9/release/   (props changed)
  stable/9/usr.sbin/bsdinstall/   (props changed)
  stable/9/usr.sbin/bsdinstall/scripts/   (props changed)

Modified: stable/9/release/rc.local
==============================================================================
--- stable/9/release/rc.local	Wed Mar 13 13:45:47 2013	(r248239)
+++ stable/9/release/rc.local	Wed Mar 13 13:50:50 2013	(r248240)
@@ -45,6 +45,17 @@ else
 fi
 export TERM
 
+if [ -f /etc/installerconfig ]; then
+	bsdinstall script /etc/installerconfig
+	if [ $? -eq 0]; then
+		dialog --backtitle "FreeBSD Installer" --title "Complete" --no-cancel --ok-label "Reboot" --pause "Installation of FreeBSD complete! Rebooting in 10 seconds" 10 30 10
+		reboot
+	else
+		dialog --backtitle "FreeBSD Installer" --title "Error" --textbox /tmp/bsdinstall_log 0 0
+	fi
+	exit 
+fi
+
 dialog --backtitle "FreeBSD Installer" --title "Welcome" --extra-button --extra-label "Shell" --ok-label "Install" --cancel-label "Live CD" --yesno "Welcome to FreeBSD! Would you like to begin an installation or use the live CD?" 0 0
 
 case $? in

Modified: stable/9/usr.sbin/bsdinstall/bsdinstall.8
==============================================================================
--- stable/9/usr.sbin/bsdinstall/bsdinstall.8	Wed Mar 13 13:45:47 2013	(r248239)
+++ stable/9/usr.sbin/bsdinstall/bsdinstall.8	Wed Mar 13 13:50:50 2013	(r248240)
@@ -1,5 +1,5 @@
 .\"-
-.\" Copyright (c) 2011 Nathan Whitehorn <nwhitehorn@FreeBSD.org>
+.\" Copyright (c) 2011-2013 Nathan Whitehorn <nwhitehorn@FreeBSD.org>
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd June 11, 2011
+.Dd January 21, 2013
 .Dt BSDINSTALL 8
 .Os
 .Sh NAME
@@ -52,9 +52,10 @@ can be invoked separately by an installa
 .Sh TARGETS
 Most of the following targets are only useful for scripting the installer.
 For interactive use, most users will be interested only in the
-.Cm auto
+.Cm auto ,
+.Cm jail ,
 and
-.Cm jail
+.Cm script
 targets.
 .Bl -tag -width ".Cm jail Ar destination"
 .It Cm auto
@@ -68,6 +69,12 @@ Behavior is generally similar to
 .Cm auto ,
 except that disk partitioning and network setup are skipped and a kernel is
 not installed into the new system.
+.It Cm script Ar script
+Runs the installation script at
+.Pa script .
+See
+.Sx SCRIPTING
+for more information on this target.
 .It Cm keymap
 If the current controlling TTY is a
 .Xr syscons 4
@@ -104,11 +111,64 @@ partition schemes. Partitions disks, run
 .Xr newfs 8 ,
 and writes the new system's
 .Pa fstab .
+.It Cm scriptedpart Ar parameters
+Sets up disks like
+.Cm autopart
+and
+.Cm partedit ,
+but non-interactively according to the disk setup specified in
+.Ar parameters .
+Each disk setup is specified by a three-part argument:
+.Pp
+.Ar disk
+.Op Ar scheme
+.Op Ar {partitions}
+.Pp
+Multiple disk setups are separated by semicolons. The
+.Ar disk
+argument specifies the disk on which to operate (which will be erased),
+while the
+.Ar scheme
+argument specifies the
+.Xr gpart 8
+partition scheme to apply to the disk. If
+.Ar scheme
+is unspecified,
+.Cm scriptedpart
+will apply the default bootable scheme on your platform.
+The
+.Ar partitions
+argument is also optional and specifies how to partition
+.Ar disk .
+It consists of a comma-separated list of partitions to create enclosed in
+curly braces. Each partition declaration takes the form
+.Pp
+.Ar size
+.Ar type
+.Op Ar mount point
+.Pp
+.Ar size
+specifies the partition size to create in bytes (K, M, and G suffixes
+can be appended to specify kilobytes, megabytes, and gigabytes respectively),
+while the
+.Em auto
+keyword causes the partition to take all the remaining space on the disk. The
+.Ar type
+option chooses the
+.Xr gpart 8
+filesystem type (e.g. freebsd-ufs or freebsd-swap).
+The optional
+.Ar mount point
+argument sets where the created partition is to be mounted in the installed
+system. As an example, a typical invocation looks like:
+.Pp
+bsdinstall scriptedpart ada0 { 20G freebsd-ufs /, 4G freebsd-swap, 20G freebsd-ufs /var, auto freebsd-ufs /usr }
 .It Cm mount
 Mounts the file systems previously configured by
-.Cm autopart
+.Cm autopart ,
+.Cm partedit ,
 or
-.Cm partedit
+.Cm scriptedpart
 under
 .Ev BSDINSTALL_CHROOT .
 .It Cm distfetch
@@ -153,13 +213,27 @@ process. Many are used internally during
 default values for most installation scenarios. Others are set by various
 interactive user prompts, and can be usefully overridden when making scripted
 or customized installers.
-.Bl -tag -width ".Ev BSDINSTALL_DISTDIR"
+.Bl -tag -width ".Ev BSDINSTALL_DISTSITE"
 .It Ev DISTRIBUTIONS
 The set of distributions to install (e.g. "base kernel ports"). Default: none
 .It Ev BSDINSTALL_DISTDIR
 The directory in which the distribution files can be found (or to which they
 should be downloaded). Default:
 .Pa /usr/freebsd-dist
+.It Ev BSDINSTALL_DISTSITE
+URL from which the distribution files should be downloaded if they are not
+already present in the directory defined by
+.Ev BSDINSTALL_DISTDIR .
+This should be a full path to the files, including architecture and release
+names. Most targets (e.g.
+.Cm auto
+and
+.Cm jail )
+that prompt for a
+.Fx
+mirror will skip that step if this variable is already defined in the
+environment. Example:
+.Pa ftp://ftp.freebsd.org/pub/FreeBSD/releases/powerpc/powerpc64/9.1-RELEASE
 .It Ev BSDINSTALL_CHROOT
 The directory into which the distribution files should be unpacked and the
 directory at which the root file system of the new system should be mounted.
@@ -177,6 +251,67 @@ target is executed. If this directory do
 created. Default:
 .Pa /tmp/bsdinstall_etc
 .El
+.Sh SCRIPTING
+.Nm
+scripts consist of two parts: a
+.Em preamble
+and a
+.Em setup script .
+The preamble sets up the options for the installation (how to partition the
+disk[s], which distributions to install, etc.) and the optional second part is
+a shell script run under
+.Xr chroot 8
+in the newly installed system before
+.Nm
+exits. The two parts are separated by the usual script header (#!), which
+also sets the interpreter for the setup script.
+.Pp
+A typical bsdinstall script looks like this:
+.Bd -literal -offset indent
+PARTITIONS=ada0
+DISTRIBUTIONS="kernel.txz base.txz"
+
+#!/bin/sh
+echo "ifconfig_em0=DHCP" >> /etc/rc.conf
+echo "sshd_enable=YES" >> /etc/rc.conf
+pkg install puppet
+.Ed
+.Pp
+On
+.Fx
+release media, such a script placed at
+.Pa /etc/installerconfig
+will be run at boot time and the system will be rebooted automatically after
+the installation has completed. This can be used for unattended network
+installation of new systems; see
+.Xr diskless 8
+for details.
+.Ss PREAMBLE
+The preamble consists of installer settings. These control global installation
+parameters (see
+.Sx ENVIRONMENT VARIABLES )
+as well as disk partitioning. The preamble is interpreted as a
+.Xr sh 1
+script run at the very beginning of the install. If more complicated behavior
+than setting these variables is desired, arbitrary commands can be run here
+to extend the installer. In addition to the variables in
+.Sx ENVIRONMENT VARIABLES ,
+in particular
+.Ev DISTRIBUTIONS ,
+the preamble can contain a variable
+.Ev PARTITIONS
+which is passed to the
+.Cm scriptedpart
+target to control disk setup.
+.Ss SETUP SCRIPT
+Following the preamble is an optional shell script, beginning with a #!
+declaration. This script will be run at the end of the installation process
+inside a
+.Xr chroot 8
+environment in the newly installed system and can be used to set up
+configuration files, install packages, etc. Note that newly configured
+system services (e.g. networking) have not been started in the installed
+system at this time and only installation host services are available.
 .Sh HISTORY
 This version of
 .Nm

Modified: stable/9/usr.sbin/bsdinstall/partedit/Makefile
==============================================================================
--- stable/9/usr.sbin/bsdinstall/partedit/Makefile	Wed Mar 13 13:45:47 2013	(r248239)
+++ stable/9/usr.sbin/bsdinstall/partedit/Makefile	Wed Mar 13 13:50:50 2013	(r248240)
@@ -2,7 +2,8 @@
 
 BINDIR= /usr/libexec/bsdinstall
 PROG=	partedit
-LINKS= ${BINDIR}/partedit ${BINDIR}/autopart
+LINKS= ${BINDIR}/partedit ${BINDIR}/autopart \
+       ${BINDIR}/partedit ${BINDIR}/scriptedpart
 LDADD=	-lgeom -lncursesw -lutil -ldialog -lm
 
 PARTEDIT_ARCH= ${MACHINE}
@@ -14,7 +15,7 @@ PARTEDIT_ARCH= generic
 .endif
 
 SRCS=	diskeditor.c partedit.c gpart_ops.c partedit_${PARTEDIT_ARCH}.c \
-	part_wizard.c
+	part_wizard.c scripted.c
 
 WARNS?=	3
 NO_MAN=	true

Modified: stable/9/usr.sbin/bsdinstall/partedit/part_wizard.c
==============================================================================
--- stable/9/usr.sbin/bsdinstall/partedit/part_wizard.c	Wed Mar 13 13:45:47 2013	(r248239)
+++ stable/9/usr.sbin/bsdinstall/partedit/part_wizard.c	Wed Mar 13 13:50:50 2013	(r248240)
@@ -42,7 +42,6 @@
 
 static char *boot_disk(struct gmesh *mesh);
 static char *wizard_partition(struct gmesh *mesh, const char *disk);
-static int wizard_makeparts(struct gmesh *mesh, const char *disk);
 
 int
 part_wizard(void) {
@@ -71,7 +70,7 @@ startwizard:
 	dlg_put_backtitle();
 	error = geom_gettree(&mesh);
 
-	error = wizard_makeparts(&mesh, schemeroot);
+	error = wizard_makeparts(&mesh, schemeroot, 1);
 	if (error)
 		goto startwizard;
 	free(schemeroot);
@@ -168,12 +167,6 @@ provider_for_name(struct gmesh *mesh, co
 	struct ggeom *gp;
 
 	LIST_FOREACH(classp, &mesh->lg_class, lg_class) {
-		if (strcmp(classp->lg_name, "DISK") != 0 &&
-		    strcmp(classp->lg_name, "PART") != 0 &&
-		    strcmp(classp->lg_name, "RAID") != 0 &&
-		    strcmp(classp->lg_name, "MD") != 0)
-			continue;
-
 		LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
 			if (LIST_EMPTY(&gp->lg_provider))
 				continue;
@@ -288,8 +281,8 @@ query:
 	return (retval);
 }
 
-static int
-wizard_makeparts(struct gmesh *mesh, const char *disk)
+int
+wizard_makeparts(struct gmesh *mesh, const char *disk, int interactive)
 {
 	struct gmesh submesh;
 	struct gclass *classp;
@@ -310,7 +303,7 @@ wizard_makeparts(struct gmesh *mesh, con
 	pp = provider_for_name(mesh, disk);
 
 	available = gpart_max_free(gp, NULL)*pp->lg_sectorsize;
-	if (available < MIN_FREE_SPACE) {
+	if (interactive && available < MIN_FREE_SPACE) {
 		char availablestr[10], neededstr[10], message[512];
 		humanize_number(availablestr, 7, available, "B", HN_AUTOSCALE,
 		    HN_DECIMAL);

Modified: stable/9/usr.sbin/bsdinstall/partedit/partedit.c
==============================================================================
--- stable/9/usr.sbin/bsdinstall/partedit/partedit.c	Wed Mar 13 13:45:47 2013	(r248239)
+++ stable/9/usr.sbin/bsdinstall/partedit/partedit.c	Wed Mar 13 13:50:50 2013	(r248240)
@@ -96,13 +96,20 @@ main(int argc, const char **argv)
 		prompt = "Please review the disk setup. When complete, press "
 		    "the Finish button.";
 		part_wizard();
+	} else if (strcmp(basename(argv[0]), "scriptedpart") == 0) {
+		error = scripted_editor(argc, argv);
+		prompt = NULL;
+		if (error != 0) {
+			end_dialog();
+			return (error);
+		}
 	} else {
 		prompt = "Create partitions for FreeBSD. No changes will be "
 		    "made until you select Finish.";
 	}
 
 	/* Show the part editor either immediately, or to confirm wizard */
-	while (1) {
+	while (prompt != NULL) {
 		dlg_clear();
 		dlg_put_backtitle();
 
@@ -189,6 +196,15 @@ main(int argc, const char **argv)
 		free(items);
 	}
 	
+	if (prompt == NULL) {
+		error = geom_gettree(&mesh);
+		if (validate_setup()) {
+			error = apply_changes(&mesh);
+		} else {
+			gpart_revert_all(&mesh);
+			error = -1;
+		}
+	}
 
 	geom_deletetree(&mesh);
 	free(items);

Modified: stable/9/usr.sbin/bsdinstall/partedit/partedit.h
==============================================================================
--- stable/9/usr.sbin/bsdinstall/partedit/partedit.h	Wed Mar 13 13:45:47 2013	(r248239)
+++ stable/9/usr.sbin/bsdinstall/partedit/partedit.h	Wed Mar 13 13:50:50 2013	(r248240)
@@ -55,6 +55,8 @@ struct partition_metadata *get_part_meta
 void delete_part_metadata(const char *name);
 
 int part_wizard(void);
+int scripted_editor(int argc, const char **argv);
+int wizard_makeparts(struct gmesh *mesh, const char *disk, int interactive);
 
 /* gpart operations */
 void gpart_delete(struct gprovider *pp);

Copied and modified: stable/9/usr.sbin/bsdinstall/partedit/scripted.c (from r245700, head/usr.sbin/bsdinstall/partedit/scripted.c)
==============================================================================
--- head/usr.sbin/bsdinstall/partedit/scripted.c	Sun Jan 20 22:25:58 2013	(r245700, copy source)
+++ stable/9/usr.sbin/bsdinstall/partedit/scripted.c	Wed Mar 13 13:50:50 2013	(r248240)
@@ -45,12 +45,6 @@ provider_for_name(struct gmesh *mesh, co
 	struct ggeom *gp;
 
 	LIST_FOREACH(classp, &mesh->lg_class, lg_class) {
-		if (strcmp(classp->lg_name, "DISK") != 0 &&
-		    strcmp(classp->lg_name, "PART") != 0 &&
-		    strcmp(classp->lg_name, "RAID") != 0 &&
-		    strcmp(classp->lg_name, "MD") != 0)
-			continue;
-
 		LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
 			if (LIST_EMPTY(&gp->lg_provider))
 				continue;
@@ -81,6 +75,11 @@ part_config(char *disk, const char *sche
 		scheme = default_scheme();
 
 	error = geom_gettree(&mesh);
+	if (provider_for_name(&mesh, disk) == NULL) {
+		fprintf(stderr, "GEOM provider %s not found\n", disk);
+		geom_deletetree(&mesh);
+		return (-1);
+	}
 
 	/* Remove any existing partitioning and create new scheme */
 	LIST_FOREACH(classp, &mesh.lg_class, lg_class)
@@ -109,6 +108,11 @@ part_config(char *disk, const char *sche
 	error = geom_gettree(&mesh);
 
 	/* Create partitions */
+	if (config == NULL) {
+		wizard_makeparts(&mesh, disk, 0);
+		goto finished;
+	}
+
 	while ((partition = strsep(&config, ",")) != NULL) {
 		while ((ap = strsep(&partition, " \t\n")) != NULL) {
 			if (*ap == '\0')
@@ -131,6 +135,7 @@ part_config(char *disk, const char *sche
 		size = type = mount = NULL;
 	}
 
+finished:
 	geom_deletetree(&mesh);
 	free(disk);
 
@@ -177,7 +182,7 @@ int parse_disk_config(char *input)
 	} while (input != NULL && *input != 0);
 
 	if (disk != NULL)
-		part_config(disk, scheme, partconfig);
+		return (part_config(disk, scheme, partconfig));
 
 	return (0);
 }
@@ -186,7 +191,7 @@ int
 scripted_editor(int argc, const char **argv)
 {
 	char *token;
-	int i, len = 0;
+	int i, error = 0, len = 0;
 
 	for (i = 1; i < argc; i++)
 		len += strlen(argv[i]) + 1;
@@ -197,8 +202,11 @@ scripted_editor(int argc, const char **a
 		strcat(input, argv[i]);
 	}
 
-	while ((token = strsep(&input, ";")) != NULL)
-		parse_disk_config(token);
+	while ((token = strsep(&input, ";")) != NULL) {
+		error = parse_disk_config(token);
+		if (error != 0)
+			return (error);
+	}
 
 	return (0);
 }

Modified: stable/9/usr.sbin/bsdinstall/scripts/Makefile
==============================================================================
--- stable/9/usr.sbin/bsdinstall/scripts/Makefile	Wed Mar 13 13:45:47 2013	(r248239)
+++ stable/9/usr.sbin/bsdinstall/scripts/Makefile	Wed Mar 13 13:50:50 2013	(r248240)
@@ -2,7 +2,7 @@
 
 SCRIPTS= auto adduser checksum config docsinstall hostname jail keymap \
 	 mirrorselect mount netconfig netconfig_ipv4 netconfig_ipv6 rootpass \
-	 services time umount wlanconfig
+	 script services time umount wlanconfig
 BINDIR= /usr/libexec/bsdinstall
 
 NO_MAN=	true

Copied and modified: stable/9/usr.sbin/bsdinstall/scripts/script (from r245702, head/usr.sbin/bsdinstall/scripts/script)
==============================================================================
--- head/usr.sbin/bsdinstall/scripts/script	Mon Jan 21 01:01:32 2013	(r245702, copy source)
+++ stable/9/usr.sbin/bsdinstall/scripts/script	Wed Mar 13 13:50:50 2013	(r248240)
@@ -50,10 +50,8 @@ rm -rf $BSDINSTALL_TMPETC
 mkdir $BSDINSTALL_TMPETC
 
 split -a 2 -p '^#!.*' "$SCRIPT" /tmp/bsdinstall-installscript-
-cd /tmp
-echo BORK
 
-. bsdinstall-installscript-aa
+. /tmp/bsdinstall-installscript-aa
 : ${DISTRIBUTIONS="kernel.txz base.txz"}; export DISTRIBUTIONS
 export BSDINSTALL_DISTDIR
 
@@ -70,6 +68,11 @@ bsdinstall distextract
 # Finalize install
 bsdinstall config
 
+# Make sure networking is functional, if we can arrange that
+if [ ! -f $BSDINSTALL_CHROOT/etc/resolv.conf -a -f /etc/resolv.conf ]; then
+	cp /etc/resolv.conf $BSDINSTALL_CHROOT/etc/resolv.conf
+fi
+
 # Run post-install script
 if [ -f /tmp/bsdinstall-installscript-ab ]; then
 	cp /tmp/bsdinstall-installscript-ab $BSDINSTALL_CHROOT/tmp/installscript

Modified: stable/9/usr.sbin/bsdinstall/scripts/wlanconfig
==============================================================================
--- stable/9/usr.sbin/bsdinstall/scripts/wlanconfig	Wed Mar 13 13:45:47 2013	(r248239)
+++ stable/9/usr.sbin/bsdinstall/scripts/wlanconfig	Wed Mar 13 13:50:50 2013	(r248240)
@@ -60,7 +60,7 @@ NETWORKS=`echo "$SCAN_RESULTS" | awk -F 
    '/..:..:..:..:..:../ {if (length($5) > 0) printf("\"%s\"\t%s\n", $5, $4);}' |
    sort | uniq`
 
-if [ -z $NETWORKS ]; then
+if [ -z "$NETWORKS" ]; then
 	dialog --backtitle "FreeBSD Installer" --title "Error" \
 	    --yesno "No wireless networks were found. Rescan?" 0 0 && \
 	    exec $0 $@



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