Raspios
[unofficial] Add first boot script to Raspberry Pi OS Lite (Raspbian)
Install / Use
/learn @meeDamian/RaspiosREADME
Raspberry Pi OS
Official Raspberry Pi OS Lite minimally modified with the ability to run a script on the first boot.
Supported script filenames:
/boot/firstboot.sh- Just run the script on the first boot/boot/firstboot-script.sh- Same as above, except script is run withscript(1)for complete session recording, that can be later played back usingscriptreplay(1)
Repo is inspired by https://github.com/nmcclain/raspberian-firstboot, but has been automated, Dockerized, and fully scripted.
NOTE: If
firstboot-script.shis used, recording of script run is saved as/boot/firstboot-script-log.out(timing file alongside asfirstboot-script-log.tm)
Usage
-
Download latest image
<details><summary><b>Alternatives?</b></summary>If downloading images built by other people is not your thing, you can also:
</details> -
Burn it into a MicroSD Card
<details><summary><b>How?</b></summary>- Probably the easiest is to use Etcher
- Another way is using
ddon Linux:dd bs=4M if=path/to/downloaded/file.img of=/dev/sdX conv=fsync - Or MacOS:
dd bs=4M if=path/to/downloaded/file.img of=/dev/diskX conv=fsync
NOTE:
</details>bootpartition will usually get mounted as/Volumes/boot/on MacOS, and probably/mnt/boot/on Linux. -
Mount it
<details><summary><b>How?</b></summary>- [MacOS] Simply re-inserting the card should do the trick, if not then
diskutil, orDisk Utilityshould help - [Linux] Hard to say exactly, but sth like:
</details>mkdir -p /mnt/boot/ sudo mount /dev/sdX /mnt/boot/ - [MacOS] Simply re-inserting the card should do the trick, if not then
-
Add your script & mark it as executable
# MacOS example: cd /Volumes/boot/ cat <<EOF > firstboot-script.sh #!/bin/sh -e echo "Hello World!" EOF chmod +x firstboot-script.sh -
Safely eject, move the card into Raspberry Pi, and power it on
Download
There are 4 possible ways, numbered from easiest to most manual.
1. Releases
The easiest way is going to Releases, and downloading the latest one.
Releases are created automatically upon each new Raspberry Pi OS release, you can see their build log either directly in Actions tab, or by searching for release-pending-approval issues.
2. Docker
Second easiest path is (after cloning this repo) running:
NOTE:
--privilegedflag is required becausemounting a filesystem requires root.NOTE_2: Alternatively
./run-in-docker.shcan be run to achieve the same effect.
3. Script
If you're on a Linux box, you can (after cloning this repo) run:
./modify-image.sh create images/
NOTE:
sudomight be required becausemounting a filesystem requires root.
4. Manual
You can also completely ignore all contents of this repo, download Raspberry Pi OS Lite, and (assuming you have the ability to mount ext4 on your OS):
NOTE: For
firstboot-script.servicesee here.
- Mount second partition
- Install the service, by creating
$MOUNT_PATH/etc/systemd/system/firstboot.servicefile, with the following contents:[Unit] Description=FirstBoot After=network.target Before=rc-local.service ConditionFileNotEmpty=/boot/firstboot.sh [Service] Type=oneshot ExecStart=/boot/firstboot.sh ExecStartPost=/bin/mv /boot/firstboot.sh /boot/firstboot.sh.done RemainAfterExit=no [Install] WantedBy=multi-user.target - Enable the service by running:
cd $MOUNT_PATH/etc/systemd/system/multi-user.target.wants/ && \ ln -s /etc/systemd/system/firstboot.service . # No $MOUNT_PATH(!) umountthe image- Burn it to a card
