Hauschild
Posts: 36
Joined: Wed Oct 16, 2013 4:42 pm

Resize image for use on a smaller sd card

Sun Apr 24, 2016 2:09 pm

Hi Raspberry Pi forum,
I have a custom sd card image on my 32gb card, but I would like to have on a 16gb card as well. Using Win32 diskimager I created the .img file uding the read function. When I try to write that image onto the 16gb sd card it tells me that the image is too big to fit. This is most likely because i have expanded the filesystem using raspi config on the 32 gb card.
How can I resize it to fit a 16 gb card instead?

Thank you in advance
Rasmus

User avatar
Rive
Posts: 586
Joined: Sat Mar 26, 2016 5:21 pm
Location: USA

Re: Resize image for use on a smaller sd card

Sun Apr 24, 2016 8:34 pm

Hauschild wrote:
drgeoff wrote:This has been answered dozens of times. Search the forum, but using an ordinary internet search engine, not the next to useless facility in the top right corner of these pages.
Could you please leave me with a link?
https://github.com/qrti/shrink
DNPNWO

User avatar
Ferdinand
Posts: 236
Joined: Sun Dec 01, 2013 2:24 pm
Location: Leiderdorp, NL

Re: Resize image for use on a smaller sd card

Tue Apr 26, 2016 10:14 am

Hi Hauschild,

You will find all answers here on this excellent site:
http://softwarebakery.com/shrinking-images-on-linux
Success with your project!
Ferdinand

beta-tester
Posts: 1236
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: Resize image for use on a smaller sd card

Wed Apr 27, 2016 4:16 pm

Hauschild wrote:Hi Raspberry Pi forum,
I have a custom sd card image on my 32gb card, but I would like to have on a 16gb card as well. Using Win32 diskimager I created the .img file uding the read function. When I try to write that image onto the 16gb sd card it tells me that the image is too big to fit. This is most likely because i have expanded the filesystem using raspi config on the 32 gb card.
How can I resize it to fit a 16 gb card instead?

Thank you in advance
Rasmus
why wasting power in shrinking the size of a filesystem/image to fit to a smaller sd card...
why not copying files directly to the smaller sd card?
so not copying block by block, do better copying file by file.

but even that was explained more than one time in the forum...
(yeah, kind of boring/annoing to read similar questions that were already answered over and over again)
{ I only give negative feedback }
RPi Model B (rev1, 256MB) & B (rev2, 512MB) & B+, RPi2B, RPi3B, RPi3B+, RPiZeroW, ...

User avatar
liudr
Posts: 685
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Resize image for use on a smaller sd card

Thu Apr 28, 2016 5:00 am

I can honestly tell you that as an entry-level linux user, my searches have turned up to be less useful than you gurus think. Most what I found involved how to do this in linux with command line. Not particularly useful for beginners.

For myself, I use paragon backup and recovery 2014 free version on a windows PC:

Just a few clicks to back up and then restore to a smaller sd card.

https://liudr.wordpress.com/2016/03/25/ ... pberry-pi/
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Resize image for use on a smaller sd card

Thu Apr 28, 2016 5:41 am


@liudr, tnx for the link to your blog; love it!


peace
marcus
:ugeek:

User avatar
Pilosopong Tasyo
Posts: 116
Joined: Wed Apr 06, 2016 11:43 am
Location: /root

Re: Resize image for use on a smaller sd card

Thu Apr 28, 2016 5:50 am

@Hauschild:

I read somewhere in this forum about rpi-clone. Give it a shot if that's what you're looking for. I was able to make a working backup of my running Raspbian onto another µSD. HTH.
Give a man a ghoti and he'll eat for a day; teach him how to ghoti and he'll eat for life. Ghoti?! - http://i.imgur.com/mAfBUdi.png
How To Ask Questions The Smart Way - http://www.catb.org/esr/faqs/smart-questions.html

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Resize image for use on a smaller sd card

Thu Apr 28, 2016 2:57 pm

