Sunday, May 9, 2021

How to make your Own SD Raspberry Image

Why Do I need This ? 

Here is the problem. Raspberry Pi SD image is less than 4GBs and you copy it on SD memory card of size 8, 16, 32 GB. It expands and you can install and customize your raspberry pi.

Now you have your own SD card with your own software that you want to reproduce. If you use dd command only for your 16GB SD card you will get a 16 GB image file. You need a 16 GB SD card to restore it again. Although the software itself can be restored in 8GB card -assuming the card is not full- and the remaining size is unused space !!! 


Here are the steps to produce a compressed raspberry pi image version:


Steps:

1- Insert SD-Card you want to clone into your laptop.

2- Run lsblk

you should see something like:

    sdb\sdb1  \media\$USER\boot

    sdb\sdb2  \media\$USER\rootfs


3- Unmount partitions

    sudo umount \media\$USER\boot

    sudo umount \media\$USER\rootfs


4- Now copy the full sd-card:

    sudo dd if=/dev/sdX   of=~/my_large_image.img

  

5- Now Compress Image using pishrink

    pishrink.sh ~/my_large_image.img  ~/my_compressed_image.img


Further more  you can compress it to zip file.


How to Get pishrink


1- Download:

wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh


2- Change Permission:

chmod +x pishrink.sh


3- Move it: 

sudo mv pishrink.sh /usr/local/bin