I downloaded the official ubuntu-mate-16.04.img.xz (which is about 1.1GB) and extracted it. But the extracted .img is about 8.1 GB which is about 162 MB larger than the size of my sd card. So, I can't restore the .img to sd card. In other words Raspberry Pi MATE 16.04 Image is too Large for 8GB sd card

Since the .xz file was so small compared to .img, I suspect that the .img has free space, so I mounted the img and found that there was 4GB free space.

How do I resize the .img to reduce its size so that I can restore it to my sd card?

  • 1
    In the future, please make some effort in making sure your question is readable. Paragraphs and capitalization are good things.
    – Jacobm001
    Commented Apr 26, 2016 at 14:53

3 Answers 3


Ok so I finally found an answer and I wish to share it with you guys. My guess is that the creators created the compressed file from an expanded image by mistake.

The fact that the compressed file is nearly 1.1 GB, compared to 8.1 GB of the extracted files, proves this. Empty space will compress to a couple of bytes. If there were additional packages, there would have been a noticeable size disparity between the two images.

Shrinking the image

$ sudo modprobe loop # to enable loopback
$ sudo losetup -f  #request a new loopback device

#This will return the path to a free loopback device.this is /dev/loop0 for me

$ sudo losetup /dev/loop0 ubuntu-mate-16.04-desktop-armhf-raspberry-pi.img
$ sudo partprobe /dev/loop0
$ sudo gparted /dev/loop0

Now a separate window will show up with /dev/loop0 .. you will see two mounted partitions a boot and a root partition.

gparted snapshot

In my case the root partition had about 3.74 GB unused space, so right click on root and click resize and reduce the free space to about 10-20MB then click apply.

enter image description here

Now we don't need the loopback-device anymore, so lets unload it:

$ sudo losetup -d /dev/loop0 

Deleting unallocated part

$ fdisk -lu ubuntu-mate-16.04-desktop-armhf-raspberry-pi.img

Here is a sample output:

 $ fdisk -lu ubuntu-mate-16.04-desktop-armhf-raspberry-pi.img Disk
 ubuntu-mate-16.04-desktop-armhf-raspberry-pi.img: 7.5 GiB, 8053063680
 bytes, 15728640 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: 0xd882991d

 Device                                            Boot  Start      End
 Sectors  Size Id Type
 ubuntu-mate-16.04-desktop-armhf-raspberry-pi.img1 *      2048   133119
 131072   64M  c W95 FAT3
 ubuntu-mate-16.04-desktop-armhf-raspberry-pi.img2      133120 11487231
 11354112  5.4G 83 Linux

Then truncate the partition:

$ truncate --size=$[(11487231+1)*512] ubuntu-mate-16.04-desktop-armhf-raspberry-pi.img

Note the number 11487231 in the above command depends on what your output for fdisk is.

Now you should be ready with the image!

  • There are admitted problems in the MATE image. This post is one way of reducing the image size to make it fit on an 8GiB SD. The WiFi problem fixes are proposed for July. If you are going to modify the image you should also move the ext4 partition to 139264 (a 4MiB Erase Block boundary).
    – Milliways
    Commented Apr 27, 2016 at 12:42
  • Thank you! :-) Only... This solution assumes you're already running some flavour of Linux on the Pi or elsewhere. How can those folks who currently don't have a running Linux instance, but are stuck in Windows or MacOS, accomplish the same result? Much obliged!
    – user45699
    Commented Apr 27, 2016 at 21:15
  • @Schurdl a live linux DVD will work as well. Commented Apr 28, 2016 at 7:14
  • you can try a live linux DVD or a virtual machine but if you want to do it on windows try cygwin Commented Apr 28, 2016 at 10:23

Are sure it's Raspberry Pi dedicated image file? Your filename doesn't specify that it's for the Raspberry Pi. You can download the correct image from here: https://ubuntu-mate.org/raspberry-pi/ and also follow the guide to write it on your sd card.

  • Yes it has raspberry pi armhf in its file name. I just removed it to reduce the length of te question Commented Apr 26, 2016 at 14:50
  • So don't worry. They write that you need at least 8GB sd card. Just follow the guide and everything should be OK. If you occur some errors just edit the original post with logs.
    – Huczu
    Commented Apr 26, 2016 at 19:57
  • Nope, following their instructions won't work, and it's already 2017. The extracted image size simply is bigger than the size of the 8GB sdcard by a few blocks.
    – Quan To
    Commented Jan 18, 2017 at 2:57

There is also a pishrink script that does this: https://github.com/Drewsif/PiShrink

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.