0% found this document useful (0 votes)
30 views4 pages

Raspberry Pi Shrinking image to fit on a smaller card

The document provides a guide on how to shrink a Raspberry Pi image to fit on a smaller SD card using tools like gparted and Win32DiskImager. It details the steps to create unallocated space on the SD card, create an image file, and then resize the image using the 'truncate' command. Additionally, it includes user feedback on alternative methods for creating images and resizing partitions.

Uploaded by

jayasinghellr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views4 pages

Raspberry Pi Shrinking image to fit on a smaller card

The document provides a guide on how to shrink a Raspberry Pi image to fit on a smaller SD card using tools like gparted and Win32DiskImager. It details the steps to create unallocated space on the SD card, create an image file, and then resize the image using the 'truncate' command. Additionally, it includes user feedback on alternative methods for creating images and resizing partitions.

Uploaded by

jayasinghellr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Raspberry Pi: Shrinking image to fit on a smaller card - Smart Retro Forums http://smartretro.co.uk/forums/viewtopic.php?

f=3&t=58

Smart Retro Forums


Retro Gaming Search…  

 Quick links  FAQ  Register  Login

 Home ‹ Board index ‹ Raspberry Pi

Raspberry Pi: Shrinking image to fit on a smaller card


 3 posts • Page 1 of 1
Post Reply   Search this topic…  

Raspberry Pi: Shrinking image to fit 


Floob
Site Admin
on a smaller card
Posts: 182
 by Floob » Tue Mar 10, 2015 11:09 pm Joined: Mon Feb 09, 2015 8:27 pm

This was (is?!) a pain. I wanted to shrink my image to fit on a smaller, or even
same size card.
When I use Win32DiskImager to make an image it wouldnt write the same
image back to an SD card of the same size.

The upshot is that you have to shrink the filesize of the image slightly.

So....

Get your SD card

1) Use gparted to create some unallocated space:


http://gparted.org/download.php

This is a Linux "live" CD, so when you write the ISO to a CD and boot from it, it
gives you a virtual linux environment to run gparted in.
I ran it in safe mode as it had a wobbly with drivers otherwise for me.

When in gparted, make sure you select the device that is the SD card (should
be easy to tell by overall size shown).

Resize your main (largest) partition by clicking on it and dragging the bar left
to free up some space.
This smaller size is what we will resize the image to. Remember to click Apply
to make the change to the card.

If this produces an error, try reducing the partition less (so leave less in the
unpartitioned area).

1 of 4 18-09-2021, 19:48
Raspberry Pi: Shrinking image to fit on a smaller card - Smart Retro Forums http://smartretro.co.uk/forums/viewtopic.php?f=3&t=58

1.5) Create image file of your SD card with Win32DiskImager


Write new image file from newly reduced sd card.

You could do this next part in Linux (see end of post for details), but because I
use windows I do this:

2) Download Cygwin
https://www.cygwin.com/

Copy your SD image (created with Win32DiskImager) across to cygwin home


directory
Probably something like C:\cygwin64\home\{Username}

In a cygwin terminal type (this may be in /sbin at the root)

CODE: SELECT ALL

/usr/sbin/fdisk -lu {Image filename}

This will output the structure and size of the image.


An example is

CODE: SELECT ALL

Disk RPi1-2.6.0.16GB-shrunk.img: 14.7 GiB, 15811477504 bytes, 30881792 sectors


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: 0xb847d94e

Device Boot Start End Sectors Size Id Type


RPi1-2.6.0.16GB-shrunk.img1 * 8192 124927 116736 57M e W95 FAT16 (LBA)
RPi1-2.6.0.16GB-shrunk.img2 124928 29835263 29710336 14.2G 83 Linux

3) Then we resize the image with "truncate"

The calculation for your resize is (based on my numbers above)


End Sector of last (largest) device = 29835263
Add 1, because sectors start at 0

2 of 4 18-09-2021, 19:48
Raspberry Pi: Shrinking image to fit on a smaller card - Smart Retro Forums http://smartretro.co.uk/forums/viewtopic.php?f=3&t=58

29835263 + 1 = 29835264
Multiply this by the sector size (512) = 29835264 * 512 = 15275655168

So my truncate command would be:

CODE: SELECT ALL

truncate --size=15275655168 RPi1-2.6.0.16GB-shrunk.img

This then produces a smaller image filesize without overwriting a live partition.

Then when you write that image back to an SD card and boot it, make sure to
run raspi-config and extend the filesystem again.

If you want to do this in Linux there is an auto script that does it for you here:
http://sirlagz.net/2013/03/10/script-au ... downsizer/

Some useful links:


http://raspberrypi.stackexchange.com/a/7192/20719
https://github.com/Drewsif/PiShrink - Very popular
https://github.com/dweeber/rpiwiggle
http://softwarebakery.com/shrinking-images-on-linux
http://sirlagz.net/2013/03/04/how-to-re ... le-part-2/
https://cygwin.com/faq/faq.html#faq.using.not-found

Re: Raspberry Pi: Shrinking image to fit 


evilalex

on a smaller card Posts: 1


Joined: Sun Jan 29, 2017 8:13 pm
 by evilalex » Sun Jan 29, 2017 8:45 pm

Hi Floob,

i have used your manual to resize the image from my 32GB sd card.
only after the truncate when i have written the new image to an other card it
didnt work(the rpi didnt boot).
stil working on finding out what i did wrong.

but i found an mutch faster way to make a image.


since symantec has resurrected ghost, i used one of the latest builds (found
online) and this worked just fine.
it compresses the backup automaticaly and when writing back to any sdcard it
automaticaly resizes the partitions.
i even used this to copy the ext partition to an external hdd to let my rpi run
from it.(still needs the fat32 on the sdcard to boot)
ghost runs just as a program on the computer and works on any windows
system.

Re: Raspberry Pi: Shrinking image to fit 


Clax

on a smaller card Posts: 1


 by Clax » Fri Sep 15, 2017 5:33 pm Joined: Fri Sep 15, 2017 5:28 pm

3 of 4 18-09-2021, 19:48
Raspberry Pi: Shrinking image to fit on a smaller card - Smart Retro Forums http://smartretro.co.uk/forums/viewtopic.php?f=3&t=58

 evilalex wrote:
Hi Floob,

but i found an mutch faster way to make a image.


since symantec has resurrected ghost, i used one of the latest builds (found
online) and this worked just fine.
it compresses the backup automaticaly and when writing back to any sdcard
it automaticaly resizes the partitions.
i even used this to copy the ext partition to an external hdd to let my rpi run
from it.(still needs the fat32 on the sdcard to boot)
ghost runs just as a program on the computer and works on any windows
system.

Can you be more specific here? Is it just called Ghost, or in a suite of some
kind? Do you know the version number? What's the file extension of the images
it makes, or does it give you options on that?

TIA!

  3 posts • Page 1 of 1
Post Reply   

 Return to “Raspberry Pi” Jump to 

 Home ‹ Board index  Contact us  Delete cookies All times are UTC

Powered by phpBB® Forum Software © phpBB Limited


Privacy | Terms

4 of 4 18-09-2021, 19:48

You might also like