6 Automatic installation

If you are going to set up a large number or servers with the same base installation, you'll quickly get tired of navigating the sysinstall menus. sysinstall can be scripted, this section show you how. By the end of the section, all you need to do is to plug in your new machine and drink coffee.

6.1 Scripting sysinstall

sysinstall(8) will first look for the file /install.cfg on the root file system which sets installation parameters. This file can also be used to script sysinstall. When the execution exits, sysinstall will return to the interactive mode.

Hence, to automate the installation we need to create install.cfg and place it in the root of the memory filesystem we created. The syntax, variables and commands are described in sysinstall(8), however not all variables and commands are documented, for theese, we need to take a look at the source code also. Also a sample install.cfg is given in the source code directory, /usr/src/usr.sbin/sysinstall.

One important thing is that /install.cfg is read and executed strictly top down, variables must be set before the function using them.

If anything fails in the script, sysinstall will abort the rest of the script and go interactive.

################################
# install.cfg for jumpstart of FreeBSD
#
# See sysinstall(8) for details about how to script the process
# This file has been edited from /usr/src/usr.sbin/sysinstall/install.cfg
# Turn on extra debugging.
debug=YES
nonInteractive=YES
noConfirm=YES
noWarn=NO
################################

We don't want any interactive questioning, the whole point is to power up the machine and drink coffee. But we do like to have some debug information for when we get back and everything has failed misserably.

################################
# Disk partitioning
#
# WARNING: This will format the disk and dedicate the entire disk to
#          FreeBSD
disk=ad0
partition=all
bootManager=none
diskPartitionEditor
################################

This section selects a disk and creates the partitions. Multiple disks can be partitioned but you must end each disk defintion with diskPartitionEditor.

Note: The sample install.cfg provided with sysinstall source sets partition to exclusive, this will set your disk in "dangerously dedicated" mode which is not recommended unless you really need it.

################################
# Disk labeling
#
# All sizes are expressed in 512 byte blocks!
#
# For example:
# / 512MB, swap 512MB, /usr 8192MB, /var 8192MB, /home remaining
ad0s1-1=ufs  1048576 /
ad0s1-2=swap 1048576 none
ad0s1-3=ufs 16777216 /usr
ad0s1-4=ufs 16777216 /var 
ad0s1-5=ufs  1048576 /tmp
ad0s1-6=ufs        0 /home 1
diskLabelEditor
################################

This section slices up the chosen diskpartitions. The line labeling /home is special, this will use any remaining space, so it must be last.

################################
# Host specific configuration:
tryDHCP=YES
netDev=vr0
# The following optional if using dhcp to configure the network
hostname=jumpstart
domainname=example.com
################################

Apparently sysinstall suffers from amnesia when it comes to the network configuration. Even though the network was configured on boot, sysinstall will need a network configuration as above unless you are installing from a disk.

This should be a general configuration file and all host configuration should be done with dhcp. For unknown reason, hostname is required even if passed with dhcp.

################################
# Select release to install
#
releaseName 6.1-RELEASE
################################

This section defines the release and which collection of packages and sources to install. releaseName is by default determined by the release of the kernel and sysinstall will then look for a directory of that name when fetching the relase. If you cvsup'ed your sources before building the custom kernel, releaseName may be x.x-STABLE or x.x-CURRENT, but there are no such releases, so we need to specify it here.

################################
# Set distribution to install, either use distSetCustom and choose
# individual components or choose a collection, for example
# distSetKernDeveloper which installs base and kernel sources
distSetKernDeveloper
################################

FreeBSD has some predefined distributions you can choose: distSetMinimum, distSetUser, distSetXUser, distSetKernDeveloper, distSetXKernDeveloper, distSetDeveloper, distSetXDeveloper and distSetEverything. You can also customize defining the variable dists and then use distSetCustom.

Note: Some have reported problem using the custom distribution, that the kernel is not correctly installed. A work around is to install the minimal distribution and commit it, then select custom and commit that.

################################
# Select installation method
# 
# We want an FTP install, so we also need to specify the ftp server to
# fetch from
netDev=vr0
tryDHCP=YES
_ftpPath=ftp://ftp.example.com/pub/FreeBSD
mediaSetFTP
################################

Again (!?) we need to specify the interface we want to use and configure it using dhcp. For ftp installation we must specify a server and path to the selected release. You can always check the release announcement for a list of available ftp servers, if you do not set up your own. With the above settings, sysinstall will fetch the release from this directory:

ftp://ftp.example.com/pub/FreeBSD/releases/i386/6.1-RELEASE

That is, sysinstall assumes the release files are found in the subdirectory releases/<architecture>/<releaseName> in the ftp-path.

At this point, your old disk is still alive and happy, the next section will commit everything to the disk, and we have set noConfirm!

################################
#
# OK, everything is set.  Do it!
installCommit
################################

You can customize further after install commit setting the variable package to any package you'd like installed and followed by the command packageAdd. At this point, when installation is finnished it will return to the well known sysinstall menu to allow you to add any further customization. To avoid this end the install.cfg with the command shutdown(8). It may be better though, if you compiled your memory disk with halt(8) to terminate the installation with system halt -p.

If everything works well, simply power up your system, is should be busy installing installing and you busy drinking coffee :-)

6.2 Customization

It is a bit tiresome to change the install.cfg if it is located on the memory disk. If you created a custom memory file system with support for the ftp(1) command, then could create a minimal install.cfg and then fetch one to be included like this:

################################
# Host specific configuration:
tryDHCP=YES
netDev=vr0
# The following optional if using dhcp to configure the network
hostname=jumpstart
domainname=example.com
################################
system /bin/ftp ftp://ftp.example.com/pub/FreeBSD/jumpstart.cfg
loadConfig jumpstart.cfg
 

This should configure the network interface and fetch the installation configuration file (altough I have not tested it yet). Furter scripting is posible, and you can also change loader.conf to run init(8) instead and script everything - the limits are given by the commands available on the root file system.

This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.

For questions about FreeBSD, read the documentation before contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.