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

Is there a way to resize an .img file?

Fri Sep 09, 2016 12:38 am

I have an SD card in my raspberry pi running retropie. I want to be able save the configuration I've spent ages getting right, so that I can burn it to future cards. Basically I want a backup so that I can burn to multiple cards and also in case of SD corruption.

My problem is thus:

- I have a 16gb card and I've used about 75% of the free space

- If I make an image of the card using Win32DiskImager it takes up ~16gb i.e. the full amount of space of the card

- When I attempt to burn this image to another 16gb card, I can get an error telling me that its a few sectors too big

Now there are some other 16gb cards that I tried that I can burn the image to, but the failure rate was too high for what I need.
Is there any way for me to resize that partition somehow? Getting it down just a few hundred megabytes would be enough to ensure I could burn it to most if not all 16gb cards.

Is there something I can do whilst logged into the pi itself? or from an Ubuntu Live CD or USB via my PC?

It's killing me that it's just a few sectors over!!

wh7qq
Posts: 1340
Joined: Thu Oct 09, 2014 2:50 am

Re: Is there a way to resize an .img file?

Fri Sep 09, 2016 1:20 am

You might be able to resize your partition to a minimum size before using a disk imager and then image the partition rathen than the entire disk. Gparted is great for resizing existing partitions. You would then have /dev/sda1 and /dev/sda2 (empty) and you would image /dev/sda1. I have not tried to do this and you might have to use a linux imager to do it...downloading a separate live DVD or USB, ubuntu, mint or whatever. Worst case, 32G uSD cards aren't that expensive

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

Re: Is there a way to resize an .img file?

Fri Sep 09, 2016 8:24 am

i see that retropie is build ontop of rasbian
so maybe you can use piclone

or the one i use is rpi-clone script from github

https://github.com/billw2/rpi-clone

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

Re: Is there a way to resize an .img file?

Fri Sep 09, 2016 1:45 pm

Thanks I'll check it out

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

Re: Is there a way to resize an .img file?

Sat Sep 10, 2016 1:29 am

nl3prc wrote:
or the one i use is rpi-clone script from github

https://github.com/billw2/rpi-clone
When I run this I get an error saying "operation not permitted", even when I'm logged in as root:

Code: Select all

======== Clone Summary ========
Clone mode               :  rsync all files to sda root file system
Clone destination disk   :  sda
Clone destination rootfs :  /dev/sda2 (retpie) on /mnt/clone
Clone destination bootfs :  /dev/sda1 on /mnt/clone/boot
Verbose mode             :  off
===============================
Final check, is it Ok to proceed with the clone (yes/no)?: y
=> Mounting /dev/sda2 (retpie) on /mnt/clone
=> Mounting /dev/sda1 on /mnt/clone/boot
===============================
Starting the filesystem rsync to sda
(This may take several minutes)...rsync: chown "/mnt/clone/boot" failed: Operati                                     on not permitted (1)
rsync: chown "/mnt/clone/boot/COPYING.linux" failed: Operation not permitted (1)
rsync: chown "/mnt/clone/boot/LICENCE.broadcom" failed: Operation not permitted                                      (1)
rsync: chown "/mnt/clone/boot/LICENSE.oracle" failed: Operation not permitted (1                                     )
rsync: chown "/mnt/clone/boot/bcm2708-rpi-b-plus.dtb" failed: Operation not perm                                     itted (1)
Someone else seems to have experienced this and logged and issue but never followed up on it.

User avatar
rpdom
Posts: 15430
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Is there a way to resize an .img file?

Sat Sep 10, 2016 4:03 am

Don't worry about those warnings, they won't affect anything.

rsync (the command which copies the files) is trying to set the owner and group of the files it has copied into the new /boot area. That area uses an MS-DOS FAT file system which doesn't support file ownership, so it can't set it.

There is a simple fix for it. rsync can be told not to set the ownership of the files. That could be done when copying the contents of FAT filesystems.

However, as I said, the warnings are harmless in this case.

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

Re: Is there a way to resize an .img file?

Sat Sep 10, 2016 9:23 am

thats writh when you look ad the mounted patition of the cloned sd card and look in the boot directory you see that the owner and group is not set to 755 but to 644 this wil change as soon you boot from the cloned sd card

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

Re: Is there a way to resize an .img file?

Sat Sep 10, 2016 12:19 pm

Hi footwo,

See this post viewtopic.php?f=29&t=145712
and particulary the post of liudr
Success with your project!
Ferdinand

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

Re: Is there a way to resize an .img file?

Sat Sep 10, 2016 7:44 pm

Ferdinand wrote:Hi footwo,

See this post viewtopic.php?f=29&t=145712
and particulary the post of liudr
Amazing. This is exactly what I needed, and it's simple too.

Thanks!

Return to “Beginners”