liudr wrote:I can honestly tell you that as an entry-level linux user, my searches have turned up to be less useful than you gurus think. Most what I found involved how to do this in linux with command line. Not particularly useful for beginners.
Thanks, @liudr. I have been giving this a considerable thought experiment lately. During my tenure with IBM I spent a couple of years in the late '80s working at the lab in Tampa. We had a support center there, and I spent time supporting VM, MVS, CICS, and others (as an internal PSR; program support rep). We used an internal forum (not much unlike this PI forum) called RETAIN; 30% of my work was spent researching AI, and 70% of my work was spent talking calls from IBM clients and then running vigorous searches against the RETAIN database in an effort to minimize development costs by doing "Triage" , if you will , by finding existing problems and solutions in a minimum amount of time. Consequently, I spent thousands of hours generating (and refining) search arguments--- its an art, really.

I take searching the Internet as a casual, natural, and 'easy' function that I take "frankly" for granted. I often forget that others have not refined the art-form and do not have the skill honed; consequently their searches turn up mostly trash--- whereas my searches turn up mostly gold.

All I can say is try, practice practice practice, and don't give up.

peace.
marcus
:ugeek:

User avatar
liudr
Posts: 685
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Resize image for use on a smaller sd card

Thu Apr 28, 2016 3:54 pm

Marcus,

Thanks for sharing your story! Honestly, searching raspberry pi or arduino does give lots of useful/relevant hits but sometimes that overwhelms the beginners. At least it is better than finding nothing. Several years back when I was active with Processing programming, I found it impossible to get good hits because the word Processing is too generic. I got lots of industrial processing hits that are flooding the first few pages. Maybe same can be said about Wiring. We are lucky that raspberry + some programming or electronics keywords brings the right hits.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

User avatar
mihalop
Posts: 28
Joined: Thu Sep 03, 2015 7:04 am
Contact: Website

Re: Resize image for use on a smaller sd card

Sat Sep 10, 2016 4:14 pm

We do something similar, shrinking the standard Raspbian image. We have a standard procedure which involves resizing the filesystem, shrinking the partition, zeroing out free space on the partition and then image on exactly what we need. I could share some step if you want.

In your case, you could just shrink the filesystem on the last partition by 100MB (or as much as the difference is) and then image up to that point.
Yodeck - Digital Signage on the Raspberry Pi
Free Raspberry Pi 3 Player for all screens on Annual Plan

User avatar
nl3prc
Posts: 160
Joined: Sun Jul 24, 2016 12:39 pm
Location: Den Helder the netherlands

Re: Resize image for use on a smaller sd card

Sat Sep 10, 2016 4:49 pm

What a bump of an old topic
https://github.com/billw2/rpi-clone

footwo
Posts: 5
Joined: Fri Sep 09, 2016 12:29 am

Re: Resize image for use on a smaller sd card

Sat Sep 10, 2016 7:47 pm

liudr wrote:I can honestly tell you that as an entry-level linux user, my searches have turned up to be less useful than you gurus think. Most what I found involved how to do this in linux with command line. Not particularly useful for beginners.

For myself, I use paragon backup and recovery 2014 free version on a windows PC:

Just a few clicks to back up and then restore to a smaller sd card.

https://liudr.wordpress.com/2016/03/25/ ... pberry-pi/
DUDE.

I have been all over forums and reddit and various other places and not one of them has provided a working solution for this problem (which has been driving me insane). This does it, and in a few clicks, on Windows.

THANK YOU FOR EVER.

smokedmusseld
Posts: 1
Joined: Thu Mar 30, 2017 2:48 pm

Re: SD image too big for another SD Card

Thu Mar 30, 2017 2:53 pm

Searching for this question on Google has this page near the top of the results, yet the thread is almost entirely an unrelated social argument before an answer is found much further down.

Maybe a forum mod can consider cleaning this up for any future visitors who hit the first search result like I did.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23307
Joined: Sat Jul 30, 2011 7:41 pm

Re: Resize image for use on a smaller sd card

Thu Mar 30, 2017 3:33 pm

Thread cleaned of cruft.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

jlowe
Posts: 18
Joined: Wed Apr 29, 2015 1:27 am

Re: Resize image for use on a smaller sd card

Fri Mar 31, 2017 1:00 am

I've been using ShorTie8's script for a while.
https://github.com/ShorTie8/mini_image

