Create backup of SD card 128GB -> 64GB

Hi all,

is there a possibility to create a backup of the SD card while shrinking it to a smaller card?

I currently have OSMC installed for my RP3 on a 128GB card, but the installation is only using a portion of that size. I want to have a second card ready in case my card crashes. But unfortunately I only have a spare 64GB card and not a 128 GB card.

I tried to shrink the image that I created under Windows with “Win32DiskImager.exe” with the PiShrink script which I found on github but it did not really work. The image was too big for the 64GB card.

GitHub - Drewsif/PiShrink: Make your pi images smaller!

result of “df-h”:

osmc@osmc:~$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 204M 0 204M 0% /dev
tmpfs 461M 6.6M 455M 2% /run
/dev/mmcblk0p2 117G 8.8G 103G 8% /
tmpfs 461M 0 461M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/mmcblk0p1 316M 37M 279M 12% /boot
//192.168.253.1/FRITZ.NAS/HDD4TB/mount 3.7T 3.6T 101G 98% /mnt/mount_fritz
tmpfs 93M 0 93M 0% /run/user/1000

Based on what I can see above the image should easily fit onto a 64GB card, but how can I achieve this?

Thanks a lot.
Tombar

If you don’t have Linux on hand boot gparted live CD

https://gparted.org/livecd.php

Thanks, but how do I then actually create the shrank backup?

Grab osmc-restore from here and run
sudo osmc-restore -f /

After you have reduced the size of the second partition to fit on your 64GB card you can use the simple Linux tool dd to transfer to the new card.

As my main PC is Windows I was a little bit overwhelmed with the above. What I did instead:

This time it worked just fine and the result was a 11 GB image which I copied to the backup SD card. The issue last time was that I worked with a source image that was accessed via a share instead of being on an ext4 formatted drive.

But I still have one challenge which I need to solve. How to extend the OSMC installation to the full size of the sd card? After flashing the image to the sd card with balenaEtcher OSMC is starting just fine and everything seems to work, But OSMC is not using the full size of the SD card
image

How can I extend the /dev/mmcb1k0p2 to the full size of my 64GB sd card?

fdisk clearly shows that the drive is bigger:
image

Well not sure why using the Gparted ISO instead of the Debian image would be overwhelming especially as Gparted would give you a one stop solution to your shrink and extend issue.
Also no need to use the SD card image with virtual box just give the USB card reader to the VM.

You also can use this live system giving you Gparted and clonezilla
https://clonezilla.org/related-live-cd/001_gparted-clonezilla/more_info.php

No, I meant that “osmc restore & backup procedure”. But maybe I just missed something.

I now achieved what I was planning, maybe what I did was too complicated and time consuming but at least it worked …

This worked perfectly. Thank You for the tip.

After doing this I had access to the sd card and was able to assign the unused space to the partition

Some screenshots if someone is interested what I did - Sorry, system was installed in German
image
image

Maybe I was a bit brief. My answer was not to your question about shrinking but a complete answer to your original question. My osmc-restore script runs on the RPi itself and will format the back-up SD card. You just follow the prompts.

But it looks like you’ve found a solution already.

yes I did not really knew what to do with a live linux. Meaning how to then create a image of the SD card. That’s why I created the image under Windows and did the rest as I wrote above.

Yes for linux experts it might look like I spent way to much time and additional steps, but it worked.