Monday, October 18, 2021

Create a custom image ISO for Raspberry

Who was in this position?

I changed the default configuration of certain OS in my raspberry and I installed some applications, NOW do I need to do this every time that I want to replicate it? 

THE ANSWER: NO!!! you just need to make an image of your memory. 

You have TWO options: 

OPTION 1. Copy your entire SD card to your local disk and then restore in a different micro SD CARD with software like Win32DiskImager 
 

PROBLEM #1 

The SIZE of this image is going to be the same as the capacity of your micro SD CARD. 

PROBLEM #2 

Too difficult to upload to the Cloud in order to share with friends or co-workers.

OPTION 2. Obtain a SHRINK image of your  microSD card then share it into the cloud.

** (in my test I had a image of 32GB SD-Card and I obtained 3.7 GB image with this method) **

***(instead of using a Raspberry Pi OS you can follow the same steps using your Linux computer)***

Five Steps and you will be in the Cloud

What do you need:

    1. Raspberry pi ( I am using RBP 3B+) 

    2. Micro SD card that you want to replicate (called microSD Source)

    3. Adapter for reading micro SD card to USB 

    4. Micro SD card with Raspberry Pi OS (RPI OS)  with  free space,  at least the size of the SD-Source. 

    5. Keyboard, mouse.

NOTE: You can work everything in the Raspberry directly or you can work through your Windows or Mac with VNC.  

STEP 1: 

1. Insert the memory (microSD Source) with the OS that you want to have the image. 

2. Log in with your user and password and install Cockpit

sudo apt install cockpit

STEP 2: 

1. Shutdown properly your session and take out the micro SD card from RBP. 

STEP 3: 

1. Insert the second micro SD card  with RPI OS and log in. 

STEP 4: 

1. Insert the micro SD card - Source to the adapter (4a in the figure)

2. Connect the adapter to the Raspberry (4b in the figure) 

3. In the console of the raspberry  check if your system has mounted the microSD -Source with the command 

lsblk -p


in the capture of screen we can see that the microSD is the device /dev/sda, before making the copy we need to unmount the device: 

umount /dev/sda1 && umount /dev/sda2

4. Now we can start the copy of the image

sudo dd if=/dev/sda of=~/MyImage.img bs=32M

be patient it will take a while remember you are coping the entire  SD card (my case 32GB) and each block is 32MB. 

5. When it is done you will obtain a similar message :

6. Once the copy is finished, it is time to shrink the image. We will use PiShrink.

wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
chmod +x pishrink.sh
sudo mv pishrink.sh /usr/local/bin

7. Run the script

sudo pishrink.sh -z ~/MyImage.img

-z parameter will zip the file with gzip.

If you do not use the parameter -z you will obtain a larger file. In my test with -z the file was 1.7 GB without 3.6 GB and not shrinking gave me a file of 31 GB 

STEP 5:

1. Upload to you desire cloud and share it.
2. END.

 
BONUS

You can install the ISO as you are used to or try this option:

Installing the custom ISO in a new microSD Card

1. Put the card in the adapter and insert to the RPI. 
2. Check if it is mounted properly. 
lsblk -p
3. Unmount the microSD
umount /dev/sda1 && umount /dev/sda2
4. copy the image to the microSD
dd if=/path/to/image.img of=/dev/sda bs=32M conv=fsync
5. Done!


References:

Avenwedde, S., Formy-Duval (Correspondent), A., & Fallon, K. (2021, July 28). Create your own custom Raspberry Pi image. Opensource.Com. https://opensource.com/article/21/7/custom-raspberry-pi-image



No comments:

Post a Comment