In this post we will see how to modify a Raspberry unmounted image in order to make changes required by the user and burn it to a uSD card. This is very useful to create personalized images and replicate them in several PLCs.
Any of our Raspberry based devices can be used here:
Linux based PC (it will be the OS used this tutorial so it is much easier to interact with in comparison to Windows or Macintosh)
In this example we will work with the following image of our repository:
1.-Mount Raspbian partition
Find the Raspbian partition in the disk image (you must find here the start sector of the second partition (532480). In order to calculate the offset of the partition you have to multiply this number by 512 bytes.
sudo mount 2022-01-28-raspios-bullseye-armhf-lite-raspberry-plc-v4-20220428174519.img -o offset=$[512*532480] mountpoint
2.-Make changes in the Raspbian image
Here you can make all the required modifications on the image directly accessing to the mountpoint folder previously created, where the mounted image is located. A couple of change examples can be configuring the WLAN settings or enabling the SSH server.
3.-Unmount the disk image
When all the modifications are finished, you can unmount the image again.
sudo unmount mountpoint
4.-Write the image
You can write the image as commonly to the uSD card (you must take into account that all the data will be lost at the device /dev/sdb):
sudo dd bs=4M if=2022-01-28-raspios-bullseye-armhf-lite-raspberry-plc-v4-20220428174519.img of=/dev/sdb
5.-Flush the write cache
Before removing the uSD card, you must execute the following command:
And wait for the prompt. If your computer have detected the new partitions at the uSD card and mounted them automatically, please unmount them again. Now it is safe to remove the uSD card from the computer.