In this post you will see how to modify a Raspberry unmounted to make the changes required by the user and save them on a uSD card.
This is very useful to create custom images and replicate them in several industrial PLC controllers.
Any of our Raspberry PLCs can be used here:
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 to the image by directly accessing to the mountpoint folder previously created, where the mounted image is located. A couple of examples of changes can be the WLAN configurating or the enabling of 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 has 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.
Now you know how to modify an unmounted Raspberry to make the changes and save them on a uSD card.