raspberian-firstboot
raspberian-firstboot copied to clipboard
How to reboot after firstboot?
This project is awesome and I can't thank you enough for also providing the patched Raspberry Pi OS images. I have no understanding why something like this isn't in the official images since years, and is still being refused to be added.
While loving raspberian-firstboot
, I'm fighting with rebooting the system after executing my firstboot.sh
script. I assume this could be a generally useful case, reboot after setup.
The issue is that when we just invoke reboot
shutdown -r now
, the system reboots without completing systemd
's firstboot.service
. Hence the firstboot.sh
file doesn't get removed and will be executed again.
All my attempts to use a delayed reboot with something like
-
nohup sh -c "sleep 3 && touch /boot/reboot && reboot" > /dev/null 2>&1 &
-
setsid sh -c "sleep 3 && touch /boot/reboot && reboot" > /dev/null 2>&1 &
failed. The commands don't seem to be executed.
The only thing that worked is shutdown -r +1
, but that takes 1 full minute to reboot. 1 minute is the smallest time unit, unfortunately.
Is there anything that can be done about making it possible to reboot after successful script execution?
Wow, I tried so long, but after compiling my issue description above I found a way which works: systemd-run
.
systemd-run --no-block sh -c "sleep 3 && touch /boot/reboot && reboot"
(the --no-block
option shouldn't actually be necessary, but also doesn't hurt).
I'm not sure if this is the best usage of systemd-run
. But if you like it and don't know of any better canonical solution, I'd be happy to contribute an example to the repo.
This is a great solution! Please send a PR and I will merge it right away. THANK YOU @janoskut!!
Oh my god I'm so sorry that this has slipped through my attention! I added a PR in #16 , but that's just a snippet from what I came up with back then. I better give it another test next day.
I found a Stack Exchange thread that gave this code:
sync
umount /boot
mount / -o remount,ro
sync
echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger
What this does is
- All writes stored in the cache, write them to the disk
- Unmount the boot partition
- Remount the root partition
- Do Step 1 again
- Enable all
sysrq
features - Finally, trigger a reboot with
sysrq