I had the need to shrink a 16GB microSD card to use the image on my other Raspberry Pi, but only had smaller SD Cards lying around. So what now?
After a lot of tests and googling i found a way to get this working on my Mac OSX.
Things you need:
- Apple Pi Baker
- gParted Live Image
- CD Burner and empty CD or an USB Stick with at least 256 MB
- big SD Card containing current Raspberry Pi image
- smaller SD Card (2GB, 4GB, …)
Apple Pi Baker is a GUI to copy Raspberry Pi or other .img files to a SD card or USB stick, like using dd from command line, but with the advantage of using a GUI and displaying the time remaining for the process to finish. Additionally you can use it to create a .img from a SD card (backup) or create a Raspberry Pi NOOB SD card.
Part I: gParted
Download gParted live image from http://gparted.org/download.php
When using a USB drive:
- convert the downloaded .iso to a .img in the directory containing the .iso with this Terminal command:
hdiutil convert source.iso -format UDRW -o destination.img
- then use Apple Pi Baker to copy the gParted.img to the USB Stick
When using a CD:
- open the .iso in Disk Utility
- Burn this image
Then connect the USB stick to a Mac or PC and boot from the USB stick (or boot from the CD).
Start gParted an then select the SD card (on Mac you will need to use a USB SD card reader as the internal SD card reader is not supported) and select the second (big) EXT4 partition and resize it to a bit bigger than the minimum size or a little bit smaller than the desired SD card size (1.9 GB for a 2 GB SD card).
eject the SD card and / or restart your computer.
Part II: create card image and restore
Use Apple Pi Baker to backup your (big) SD card. This will create a image in the size of the card, not in the size of your shrinked image!
The trick is to restore this image to the smaller SD card. This will work, because you shrinked all partitions below the size of your (smaller) SD card. Apple Pi Baker will diskplay a warning that the image is to big to restore to the SD card, but it will stop when the card is full.
Now we have the smaller SD card and we’re almost finished.
Part III: fix the SD card
Now insert the smaller SD card into your Raspberry Pi and power it on to boot.
Booting will fail as fsck will fail to repair the card automatically. But pressing CRTL-D to continue will fix the problem and reboot the Raspberry.
Part IV: backup the smaller SD card (optional)
Now it’s a good idea to backup the small SD card to a now smaller .img because the backup will always have the size of the card used. Use Apple Pi Baker for this again.
To fill the whole SD card use this command in the Terminal of your gParted Live CD / USB stick, where XXX is the name of the SD card (eg. /dev/sdc2):
# resize2fs /dev/XXX