RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    How to shrink a retropie image?

    Scheduled Pinned Locked Moved Help and Support
    raspberry pi 3retropieattract mode
    31 Posts 15 Posters 35.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • UDb23U
      UDb23 @kevlar
      last edited by

      @kevlar Under Windows you need specific software to access Linux partitions (ext2/ext3). I haven't tried it but Ext2 Installable File System For Windows (free) should do the job. Still you then need to write the image (e.g. with win32diskimager) to a 128GB USB stick or SD, remove unwanted files until size is less than 64 GB, and create the new image file.

      1 Reply Last reply Reply Quote 0
      • GaM3r2XtremeG
        GaM3r2Xtreme
        last edited by

        How are you accessing the partition currently in order to remove those roms? I'd imagine that even after freeing up enough space, the partition would still need to shrink before re-imaging and flashing in a 64GB drive.

        If your using windows, MiniTool Partition Wizard might be able to shrink this partition down for you. I am unsure if linux partitions are compatitble though, but it's worth a shot.

        K 1 Reply Last reply Reply Quote 0
        • U
          UP4IT
          last edited by

          Hi there,

          I have used this article and an Ubuntu VM to shrink SD images. It turns out all 32GB MicroSD are not exactly the same size.
          http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php

          1 Reply Last reply Reply Quote 0
          • P
            Pyjamarama
            last edited by

            The only thing that worked for me:
            https://github.com/Drewsif/PiShrink

            C 1 Reply Last reply Reply Quote 1
            • K
              kevlar @GaM3r2Xtreme
              last edited by

              @GaM3r2Xtreme , I'm using 7zip to extract everything from the image file, thats the easy bit though.

              1 Reply Last reply Reply Quote 0
              • GaM3r2XtremeG
                GaM3r2Xtreme
                last edited by

                Oh I see how your doing it now, @kevlar . So your using 7zip to delete these files out without flashing the .img to some drive that could handle at least 128GBs.

                Seems like PiShrink would be a viable option, but your not running on linux. If you have these, you could mount a USB hard drive that contains the edited .img file to your raspberry pi, install PiShrink from the git respatory, and then run the PiShrink

                Another option is to flash that edited .img file to another empty drive, and then shrink the partition down with a program like MiniTool Partition Wizard, and then back up those partition to a new .img file. This is a little trickier than the first option.

                I can't seem to find an easy program such as PiShrink for windows sadly. Maybe having an emulated linux environment might work. This link from the "How to Geek" blog explains how to get a bash terminal onto windows 10. Maybe install that, then install PiShrink on the virtual environment and run it to shrink the .img file.

                1 Reply Last reply Reply Quote 0
                • P
                  Pyjamarama
                  last edited by

                  Put VirtualBox in your Windows Box, install a Linux distro eg [CentOS 7 (Server Gnome)], add VirtualBox Add Guest Share folder (to share a Windows folder within Linux), copy your img from there to the Linux virtual machine and PiShrink

                  GtBFilmsG 1 Reply Last reply Reply Quote 1
                  • C
                    corpvs @Pyjamarama
                    last edited by

                    @Pyjamarama OH YES. I've been searching high and low for months and just found this post. Every method I found before this involved creating a dupe of the image which was a huge pain, but this method doesn't need to dupe anything unless you want it to. The only Linux I have is on a virtual machine with 100GB total space, so duping a 64gb image was otherwise impossible. Thanks!

                    1 Reply Last reply Reply Quote 0
                    • GtBFilmsG
                      GtBFilms @Pyjamarama
                      last edited by GtBFilms

                      This thread was a while ago, but I thought I'd follow the suggestion from @pyjamarama and after a bit of head-scratching and watching YouTube videos I finally got this working on my WIndows 7 PC.

                      I thought I'd document the steps I followed in case it is of use to someone else.

                      Apologies for the length, and the number of images, but I find that helps me when following these things. If it's not appropriate for the forum let me know and I will delete it.

                      Usual disclaimers that you follow any of these steps at your own risk, etc.

                      Issue:

                      • SD card img file is large - the capacity of the card, regardless of how full the card actually is.
                      • All SD cards have slightly different capacity, so often an image made of one card won't fit on another card, even though the capacities are meant to be the same.
                      • Storing backups of SD card images uses a lot of space, with each image being the full card capacity.
                      • Pishrink can reduce the size of the image file but only runs in Linux. It could be run on the raspberry pi itself but would take a long time to reduce the size of larger images.

                      I mainly used a good video tutorial at:

                      However the VM software they use wouldn't install on my PC, so I varied it a bit:

                      I used:
                      Linux Mint: https://www.linuxmint.com/download.php
                      Pishrink Script: https://github.com/Drewsif/PiShrink
                      VM Player: https://www.vmware.com/go/downloadplayer

                      I used Win32DiskImager to make an image file of my micro SD card.

                      Install VMPlayer.

                      Select 'Create New Virtual Machine'

                      0_1508106921106_vmplayer_createVM.jpg

                      Select 'Installer disc image (iso)' and point to the Linux Mint ISO

                      0_1508106940626_vmplayer_createVM_2.jpg

                      Leave it as 'Linux - Ubuntu' operating system

                      0_1508106962345_vmplayer_createVM_3.jpg

                      Give it a name and a location for the Virtual Machine
                      20GB Hard disk, single file

                      0_1508106976705_vmplayer_createVM_4.jpg

                      0_1508106990851_vmplayer_createVM_5.jpg

                      0_1508107015346_vmplayer_createVM_6.jpg

                      Right click the new virtual machine and 'Power On'

                      0_1508107032559_vmplayer_createVM_7.jpg

                      It boots to a trial desktop with an install CD icon.

                      0_1508107054390_vmplayer_createVM_8.jpg

                      Click the install CD and install the operating system to the virtual machine. Note the drive it is installing to is the 20GB virtual drive.

                      0_1508107071827_vmplayer_createVM_9.jpg
                      0_1508107107227_vmplayer_createVM_10.jpg
                      0_1508107120166_vmplayer_createVM_11.jpg

                      Remember the password you set!

                      After installation, shut down the virtual machine.

                      In VMWare, right click the (Powered off) machine and select settings.

                      0_1508107165301_vmplayer_createVM_12.jpg

                      Click the Options tab

                      0_1508107218246_vmplayer_createVM_13.jpg

                      Click Shared Folders and add one pointing to a directory in WIndows.

                      0_1508107249967_vmplayer_createVM_14.jpg

                      In Windows, place the pishrink.sh script and the Retropie SD card image into that directory.

                      0_1508107259128_pishrink_before.jpg

                      Boot up the Mint virtual machine.

                      On the Player Menu, select Manage -> Virtual Machine Settings

                      0_1508107376176_vmplayer_createVM_16.jpg

                      Change the CD mapping back to the physical drive instead odf the Linux Mint iso file.

                      0_1508107412969_vmplayer_createVM_17.jpg

                      On the Player Menu, click Manage, then 'Install VM Tools'

                      0_1508107460968_vmplayer_createVM_18.jpg

                      After a delay, the VMTools folder will open on the desktop (or the icon for the VMTools CD will appear, click it to open the VMTools folder)

                      0_1508107485238_vmplayer_createVM_19.jpg

                      Right click the VMwareTools tag.gz file and select 'Extract To'

                      Extract it to the Downloads folder.

                      0_1508107518333_vmplayer_createVM_20.jpg

                      Navigate to the Downloads folder, then the vmware-tools-distrib folder

                      0_1508107540732_vmplayer_createVM_21.jpg

                      0_1508107579605_vmplayer_createVM_22.jpg

                      Right-click somewhere in the folder (not on an icon) and select 'Open in Terminal'

                      A terminal screen opens, type:

                      sudo ./vmware-install.pl

                      0_1508107603733_vmplayer_createVM_23.jpg

                      Enter the password you set when you installed Linux Mint

                      Press 'Enter' to accept all of the default options

                      0_1508107625683_vmplayer_createVM_24.jpg

                      Once the install is complete type exit to exit the terminal window.

                      0_1508107661086_vmplayer_createVM_25.jpg

                      Close down the vmware-tools-distrib window to return to the desktop.

                      Right click on desktop and open a terminal window.

                      Check Mint can see the shared folder by typing:

                      vmware-hgfsclient

                      This should output the shared folder name

                      Check the folder is mounted:

                      cd /mnt/hgfs
                      ls

                      You can now access the shared folder.

                      0_1508107710156_vmplayer_createVM_26.jpg

                      Right click on the desktop and create a new folder, name it pishrink, we are going to link the shared Windows folder to this desktop folder, to make it easily accessible.

                      0_1508107723355_vmplayer_createVM_27.jpg

                      Mount it permanently on the Linux mint desktop by typing the following in a terminal:

                      ln -s /mnt/hgfs/shared-directory ~/Desktop/Name-of-the-folder

                      0_1508107756072_vmplayer_createVM_28.jpg

                      Close the terminal window.

                      You can now any SD card image files by placing them in the shared folder in Windows, then
                      starting the Linux Mint virtual machine.

                      Then...

                      Open the pishrink folder on the desktop, you should see the shared pi folder inside it, open it.

                      You should see the pishrink.sh file and the retropie image file.

                      right click in the folder and open a terminal window.

                      Type 'sudo ./pishrink.sh retropieimagefilename.iso'

                      Enter your password when asked.

                      0_1508107807353_vmplayer_createVM_29.jpg

                      The image will then be shrunk. Once complete a summary of the size reduction is displayed.

                      0_1508107822355_vmplayer_createVM_30.jpg

                      0_1508107831382_pishrink_after.jpg

                      You can burn this image to an SD card (using Win32DiskImager or similar).

                      The first time a Raspberry Pi boots with this card, it will resize the available file space back to the maximum that the card allows.

                      J M 2 Replies Last reply Reply Quote 7
                      • P
                        Pyjamarama
                        last edited by

                        Excellent! Your post should be pinned!

                        1 Reply Last reply Reply Quote 1
                        • S
                          sicboy101
                          last edited by

                          sorry for bump up the old topics
                          but how about the image that can't be shrink anymore.
                          is it possible to extract the image then delete some roms
                          then rebuild the image again?

                          thanks in advance

                          mituM 1 Reply Last reply Reply Quote 0
                          • mituM
                            mitu Global Moderator @sicboy101
                            last edited by

                            @sicboy101 What is your actual issue you're trying to solve ?
                            If you follow the guide above, you can read directly the Raspbian system and delete whatever you want from it . ROMs can be also deleted directly via the same method you use to transfer them - Samba shares, WinSCP - so there is no need to use this method just to delete some ROMs.

                            S 1 Reply Last reply Reply Quote 0
                            • S
                              sicboy101 @mitu
                              last edited by

                              @mitu i've got some image files that cannot fit to my SD card.

                              mituM 1 Reply Last reply Reply Quote 0
                              • mituM
                                mitu Global Moderator @sicboy101
                                last edited by mitu

                                @sicboy101 I see - you can use a live Linux system or the method above (using VMware to get to a linux system) to look inside the image itself before running the shrinking script.

                                Once you've booted the Linux system and made the .img file available to it, then use the instructions from https://blog.vinczejanos.info/2016/09/06/mount-sd-card-image-partitioned-image-w-o-kpartx/ to 'mount' the filesystem inside the image and perform any modifications you want on it. If you follow the instructions from the page above, the ROMs will be located in the /mnt/tmp2/home/pi/RetroPie/roms folder. But, since this might be a 3rd party image with unknown configs and modifications, YMMV.

                                S 1 Reply Last reply Reply Quote 1
                                • S
                                  sicboy101 @mitu
                                  last edited by

                                  @mitu thanks man! i'll try this ASAP.

                                  1 Reply Last reply Reply Quote 1
                                  • M
                                    moelarrycheese
                                    last edited by

                                    I had an image on a monstrously large 64GB SD card but knew there wasn't near that on there so I wanted to put it on a 16GB SD card. This worked and shrunk my image down to 7.7GB. Windows 7 Professional, 64 bit. Thank you!

                                    1 Reply Last reply Reply Quote 1
                                    • B
                                      bollwerk
                                      last edited by

                                      Excellent guide. However, I ran into this error when running the pishrink.sh:

                                      Creating new /etc/rc.local
                                      retropie: Inodes that were part of a corrupted orphan linked list found.

                                      retropie: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
                                      (i.e., without -a or -p options)
                                      resize2fs 1.42.13 (17-May-2015)
                                      Please run 'e2fsck -f /dev/loop0' first.

                                      ./pishrink.sh: line 148: 31375872 - : syntax error: operand expected (error token is "- ")
                                      resize2fs 1.42.13 (17-May-2015)
                                      Please run 'e2fsck -f /dev/loop0' first.

                                      ERROR: resize2fs failed...


                                      I tried running "e2fsck -f /dev/loop0" as instructed, but that didn't work either:

                                      e2fsck 1.42.13 (17-May-2015)
                                      e2fsck: Invalid argument while trying to open /dev/loop0

                                      The superblock could not be read or does not describe a valid ext2/ext3/ext4
                                      filesystem. If the device is valid and it really contains an ext2/ext3/ext4
                                      filesystem (and not swap or ufs or something else), then the superblock
                                      is corrupt, and you might try running e2fsck with an alternate superblock:
                                      e2fsck -b 8193 <device>
                                      or
                                      e2fsck -b 32768 <device>

                                      I'm completely lost...

                                      GtBFilmsG 1 Reply Last reply Reply Quote 0
                                      • GtBFilmsG
                                        GtBFilms @bollwerk
                                        last edited by

                                        Sorry @bollwerk ,

                                        This is beyond my capability! (I hate these unhelpful Linux errors!)

                                        Hopefully someone who is a lot more skilled with Linux than me will be along shortly and able to advise!

                                        B 1 Reply Last reply Reply Quote 0
                                        • B
                                          bollwerk @GtBFilms
                                          last edited by

                                          @gtbfilms No worries. I found a newer version of the same image today and it fits on the same card. Woot!

                                          At least I got some Linux experience from this exercise. =)

                                          1 Reply Last reply Reply Quote 0
                                          • J
                                            jacalvo @GtBFilms
                                            last edited by

                                            @GtBFilms I've been searching for a solution for this for weeks. Great post, really helping. Many thanks

                                            1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post

                                            Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                            Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.