Custom Installation Script

0badc0de

Cadet
Joined
Nov 14, 2022
Messages
2
Hi all.
I would like to create an installation script so that it is run during/after installation in order to get a repeatable/automatable initial setup.
Of course I can do a plain setup, copy the script to the target (via SSH, SFTP ...) and run it from console.
Is there a way to "supplement" the installation medium (ISO) so I can have that script installed and run without any intervention?
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
I would like to create an installation script so that it is run during/after installation in order to get a repeatable/automatable initial setup.
Of course I can do a plain setup, copy the script to the target (via SSH, SFTP ...) and run it from console.

Or use the API. Which is, I think, what they expect you to do.

Is there a way to "supplement" the installation medium (ISO) so I can have that script installed and run without any intervention?

Sure. Pull apart the ISO and stick whatever you'd like in at some judicious point. This could be postinstall or at firstboot (see the hooks built into the installed system's /etc/rc to handle firstboot scripts). I've been doing this long enough that I picked the third (no longer strictly necessary) option of inserting stuff into the installer's rc.local in place of the bsdinstall call. That works fine for generic FreeBSD. Basically you'll want to look at the source code for the installer and see what makes the most sense.
 

0badc0de

Cadet
Joined
Nov 14, 2022
Messages
2
Or use the API. Which is, I think, what they expect you to do.

First of all, thanks a lot for the reply @jgreco.

I think I can use API only once the installation is over with full network services set up.
Which could be part of th things I need to customize at installation.
Anyway, I will look into that option too, indeed.

Sure. Pull apart the ISO and stick whatever you'd like in at some judicious point. This could be postinstall or at firstboot (see the hooks built into the installed system's /etc/rc to handle firstboot scripts). I've been doing this long enough that I picked the third (no longer strictly necessary) option of inserting stuff into the installer's rc.local in place of the bsdinstall call. That works fine for generic FreeBSD. Basically you'll want to look at the source code for the installer and see what makes the most sense.

Unluckily I am not a *BSD guy, but more a Linux one. Do we have any documentation on where those " judicious points" are located?
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
I think I can use API only once the installation is over with full network services set up.

I'm pretty sure the API is up by default after firstboot. You don't need to set up any additional services, as far as I know. (I don't actually use the API though so this is secondhand data)

Unluckily I am not a *BSD guy, but more a Linux one. Do we have any documentation on where those " judicious points" are located?

This has very little to do with Linux or BSD. It's really a UNIX scripting issue. There's not going to be any documentation on "judicious points" because there's probably at least a few dozen ways to do this, and probably only a handful of people who actually do this sort of work. You basically take the thing apart and "break" it in a way that causes it to do what you want.

For example,

Code:
# mdconfig FreeBSD-13.0-RELEASE-i386-disc1.iso
md0
# mkdir /tmp/x
# mount -t cd9660 /dev/md0 /tmp/x
# cat /tmp/x/etc/rc.local
[...]
        trap true SIGINT        # Ignore cntrl-C here
        bsdinstall
        if [ $? -eq 0 ]; then
                dialog --backtitle "FreeBSD Installer" --title "Complete" --yes-label "Reboot" --no-label "Live CD" --yesno "Installation of FreeBSD complete! Would you like to reboot into the installed system now?" 0 0 && reboot
        else
                . /etc/rc.local
        fi
[...]


This is a handy point in a standard FreeBSD OS install where you can intercept the launch of the installer and replace it with something else -- in our case over here, it's our automated no-keystroke system installer. In your case if you just want to twiddle settings, you might go right after bsdinstall.

Of course, this is probably going to be different for TrueNAS. But my point is that this stuff is mostly scripting. People are afraid to take it apart and make it their own. Don't be. It can be work, even significant work, but automation is a blast.
 
Top