4

I'd like to know, whether there is an option to execute a script on the first boot of Raspberry. There is a catch though.

I'd like to be able to put the script in the boot folder. Since it is available on the SD card from Windows, I could prepare the script there before the first boot.

The reason for my specific requirements is that I'm using 5" Waveshare display in custom enclosure and I have to disconnect HDMI connector, connect a regular HDMI display, boot, download and install drivers and then replace the cable with connector again after reboot.

I've been thinking, if there is a way I could craft a script, which would configure the WiFi connection, clone repo with driver scripts and run one of them (it finishes with sudo reboot). If I needed to prepare a new SD card for my Raspberry setup, I'd simply put that script in boot folder, power Raspberry up and just wait until it reboots after installing drivers.

Is it possible?

Spook
  • 185
  • 7

1 Answers1

4

If you have a virgin Raspbian image that was never booted before you will find a script that is executed on first boot up. Look at a fresh flashed CD Card with mounted boot partition for example at /mnt/p1:

laptop ~$ sudo cat /mnt/p1/cmdline.txt
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=c1dc39e5-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh

As you see at the end there is a script /usr/lib/raspi-config/init_resize.sh called. It mainly does what it's name says but also some other things. It has more than one exit point, some with error condition but with some know how of scripting it should be able to insert a call to your custom script.

With some care it should be possible to run your script at very first boot as a hook to init_resize.sh.

Ingo
  • 42,961
  • 20
  • 87
  • 207