Power & Source of Big Ideas

Shrink NanoPi Neo SD card image for mass production

Moderators: chensy, FATechsupport

I need help in order to be able to use NanoPi Neo LTS board for a product that and we have to customize the flash image.
We have developed a running unit of NanoPi Neo with a 32 GB SD card (since there is no smaller disk produced anymore - unfortunatly). We added apache, java, php, mariadb, node and many more to it and configuring steps are complex.

But when it comes to copy the disk image, it is not practical for production to use a 32 GB disk image.
I would like to shrink it, and make it like the h3_sd_friendlycore-focal_4.14_armhf_20210618.img we used to start with.

I tryed several methods but couldn´t find a working solution.

Please give the steps that we can follow to convert a customized 32 GB disk image and reduce its size, so that we can use win32diskimager.exe to flash to new SD cards faster.
# Install PiShrink
wget https://raw.githubusercontent.com/Drews ... ishrink.sh
chmod +x pishrink.sh
sudo mv pishrink.sh /usr/local/bin

# Create an image of the SD card
sudo dd if=/dev/sdX of=original_image.img bs=4M

# Shrink the image
sudo pishrink.sh original_image.img shrunk_image.img

# Write the shrunk image to another SD card
sudo dd if=shrunk_image.img of=/dev/sdY bs=4M

Replace /dev/sdX and /dev/sdY with the appropriate device names for your SD cards.
Here is what is looks like doing this:

Code: Select all

Disk /dev/sde: 119.08 GiB, 127865454592 bytes, 249737216 sectors
Disk model: uSD Card Reader
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1aaa3e1d

Device     Boot   Start       End   Sectors   Size Id Type
/dev/sde1         49152    131071     81920    40M 83 Linux
/dev/sde2        131072   2621439   2490368   1.2G 83 Linux
/dev/sde3       2621440 249737215 247115776 117.8G 83 Linux
root@rday1:~# wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
--2024-09-18 05:47:48--  https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.108.133, 185.199.109.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10775 (11K) [text/plain]
Saving to: ‘pishrink.sh’

pishrink.sh                                    100%[=================================================================================================>]  10.52K  --.-KB/s    in 0.02s

2024-09-18 05:47:49 (639 KB/s) - ‘pishrink.sh’ saved [10775/10775]

root@rday1:~# chmod +x pishrink.sh
root@rday1:~# mv pishrink.sh /usr/local/bin
root@rday1:~# dd if=/dev/sde of=nanopi_neo-ubuntu_image.img bs=4M status=progress
127863357440 bytes (128 GB, 119 GiB) copied, 3352 s, 38.1 MB/s
30485+1 records in
30485+1 records out
127865454592 bytes (128 GB, 119 GiB) copied, 3356.25 s, 38.1 MB/s
root@rday1:~# pishrink.sh nanopi_neo-ubuntu_image.img shrunk_nanopi_neo-ubuntu_image.img
pishrink.sh v0.1.4
pishrink.sh: Copying nanopi_neo-ubuntu_image.img to shrunk_nanopi_neo-ubuntu_image.img... ...
pishrink.sh: Gathering data ...
pishrink.sh: /etc not found, autoexpand will not be enabled ...
pishrink.sh: Checking filesystem ...
userdata: 72977/6035200 files (0.2% non-contiguous), 883332/30889472 blocks
resize2fs 1.47.0 (5-Feb-2023)
pishrink.sh: Shrinking filesystem ...
resize2fs 1.47.0 (5-Feb-2023)
Resizing the filesystem on /dev/loop0 to 679279 (4k) blocks.
Begin pass 2 (max = 354460)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 943)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 5443)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/loop0 is now 679279 (4k) blocks long.

pishrink.sh: Shrinking image ...
pishrink.sh: Shrunk shrunk_nanopi_neo-ubuntu_image.img from 120G to 3.9G ...
root@rday1:~# root@rday1:~# dd if=shrunk_nanopi_neo-ubuntu_image.img of=/dev/sdg bs=4M status=progress
3888119808 bytes (3.9 GB, 3.6 GiB) copied, 7 s, 555 MB/s
983+1 records in
983+1 records out
4124504576 bytes (4.1 GB, 3.8 GiB) copied, 189.054 s, 21.8 MB/s
root@rday1:~#  ls -l *.img
-rw-r--r-- 1 root root 127865454592 Sep 18 06:46 nanopi_neo-ubuntu_image.img
-rw-r--r-- 1 root root   4124504576 Sep 18 07:52 shrunk_nanopi_neo-ubuntu_image.img
root@rday1:~#


It seems like the dd copy will hang but I guess that is wrighting the 0's to the rest of the SD card.

-Raymond Day

Who is online

In total there are 4 users online :: 0 registered, 0 hidden and 4 guests (based on users active over the past 5 minutes)
Most users ever online was 5185 on Wed Jan 22, 2020 1:44 pm

Users browsing this forum: No registered users and 4 guests