I have an usb drive attached to my pi on a hub. Mount the drive to /media,
switch to /media and run the script from there. Copy the image to a linux
machine and just dd to a blank sdcard to a smaller / larger card as needed.

Cheers ... jay

Pearl.852
Posts: 38
Joined: Wed Jun 08, 2016 1:22 pm
Location: Hong Kong

Re: Resize image for use on a smaller sd card

Sat Apr 01, 2017 5:51 am

To backup a working image on a smaller sd card, I found it using the included SD Card Copier application is the most simplest method to accomplish this. I use a 32GB card on my pi3 and I do a backup to a 8GB card before each upgrade, so I can restore my system if something goes wrong after an upgrade. I can then create a 8GB image from the backup 8GB card if I wanted to.

Ollittm
Posts: 32
Joined: Wed Mar 02, 2016 9:07 am

Re: Resize image for use on a smaller sd card

Fri Aug 25, 2017 2:47 pm

I spent a lot of quality time on this. The shrink script does automate the process to a degree except it can't determine the truncate length automatically. I'm surprised there's no imaging tool that'd just do it, similar to the paragon backup.

If you don't already have a linux set up somewhere with access to 20-odd gigs of space that windows can also access it's probably too hard to do, just use the paragon backup free after you've resized the sdcard partition with gparted.

I had fun trying to set up suitable linux-on-a-stick. exfat? ha-ha. ntfs? nope. fat32? err >4GB file.. If the virtualbox from lili actually worked it's solve most of the problems but it doesn't, at least not on on my box and latest mint and ubuntu it didn't. I guess brute force solution on straight installing linux on a stick with a large enough exfat partition as well would get the job done if you absolutely had to do it with linux tools.

If anyone's interested, it's actually an RnD environment where we use RPis for testing our display products. So there's a need to be able to duplicate the test setup on multiple pi boxes.

RonR
Posts: 459
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: Resize image for use on a smaller sd card

Fri Aug 25, 2017 9:35 pm

Ollittm wrote:
Fri Aug 25, 2017 2:47 pm
The shrink script does automate the process to a degree except it can't determine the truncate length automatically. I'm surprised there's no imaging tool that'd just do it, similar to the paragon backup.
Attached is a script I put together a while back to shrink an image file's root partition to its absolute smallest size and, optionally, add some additional free space to that minimal size. No calculations, truncations, or manual intervention is required.

WARNING: This script hasn't had much use by anyone but me, so don't run it on your only copy of an image file in case there's a bug lurking!

Usage is:

sudo ./image-shrink imagefile [Additional MB]

If 'Additional MB' is omitted, you will be prompted, but can simply hit ENTER for none.

ianboag
Posts: 36
Joined: Thu Jul 17, 2014 5:08 am

Re: Resize image for use on a smaller sd card

Mon Aug 28, 2017 2:35 am

I found all the answers that involved gparted and stuff to be too much for me.

My situation might have been a bit different to some others, but here goes.

I set something up with DietPi - it fitted on a 2GB card and worked fine. DietPi will expand the filesystem if asked but does not pester you about it. I saved the card and the next time I wanted to clone it, I wrote it to a 4GB card - 2 GB cards being hard to find. Then I did a few changes and wrote an image for the 4GB card. Just to make one point here - when I was running the 4GB card - if I ran df -h it told me the total space was 1.7GB.

Then I wanted to write a new 4GB card from the image and ran into the dreaded "not quite enough space" problem. So I had put it on an 8GB card. Later I saved the 8GB card, then went to write another one and - guess what - it happened again - the same message. Not all XGB cards are exactly the same figure and Win32DiskImager writes the WHOLE card.

Resizing an image looked real hard. I banged my head on it a few times .... until ... I found the Windows app IBEX which just does it for the case where the filesystem has not been expanded to the full size. So I chopped an 8GB image back to 6GB, wrote it on an 8GB card and it was all happy. If I use Win32DI on it, the result will be a file of about 8GB. SO I might want to resize that too.

DietPi still sees it as a 1.7GB filesystem .. I would guess that I could knock it back to a bit over 1.7GB and it would still go.

Happy days. Too easy.

dmedeiros32
Posts: 2
Joined: Wed Aug 23, 2017 7:20 pm

