firstboot

I recently became aware of the firstboot option for rc scripts but The Handbook does not mention anything about the option as far as I can see.

Where would I find any documentation on how to use this?

And would it be possible to install various pkgs as part of a first boot?
 
firstboot is a zero K file which resides in the root directory. It acts as a sentinel for rc.d scripts with the KEYWORD= firstboot
sysutils/firstboot-pkgs/

firstboot_sentinel
(str) This variable specifies the full path to a ``first
boot''sentinel file.If a file exists with this path, rc.d
scripts with the ``firstboot'' keyword will be run on startup
and the sentinel file will be deleted after the boot process
completes. The sentinel file must be located on a writable
file system which is mounted no later than early_late_divider
to function properly.The default is /firstboot.

https://www.freebsd.org/cgi/man.cgi?query=rc.conf
 
So it's basically a single file..../usr/local/etc/rc.d/firstpoot_pkgs...

I'll see if I can incorporate it into a new install script I'm working on..
 
It's really easy to use, I've used a couple of those firstboot-* ports for deployment on AWS.

If you want to test it, simply create a file /firstboot: touch /firstboot. This is the trigger for those scripts, if that file exists the scripts are run and the firstboot file is removed afterwards.
 
in /usr/local/etc/rc.d/firstboot_pkgs

it says to set 'firstboot_pkgs_enable="YES" so is that an alternative to touch /firstboot or in addition to?

Also, not entirely what 'firstboot-* ports' refers to
 
it says to set 'firstboot_pkgs_enable="YES" so is that an alternative to touch /firstboot or in addition to?
No, they both need to be set. The firstboot_pkgs_enable is to ensure the rc(8) script is executed but the script is only functional if the /firstboot file exists. This file is removed after the first boot. On consecutive boots the script is still active and started (due to the *_enable in rc.conf) but won't do anything because the /firstboot file doesn't exist anymore.
 
Steps to install www/apache24 on first boot...
Code:
touch /firstboot
sysrc firstboot_pkgs_enable=YES
echo 'firstboot_pkgs_list="apache24"' >>/etc/rc.conf
cp firstboot_pkgs /etc/rc.d
Is this more or less it? Are any changes to sysutils/firstboot-pkgs required?

A year later, I can't workout how this works... I thought I understood at the time....

I get this bit:-

Code:
touch /firstboot
sysrc firstboot_pkgs_enable=YES
echo 'firstboot_pkgs_list="apache24"' >>/etc/rc.conf

but can't figure out what this is supposed to do:-
Code:
cp firstboot_pkgs /etc/rc.d

My idea is to automatically install some packages on first boot, ie before pkg has even been installed. It looks like I need something like pkg bootstrap first but that always causes a prompt which I'm trying to avoid as this is meant to be an automated process.
 
I am not sure where you came up with that line. SirDice pretty much snuffed that out in post#11
cp firstboot_pkgs /etc/rc.d

From the rc.d script itself:
Code:
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf (in the disk
# image, since this only runs on the first boot) to enable this:
#
# firstboot_pkgs_enable="YES"
#
# and place a list of packages in firstboot_pkgs_list, e.g.,
#
# firstboot_pkgs_list="apache22 php5 mysql56-server"

Unattended package installing could be tough because of pkg prompts (Y)
Let us know how you make out.
First off I would start with something small with few dependencies. Get a hang for how it works.

Obviously, this port is not useful after a system is already running; it is
intended to be included as part of the installation or disk image building
process.
 
Unattended package installing could be tough because of pkg prompts (Y)
Let us know how you make out.
First off I would start with something small with few dependencies. Get a hang for how it works.

Managed to crack it after many attempts/hours using the following code, slightly amended... (/mnt) is the mounted partition where FreeBSD is being installed..

Code:
touch /mnt/firstboot
cat <<EOF  >> /mnt/etc/rc.d/firstboot
env ASSUME_ALWAYS_YES=YES pkg bootstrap
pkg install -y mc
EOF

misc/mc will be installed on first boot.
 
It's not the script's job to remove the sentinel (it's done at the end of /etc/rc). Besides that, it would still get executed with each boot. It's missing the rcorder(8) KEYWORD for example.
 
That will actually install mc every time you boot the system.

The sentinel file created is /firstboot and this gets deleted at the end of the 'firstboot' process. The script itself - /etc/rc.d/firstboot remains but will not get invoked because the sentinel file no longer exists.

For the sake of tidying things up, maybe I should delete the script by including rm /etc/rc.d/firstboot as the last command in the script, although I'm not sure if you can delete a script which is currently running...
 
The script itself - /etc/rc.d/firstboot remains but will not get invoked because the sentinel file no longer exists.
The script would be invoked every time regardless if the sentinel exists or not, because there's nothing limiting it to the firstboot only. See rc(8).
 
Revisiting an old topic which I never fully understood, I came across this article which helped me understand how it holds together:-

https://reviews.freebsd.org/D14275

The suggestion was to add firstboot-pkgs work into the base system, which makes a lot of sense, because you have a catch-22 situation in that, AFAICS BICBW, you need to pkg install sysutils/firstboot-pkgs before the first boot!!!

I could never get my head around this and couldn't see how it could work.
 
Back
Top