# Injecting a file into an rasberry pi boot image



## tux2bsd (Aug 20, 2021)

I have a script I run on a fresh raspberry pi _install_, I scp it in and run it immediately after the initial install boot. It's easy and not time consuming.

This is a "want to do it for the sake of it" exercise but I haven't done this before and am not entirely sure what to google for the right guide.

I want to inject that file into the boot image so it is available in /root/hello.world after the initial install is done.

Any help would be appreciated.


----------



## SirDice (Aug 20, 2021)

Just mount the image with mdconfig(8), add the file, then write that image to an SD card. The images for the Pi are ready to run, you don't need to "install" them.


----------



## eternal_noob (Aug 20, 2021)

SirDice said:


> The images for the Pi are ready to run, you don't need to "install" them.


There is one exception. On Raspberry Pi 4, the u-boot does not work when booting from the internal SD card slot (USB readers are OK). You have to replace the bootloader in the image. See PR 255080
You'd need the files in comment 15 and mount n copy them over.


----------



## tux2bsd (Aug 20, 2021)

SirDice said:


> The images for the Pi are ready to run, you don't need to "install" them.



I'm well aware of that, I should have said boot - edited.



SirDice said:


> Just mount the image with mdconfig(8), add the file, then write that image to an SD card.



Thanks.


----------

