gitbls / sdm

Raspberry Pi SD Card Image Manager
MIT License
469 stars 48 forks source link

Issue Running First Boot Scripts #141

Closed hunoz closed 11 months ago

hunoz commented 11 months ago

Hello,

I have a script that I am looking to perform some actions on first boot of the system, and I've read the documentation, but it does not seem to be running the script at all.

The file is located at /usr/local/sdm/1piboot/00-install.sh and has been modified using chmod +x to ensure it is executable. I then run this command: sdm --customize --bootscripts --restart /root/2023-10-10-raspios-bookworm-arm64-lite.img, and while I can find the file in the same directory in the image, it is not executed. I also attempted this: sdm --customize --plugin runatboot:"user=root|script=/root/00-install.sh|output=/root/output" --plugin copyfile:"from=/usr/local/sdm/1piboot/00-install.sh|to=/root" --restart /root/2023-10-10-raspios-bookworm-arm64-lite.img with no luck eitherr.

I thought perhaps it was that it only ran during first actual boot (i.e. on a live SD card in a Pi), but that also proved unfruitful. Am I doing something incorrectly or misinterpret the documentation on how first boot operates?

Thanks in advance!

gitbls commented 11 months ago

I think you may have a misunderstanding about the 1piboot scripts. It sounds like you've got the setup done correctly (protection, filename, etc), but perhaps a misunderstanding of when it actually runs.

The 1piboot scripts don't run when you do the customize. Customization is about preparing the IMG. Next, you burn that IMG to an SSD or SD Card and boot it on a Pi. At that point, during the First Boot of the system, the 1piboot script will run.

Here are a few lines from the first boot of the system, where you can see the line "This is running during first boot". This was put into the log by the script 00-install.sh

Nov 28 20:12:27 p83 systemd[1]: Starting sdm-firstboot.service - sdm System FirstBoot Configuration...
Nov 28 20:12:27 p83 root[724]: FirstBoot: Start sdm FirstBoot Service
Nov 28 20:12:27 p83 root[727]: FirstBoot: Start Configuration with configuration file '/etc/sdm/auto-1piboot.conf'
Nov 28 20:12:27 p83 root[737]: FirstBoot: Configuration with configuration file '/etc/sdm/auto-1piboot.conf' Completed
Nov 28 20:12:27 p83 root[740]: FirstBoot: Set WiFi Country to 'US'
Nov 28 20:12:28 p83 systemd[1]: Started sdm-firstboot.service - sdm System FirstBoot Configuration.
Nov 28 20:31:15 p83 root[908]: FirstBoot: System time synchronization achieved
Nov 28 20:31:23 p83 root[1464]: FirstBoot: Run Custom FirstBoot Script '/usr/local/sdm/1piboot/00-install.sh'
Nov 28 20:31:23 p83 root[1468]: *** This is running during first boot
Nov 28 20:31:25 p83 root[1488]: FirstBoot: Regenerate SSH Host Keys
Nov 28 20:31:29 p83 root[1517]: FirstBoot: set boot behaviour to B1
Nov 28 20:31:32 p83 root[1559]: FirstBoot: Re-enable getty@tty1
Nov 28 20:31:34 p83 root[1580]: FirstBoot: System will restart in 20 seconds
Nov 28 20:31:55 p83 root[1603]: FirstBoot: System restarting now
Nov 28 20:31:55 p83 systemd[1]: Stopped sdm-firstboot.service - sdm System FirstBoot Configuration.

The steps with sdm are as follows: 1/ Start with a fresh IMG, do the --customize. This is where apps are installed into the IMG, other updates done. 2/ Burn the IMG to media using --burn. 3/ Boot the media on a Pi. This is when the 1piboot script will run.

I'd suggest that you tell me in some detail what you want to do in your 00-install.sh script and/or post the script here.

There may be a better way to accomplish what you're trying to do, and your explanation will help me understand what's confusing. And I'll be happy to clarify as needed.

hunoz commented 11 months ago

Odd, I did use sudo journalctl -b -1 | grep FirstBoot on the running Pi, and it wasn't able to find anything. The goal of my script is to run the necessary commands, install the necessary packages, and copy the necessary files to be set up for the following:

gitbls commented 11 months ago

Like Linux, using sdm isn't super-complex, but it's important to describe all your steps clearly, so that the listener (me in this case) can understand what exactly you're doing, and then provide you with the best help/advice.

So, please describe what steps you took to get to the point of booting that sdm-created SD Card (or SSD). Please use terms that clearly differentiate between the "host" where you run sdm and a Pi system booting that sdm-created SD Card.

What you want to do is not complex except for:

I'm happy to have a look at your script if you'd like, but first let's focus on the steps you took to get that Pi booting your sdm-created disk and why you didn't see anything in the system log. (If you'd prefer to email me the script rather than posting it here, you can find my email in the README doc.

hunoz commented 11 months ago

Right, enough time in your own echo chamber, you forget how to properly elaborate on your own setup, sorry!

The guide I'm using for the iPad USB-C configuration is located here

Code Server is a web version of Visual Studio Code. I am installing it using the instructions here.

Before explaining, I should mention this environment is a Debian instance in AWS EC2, so I was not able to use sdm --burn since I was not connected

Steps I took to get an image for booting:

  1. Placed my 00-install.sh script in /usr/local/sdm/1piboot and ensured that it was executable
  2. Ran the above commands
  3. Exited the explored environment
  4. Copied the img file that I was using to my local laptop and flashed it on an SD card using the Raspberry Pi Imager
  5. Booted the Pi to examine if changes took effect

This may be my misunderstanding, the reason I did it this way was two-fold:

gitbls commented 11 months ago

OK, that helps some. Thx.

No problem with using EC2, except that you can't pop an SD Card into an EC2 instance. But you CAN:

As to your two points/questions:

If you burn an SD Card, and boot it, but don't see anything from FirstBoot, then I'm very confused and concerned, as it's ALWAYS there. Many things can break if this isn't working. It sounds like you know a bit of journalctl. Please post the output from (on the freshly-booted pi):

sudo ls -l /etc/sdm
systemctl status sdm-firstboot
journalctl --list-boots
journalctl -b -<the very first boot> | grep FirstBoot

Specific comments:

hunoz commented 11 months ago

Ah, okay, let me try burnfile to see if writing and booting it on a Pi.

hunoz commented 11 months ago

Closing as I decided to go a different route to automate my Pi images.

gitbls commented 11 months ago

Sorry to hear that sdm didn't do what you wanted. I'd be interested in hearing how it fell short of meeting your needs, if you have a minute. Thx.