Custom iso with bsdinstall in FreeBSD

To build a custom iso, you will need to build from source. An easy way is to install with source or alternatively use svn to fetch source files. While using make command, ‘jX’ (X can be replaced by 4 or more depending upon the processor cores) parameter allows for speeding up of make by running multiple processes in parallel. Options for make can be explored using ‘man src.conf’[2]. For ex., if you are not interested in CLANG for the moment, use WITHOUT_CLANG flag. This could save upto 30 minutes if your build time.
# cd /usr/src
# make -j4 buildworld buildkernel
# cd /usr/src/release

Installation shell scripts are located at /usr/src/usr.sbin/bsdinstall/scripts/ . First file to run is ‘auto’, which then calls other files. To add extra files in the custom iso, include the filename in SCRIPTS section of /usr/src/usr.sbin/bsdinstall/Makefile and then upload the files to /usr/src/usr.sbin/bsdinstall/scripts/ [3]. A small tip: if you are including a .gz or .bz2  compressed file, it will be available to you in uncompressed format after installation in the bsdinstall directory (defaults to /usr/libexec/bsdinstall). Automating most of the tasks would involve modifying their respective shell scripts. The only exception I could see was the paritioning wizard which is written in C. I prefer to comment out the part which called the wizard and use the geom shell commands to directly create the basic partitions[4].

You do not need to repeat ‘make buildworld buildkernel’ if you are just making changes to the scripts file. I generally like to keep my custom iso as minimal as possible, so no docs, ports or src in the final iso[1].
# make release NODOC=YES NOPORTS=YES NOSRC=YES

Once the release has been built we now copy the iso, usb image, ftp files to the desired directory [5]
# make install DESTDIR=/usr/freebsd-snapshot clean

NOTES:
[1] release options:
http://www.freebsd.org/cgi/man.cgi?query=release&apropos=0&sektion=0&manpath=FreeBSD+9.1-RELEASE&arch=default&format=html

[2] src options:
http://www.freebsd.org/cgi/man.cgi?query=src.conf&apropos=0&sektion=0&manpath=FreeBSD+9.1-RELEASE&arch=default&format=html

[3] bsdinstall itself is not documented very well as of now. It is being worked upon, and will see a lot of changes in 9.2 release. Check out the mail from Devin in freebsd-questions mailing list:
http://lists.freebsd.org/pipermail/freebsd-questions/2012-December/247497.html

[4] How to use geom commands within the install process:
http://www.amitabhkant.com/partition-automation-in-bsdinstall-auto-script-in-freebsd/

[5] To write the memory stick image to a usb drive, FreeBSD docs now refer to:
https://launchpad.net/win32-image-writer/

One thought on “Custom iso with bsdinstall in FreeBSD

Comments are closed.