Re: Resize image for use on a smaller sd card

Fri Nov 17, 2017 12:00 pm

Best solution so far:

https://github.com/Drewsif/PiShrink

You`ll need ubuntu 16.10 or up, but it should work on Ubuntu for Windows.

AlonOr
Posts: 2
Joined: Thu Jan 04, 2018 8:07 am

Re: Resize image for use on a smaller sd card

Thu Jan 04, 2018 9:28 am

Agree with @dmedeiros32 .
I wanted to backup a Raspberry PI with Raspbian and use it as a "Golden image" so I did it as follow.
In my case i used 2 RPI and my PC (Windows), the second PI is just used to install the tool and compress the image, it could be done on an linux machine but i had no access to one.

Configure the source PI on a small SD card (8gb) as desired with all the programs and configurations you want then back it up on my PC using an SD card reader and Win32DiskImager, there is a nice guide at https://lifehacker.com/how-to-clone-you ... 1261113524, so now I got my "Golden image" named as "test.img", of course it is big as the size of the SD card .

Configured the destination PI with a bigger SD card (16gb) to have ssh and git:

Code: Select all

sudo systemctl enable ssh
sudo systemctl start ssh
sudo apt-get -y install git
git config --global http.sslverify false
git clone https://github.com/Drewsif/PiShrink.git
Now I go to my PC , download putty.exe, pscp.exe, plink.exe from https://www.chiark.greenend.org.uk/~sgt ... atest.html and copy them to my windir (c:\windows), now the PC is ready to connect and transfer files to the PI.

Open CMD prompt, and copy test.img (the "Golden image") to the destination PI (16gb), replace "pi","raspberry" if using different username/password combo , of course the filename and path to the Golden image and your destination PI`s IP:

Code: Select all

pscp -l pi -pw raspberry C:\apath\test.img 192.168.123.45:/home/pi
It will take a while, after finishing we proceed to compress the image:

Code: Select all

plink pi@192.168.123.45 -pw raspberry sudo ./PiShrink/pishrink.sh test.img
Once it finished it will inform how much it shrinked, in my case it went from 8gb to 2gb.
Now we copy back the compressed image:

Code: Select all

pscp -l pi -pw raspberry 192.168.123.45:/home/pi/test.img C:\apath\compressed.img
Now you have your compressed image (compressed.img) and can restore it to any SD card even a small than the original using the guide above.

One nice feature of PiShrink is that once you boot for the first time of the compressed image the PI it will expand and take the whole SD card then reboot, so you have all the space available to use.
So just take it into consideration, let it reboot before you start using your newly cloned PI.

ONECore
Posts: 2
Joined: Wed Apr 26, 2017 3:05 pm

Re: Resize image for use on a smaller sd card

Mon Feb 26, 2018 9:36 pm

pishrink sounds great, but I can't get the 'golden' image. When I plug the raspberry pi SD into my windows machine, it shows up as 3 drives. I can't ask Win32DiskImager to copy from three different partitions/drives. Help.

amilino
Posts: 81
Joined: Fri Feb 05, 2016 6:01 pm

Re: Resize image for use on a smaller sd card

Sun Jul 29, 2018 3:22 pm

Yesterday I tried to use PiShrink on my laptop. I have Jumper book, where I installed on internal eMMC card Windows 10 and Kubuntu 18.04 in dual boot. I did backup of entire device (mmcblk1) with dd command, and did shrinking of it. During the process I received some messages that something is wrong and I was offered to chose "y" for fixing it. At the end when I try to mount img I get error and when I examine img file I see that GPT partition is damaged. As far as I can see only Kubunut partition was shrinked. So I guess I cannot use this script if I have GPT partitions in my image file. I would like to use this script on my laptop also not just on my RPI. I know that this is RPI forum but does anyone know some script which supports GPT partitions?

Paul Hutch
Posts: 378
Joined: Fri Aug 25, 2017 2:58 pm
Location: Blackstone River Valley, MA, USA
Contact: Website

Re: Resize image for use on a smaller sd card

Sat Aug 04, 2018 4:58 pm

AFAIK PiShrink only works with basic Raspbian images, it doesn't even work for RasPi NOOBS images.


Return to “Advanced users”