1

I am using Debian preseed to build a "base" linux OS in which I have created a 'firstboot.service', to run on first-boot, to set device specific settings - ie host name. I am distributing the base image via clonezilla to individual kiosks, not running preseed on each device.

To force the first boot ConditionFirstBoot=true I remove the file /etc/machine-id in the last step before I create my clonezille image.

How can I reboot the kiosk automatically from my firstboot script once the customisations is complete? I need to do this a lightdm does not automatically login until a reboot after my customisations - ie hostname.

I have tried to force a reboot but it does not work and I get an error.

How do I perform a reboot from a first boot script?

Firstboot.service contents /lib/systemd/system/firstboot.service

[Unit]
Description=FirstBootSetup
ConditionFirstBoot=true

[Service]
Type=idle
RemainAfterExit=yes
ExecStart=/bin/bash /root/firstboot.bash

[Install]
WantedBy=multi-user.target

Script run by firstboot.service /root/firstboot.bash

systemd-machine-id-setup
hostname "RANDOM"

if [ -f /etc/machine-id ]; then
  systemctl --force --force reboot
endif

systemctl status firstboot

systemctl status firstboot
firstboot.service - FirstBootSetup
Loaded: loaded (/lib/systemd/system/firstboot.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2019-02-07 11:41:45 AEST; 1h 00min ago
Process: 562 ExecStart=/bin/bash /root/firstboot.bash (code=exited, status=2)
 Main PID: 562 (code=exited, status=2)

closed as off-topic by Rui F Ribeiro, terdon Feb 7 at 9:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Rui F Ribeiro, terdon
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Could you use just: shutdown -r now? – Michael Prokopec Feb 7 at 5:28
  • The end of your if statement in the bash script looks wrong. It should end with fi not endif. – Peschke Feb 7 at 6:07
2

It turned out that the shell script was syntactically incorrect and the shell was simply not running the commands. As mentioned in a question comment, it should have fi where it actually had endif.

  • @jimmij this is the only answer the question could have. Why would it not be an answer? – terdon Feb 7 at 9:12
  • @jimmij ah, sorry, just checked the review history. You're quite right. – terdon Feb 7 at 9:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.