mattbee
Posts: 2
Joined: Wed Jul 18, 2012 4:41 pm

Having Raspbian run startup scripts from the /boot partition

Tue Jan 05, 2016 2:40 pm

Hello there,

I recently ran into a workflow problem with building Raspberry Pi images which I solved, but could solve more nicely with a bit of support from Raspbian.

What I want to do was set up several RPis from the stock Raspbian images, WITHOUT having to boot them and fiddle around with a Pi on my desk. I just wanted to dump some setup scripts onto the SD card, and have it run. I was also using Windows at the time, so couldn't customise them via mounting the ext4 partition - I wanted to be able to deploy my startup scripts in /boot.

I ended up writing a "shim" init process to solve the problem, so now when I want to deploy a Raspberry Pi browser kiosk, I just unzip a 700KB folder into the /boot partition, take out the SD card and the Pi sets itself up on the first boot. I can edit a few text files to add wireless credentials, the startup URL and so on.

For me it's a much nicer way of sharing Raspberry Pi appliances, and is a bit like the way Docker describes Linux setups, i.e. very small. Unlike Docker & Linux, the RPi is much more centred on a single OS. The shim init binary is a hack, and would be unnecessary if Raspbian supported some convention for triggering code from /boot at an early stage.

I wrote it all up in a blog post https://blog.bytemark.co.uk/2016/01/04/ ... first-boot and the code for the init process is up on https://github.com/BytemarkHosting/pi-init2 - any suggestions or improvements appreciated!

anita2r
Posts: 226
Joined: Sun Dec 23, 2012 6:55 pm
Location: Ottawa, Canada

Re: Having Raspbian run startup scripts from the /boot parti

Wed Jan 06, 2016 4:06 am

Hi,

I have probably completely missed the point of your issue ...
but why not create one fully configured, fully working system and then use 'DD' to copy the complete working system on the SD card to a new SD card (& repeat as required for further SD cards), then plug the new SD cards into the Pi's and away they go - fully operational.

You would need to have a network setup that uses DHCP, as static IP addresses wouldn't work. You also would have to edit the hostname to make it unique. Perhaps a script run at bootup in sudo's crontab that creates a unique name would work.

Regards

anita2R

malicious
Posts: 96
Joined: Thu Jul 24, 2014 10:07 pm
Location: USA

Re: Having Raspbian run startup scripts from the /boot parti

Wed Jan 06, 2016 4:15 am

The point seems to be customizing Raspbian on a computer without ext4 support. Seems like a lot of work compared with spinning up a virtual machine that understands ext4 under Windows :) but still a neat idea. Thank you for sharing, OP.

snarkyFish
Posts: 1
Joined: Wed Aug 24, 2016 11:11 pm

Re: Having Raspbian run startup scripts from the /boot parti

Wed Aug 24, 2016 11:24 pm

Seconded.. After using things like docker, vagrant, etc.. Systems for spinning up a system configuration quickly and easily from a script or configuration file, I often wish for the same thing with the pi. 'just run linux' is a copout. Most folks don't and shouldn't need to have ext4 support to get hacking.

If the distro looked for a specific shell script in the /boot directory and executed it on start up, that is all we'd need. From there that script could do all the rest.

With that hook in place I could build a script that would pull down the latest .img of raspbian, write it to an sd card, then write a set up script to /boot that would turn that pi into anything I want it to be.

I could then share that script with friends, etc. The pi's configuration could be version controlled, passed around, improved/modified. Without having to roll a whole raspbian distro of your own.


My other argument for this stems from the fact that backing up a pi once installed is still a pretty terrible process, as far as I know.. I really don't want a back up of my pi's data, as much as I want backups of the hard won configurations I build on them.

nickoala
Posts: 7
Joined: Sat Apr 09, 2016 8:46 am

Re: Having Raspbian run startup scripts from the /boot partition

Tue Jan 16, 2018 2:47 pm

Unlike previous commenters, I totally sympathize with the purpose of your project.

I am a part-time instructor who has to prepare Raspbian images in bulk (10+ SD cards) a few times a year. My customization is simple, involving adding a file to /boot and appending a line to config.txt, so having no need of a system like yours. However, I can easily imagine more complex situations to which your system is perfectly suited. I also had some thoughts along similar lines to what you have done, although I have never got around to do it.

Thanks for sharing it. It's a great addition to my repertoire.

mattmiller
Posts: 2083
Joined: Thu Feb 05, 2015 11:25 pm

Re: Having Raspbian run startup scripts from the /boot partition

Tue Jan 16, 2018 2:51 pm

My customization is simple, involving adding a file to /boot and appending a line to config.txt
I'd be very interested to find out what you add to config.txt to execute a file in /boot - can you share what you do please?

nickoala
Posts: 7
Joined: Sat Apr 09, 2016 8:46 am

Re: Having Raspbian run startup scripts from the /boot partition

Wed Apr 11, 2018 6:07 am

What I do are two things: touch a `ssh` file to enable sshd, and add a line to `config.txt` to enable UART. That's all. Really very simple.

EternityForest
Posts: 5
Joined: Fri Jul 12, 2013 7:15 pm

Re: Having Raspbian run startup scripts from the /boot partition

Sat Jan 12, 2019 11:17 pm

Just found this thread while searching for a way to do exactly this.

Customized images are inflexible, in that you have to start all over to use a new Raspbian. I would love to see a way to have a boot script that runs once per every time it's modified, that you could just drop in the /boot partition.

SSHing is inconvenient to do in large numbers, it takes a bit of time.

Ideally, whatever was used to track the state of if it had ever been run would work on read only disks, and for that reason I'd be fine with boot scripts that ran *every* time, with the user being responsible for tracking when it should do what(By manually mounting as writable if needed, etc).

mattmiller
Posts: 2083
Joined: Thu Feb 05, 2015 11:25 pm

Re: Having Raspbian run startup scripts from the /boot partition

Sun Jan 13, 2019 9:57 am

Check out PiBakery - its the tool for this sort of job

https://www.pibakery.org/

EternityForest
Posts: 5
Joined: Fri Jul 12, 2013 7:15 pm

Re: Having Raspbian run startup scripts from the /boot partition

Sun Jan 13, 2019 10:01 am

Wow thanks! That tool looks like it handles this sort of job perfectly!

User avatar
procount
Posts: 1668
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: Having Raspbian run startup scripts from the /boot partition

Sun Jan 13, 2019 6:38 pm

If anyone wants to do a similar thing with a NOOBS installation, you can try https://github.com/procount/noobsconfig.
This uses NOOBS Flavours to select customisations to be applied on top of a new OS installation.
Each flavour only holds the additional files and they share the same OS files, thus saving space if you want many flavours, say for different workshop setups.
As it uses NOOBS to hook into the installation, it works with a standard OS, so it can be applied to any NOOBS supported OS without modifying the OS.

NOOBSCONFIG is also directly supported in PINN, so there is no need to add any additional files apart from your customised flavours.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

Return to “Advanced users”