firstboot

balanga

Son of Beastie

Reaction score: 118
Messages: 2,894

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?
 

Phishfry

Son of Beastie

Reaction score: 1,335
Messages: 3,965

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
 
OP
OP
B

balanga

Son of Beastie

Reaction score: 118
Messages: 2,894

It would be useful to see an example of such an rc.d script.
 
OP
OP
B

balanga

Son of Beastie

Reaction score: 118
Messages: 2,894

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..
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 7,540
Messages: 30,244

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.
 
OP
OP
B

balanga

Son of Beastie

Reaction score: 118
Messages: 2,894

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
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 7,540
Messages: 30,244

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.
 
OP
OP
B

balanga

Son of Beastie

Reaction score: 118
Messages: 2,894

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?
 
OP
OP
B

balanga

Son of Beastie

Reaction score: 118
Messages: 2,894

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.
 

Phishfry

Son of Beastie

Reaction score: 1,335
Messages: 3,965

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.
 
OP
OP
B

balanga

Son of Beastie

Reaction score: 118
Messages: 2,894

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.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 7,540
Messages: 30,244

That will actually install mc every time you boot the system.
 

Phishfry

Son of Beastie

Reaction score: 1,335
Messages: 3,965

So his script is missing the delete sentinel step.
rm /firstboot
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 7,540
Messages: 30,244

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.
 
OP
OP
B

balanga

Son of Beastie

Reaction score: 118
Messages: 2,894

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...
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 7,540
Messages: 30,244

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).
 
Top