[Midnightbsd-cvs] src [8947] trunk/usr.sbin/bsdinstall: add automated install support based on FreeBSD 9.2 code.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Mon Sep 26 19:23:51 EDT 2016
Revision: 8947
http://svnweb.midnightbsd.org/src/?rev=8947
Author: laffer1
Date: 2016-09-26 19:23:51 -0400 (Mon, 26 Sep 2016)
Log Message:
-----------
add automated install support based on FreeBSD 9.2 code.
Modified Paths:
--------------
trunk/usr.sbin/bsdinstall/bsdinstall.8
trunk/usr.sbin/bsdinstall/partedit/Makefile
trunk/usr.sbin/bsdinstall/partedit/part_wizard.c
trunk/usr.sbin/bsdinstall/partedit/partedit.c
trunk/usr.sbin/bsdinstall/partedit/partedit.h
trunk/usr.sbin/bsdinstall/scripts/Makefile
trunk/usr.sbin/bsdinstall/scripts/wlanconfig
Modified: trunk/usr.sbin/bsdinstall/bsdinstall.8
===================================================================
--- trunk/usr.sbin/bsdinstall/bsdinstall.8 2016-09-26 23:20:46 UTC (rev 8946)
+++ trunk/usr.sbin/bsdinstall/bsdinstall.8 2016-09-26 23:23:51 UTC (rev 8947)
@@ -1,5 +1,5 @@
.\"-
-.\" Copyright (c) 2011 Nathan Whitehorn <nwhitehorn at FreeBSD.org>
+.\" Copyright (c) 2011-2013 Nathan Whitehorn <nwhitehorn at FreeBSD.org>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@@ -26,7 +26,7 @@
.\" $MidnightBSD: src/usr.sbin/bsdinstall/bsdinstall.8,v 1.2 2013/01/19 23:43:37 laffer1 Exp $
.\" $FreeBSD: src/usr.sbin/bsdinstall/bsdinstall.8,v 1.2 2011/06/12 15:19:38 nwhitehorn Exp $
.\"
-.Dd June 11, 2011
+.Dd January 21, 2013
.Dt BSDINSTALL 8
.Os
.Sh NAME
@@ -53,9 +53,10 @@
.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
@@ -69,6 +70,12 @@
.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
@@ -105,11 +112,64 @@
.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
@@ -154,7 +214,7 @@
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
@@ -161,6 +221,20 @@
The directory in which the distribution files can be found (or to which they
should be downloaded). Default:
.Pa /usr/midnightbsd-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
+.Mx
+mirror will skip that step if this variable is already defined in the
+environment. Example:
+.Pa ftp://ftp.midnightbsd.org/pub/MidnightBSD/releases/i386/0.8-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.
@@ -178,6 +252,67 @@
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: trunk/usr.sbin/bsdinstall/partedit/Makefile
===================================================================
--- trunk/usr.sbin/bsdinstall/partedit/Makefile 2016-09-26 23:20:46 UTC (rev 8946)
+++ trunk/usr.sbin/bsdinstall/partedit/Makefile 2016-09-26 23:23:51 UTC (rev 8947)
@@ -3,7 +3,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}
@@ -15,7 +16,7 @@
.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: trunk/usr.sbin/bsdinstall/partedit/part_wizard.c
===================================================================
--- trunk/usr.sbin/bsdinstall/partedit/part_wizard.c 2016-09-26 23:20:46 UTC (rev 8946)
+++ trunk/usr.sbin/bsdinstall/partedit/part_wizard.c 2016-09-26 23:23:51 UTC (rev 8947)
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD: src/usr.sbin/bsdinstall/partedit/part_wizard.c,v 1.2 2012/01/27 04:53:26 laffer1 Exp $
+ * $MidnightBSD$
* $FreeBSD: src/usr.sbin/bsdinstall/partedit/part_wizard.c,v 1.6 2011/10/07 01:40:30 nwhitehorn Exp $
*/
@@ -43,7 +43,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) {
@@ -72,7 +71,7 @@
dlg_put_backtitle();
error = geom_gettree(&mesh);
- error = wizard_makeparts(&mesh, schemeroot);
+ error = wizard_makeparts(&mesh, schemeroot, 1);
if (error)
goto startwizard;
free(schemeroot);
@@ -169,12 +168,6 @@
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;
@@ -289,8 +282,8 @@
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;
@@ -311,7 +304,7 @@
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: trunk/usr.sbin/bsdinstall/partedit/partedit.c
===================================================================
--- trunk/usr.sbin/bsdinstall/partedit/partedit.c 2016-09-26 23:20:46 UTC (rev 8946)
+++ trunk/usr.sbin/bsdinstall/partedit/partedit.c 2016-09-26 23:23:51 UTC (rev 8947)
@@ -97,6 +97,13 @@
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 MidnightBSD. No changes will be "
"made until you select Finish.";
@@ -103,7 +110,7 @@
}
/* Show the part editor either immediately, or to confirm wizard */
- while (1) {
+ while (prompt != NULL) {
dlg_clear();
dlg_put_backtitle();
@@ -190,6 +197,15 @@
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: trunk/usr.sbin/bsdinstall/partedit/partedit.h
===================================================================
--- trunk/usr.sbin/bsdinstall/partedit/partedit.h 2016-09-26 23:20:46 UTC (rev 8946)
+++ trunk/usr.sbin/bsdinstall/partedit/partedit.h 2016-09-26 23:23:51 UTC (rev 8947)
@@ -56,6 +56,8 @@
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);
Modified: trunk/usr.sbin/bsdinstall/scripts/Makefile
===================================================================
--- trunk/usr.sbin/bsdinstall/scripts/Makefile 2016-09-26 23:20:46 UTC (rev 8946)
+++ trunk/usr.sbin/bsdinstall/scripts/Makefile 2016-09-26 23:23:51 UTC (rev 8947)
@@ -1,9 +1,9 @@
-# $MidnightBSD: src/usr.sbin/bsdinstall/scripts/Makefile,v 1.1 2011/12/24 06:24:01 laffer1 Exp $
+# $MidnightBSD$
# $FreeBSD: src/usr.sbin/bsdinstall/scripts/Makefile,v 1.5 2011/07/09 23:01:54 nwhitehorn Exp $
SCRIPTS= auto adduser checksum config 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
Modified: trunk/usr.sbin/bsdinstall/scripts/wlanconfig
===================================================================
--- trunk/usr.sbin/bsdinstall/scripts/wlanconfig 2016-09-26 23:20:46 UTC (rev 8946)
+++ trunk/usr.sbin/bsdinstall/scripts/wlanconfig 2016-09-26 23:23:51 UTC (rev 8947)
@@ -61,7 +61,7 @@
'/..:..:..:..:..:../ {if (length($5) > 0) printf("\"%s\"\t%s\n", $5, $4);}' |
sort | uniq`
-if [ -z $NETWORKS ]; then
+if [ -z "$NETWORKS" ]; then
dialog --backtitle "MidnightBSD Installer" --title "Error" \
--yesno "No wireless networks were found. Rescan?" 0 0 && \
exec $0 $@
More information about the Midnightbsd-cvs
mailing list