This post describes how to create an image file with Operation System, Apps and configurations for a Raspberry Pi which can be used to flash SD cards and reduce setup time.
For more articles about Raspberry Pi check: Raspberry Pi
For my three Raspberry Pis which are hosting applications I created an image file where the following setups are already done:
- Basic Raspberry Pi config (Keyboard, user etc. in "raspiconfig")
- Power saving setup is done (check also here Minimize Power Consumption for Raspberry Pi 4)
- SSH setup
- docker-ce, docker-compose
- PiShrink (https://github.com/Drewsif/PiShrink)
Additionally some scripts are per default in the home directory of my user. When all is set up I just create the image like described here: Automatic Backup of Raspberry Pi as img file.
Compared to that article you can create the image also on an USB stick instead of a mounted NAS. You just have to change the commands in the script in the following way:
sudo mkdir /dev/usbstick
sudo mount /dev/sda1 /dev/usbstick
sudo dd if=/dev/mmcblk0 of=/dev/usbstick/pi.img bs=1M
sudo pishrink.sh -z /dev/usbstick/pi.img
So we make a directory where the USB stick is mounted into (line 1). We mount the USB stick (/dev/sda1) to the newly created directory (line 2), create the image (line 3) and shrink it to make it smaller (line 4).
When the sd card is plugged into a computer via usb card reader and you want to create the image there such a script would do the job:
if [[ $# -eq 0 ]] ; then
echo 'image name needed -> exit';
exit 1;
fi
now=$(date +%F)
echo "Date: $now";
sudo dd if=/dev/sdb of=/images/$1_${now}.img bs=1M;
sudo pishrink.sh -z $1_${now}.img;
The scripts needs one parameter (the image name) and stores the image with that file name plus the date in YYYY-MM-DD format.
Leave a Reply