Ben Akrin's Script Lets You Flash Raspberry Pi SD Cards Automatically Over Your Local Network

In active use to manage a 70-node Raspberry Pi deployment, this handy tutorial makes keeping your OSes up to date as easy as possible.

Gareth Halfacree
3 years agoHW101 / Home Automation

Raspberry Pi wrangler Ben Akrin has put together a guide for automated, fully-headless imaging — designed to get Raspberry Pi single-board computers up and running as quickly as possible and with a minimum of human interaction.

"Recent improvements in the Raspberry Pi EEPROM [have] made it possible to boot them completely online," Akrin explains. "This method currently requires access to the Pi and human interaction. What I'm describing here is a way to image Pis with zero access or interaction required. It uses the network booting mechanism which has been available in the EEPROM for a while. You’ll be right at home if you know PXE."

Akrin's approach is designed to remove the human element, turning one Raspberry Pi — or any other computer — into a network boot (netboot) server fro one or more target Raspberry Pi devices on the same network. Setup is simple: Copy, paste, and run a quick installation script, then add a Raspberry Pi-compatible operating system image of your choice.

There's one minor caveat in the "automated" imaging approach, however: Each Raspberry Pi needs to have its EEPROM configured to find the netboot server before deployment. It's a one-off modification, and once applied the Raspberry Pi is ready for repeated re-imaging without user interaction — but it's still a manual process, and one which needs you to boot each Raspberry Pi up in turn from an existing microSD card.

Akrin uses the system to maintain a fleet of 70 single-board computers, which are imaged with a custom operating system based on the official Raspberry Pi OS Linux distribution. Part of the customization: a timer that encourages each device to check in with the central server every 15 minutes. "I can simply publish a new image there and the whole fleet will go in for re-imaging," he explains.

When it does so, I have the Pis sleep a random amount between 0 and 48 hours to avoid having a huge wave of traffic, but also to avoid breaking everything at the same time."

The full tutorial is available on Akrin's website, but it does come with a clear warning for larger deployments: The server briefly switches into instructing target devices to boot from local storage after a Raspberry Pi signals that it's successfully flashed an image and is going down for reboot, and if another Raspberry Pi connects to the server in this window it won't receive the operating system image.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Latest articles
Sponsored articles
Related articles
Get our weekly newsletter when you join Hackster.
Latest articles
Read more
Related articles