We should all work on being more friendly, generous and considerate – the more people smile, the more the world will smile.

VE3SP How to make smaller backup images of Rpi SD card?

I always keep backups of my raspberry pi's, but the only way that I've ever seen to do this is using the dd command on OSX. It works fine, I keep a few backups this way, and it's very easy, but it becomes troublesome when every backup is the full size of the SD card, which is usually 16GB. I'm pretty sure I've seen people upload their rPi images to websites before with much smaller file sizes. Is there a better way to do this? Any way to backup a pi without a huge file size, or maybe compress it afterward?

 TinyURL was created here!
http://tinyurl.com/RpiSDcard


Backup, Restore, Customize and Clone your Raspberry Pi SD Cards (tutorial)

Check out sysmatt's script, i think it's exactly what you need.
https://reddit.com/r/raspberry_pi/comments/2ct1gn/backup_restore_customize_and_clone_your_raspberry/

http://sysmatt.blogspot.com/2014/08/backup-restore-customize-and-clone-your.html


A few more examples (you can scroll past the first bit):
http://lnx.cx/docs/vdg/html/ch02s02.html

Most involve using
'kpartx' / 'gparted' at some point, if you google that with 'raspberry pi' -
you find lots of examples, videos etc.

You can something like this to make the file sparse saving space
.cp -v --sparse=always pi.img ./tmp

A simple solution would probably be to compress the images. The empty space on the SD-card-image is probably represented by just 0's which would be really easy to compress. If I'm not mistaken, OSX comes with gzip2 pre-installed (a command line utility) altough I'm not sure about that.

There are a few ways to do this, here's a straightforward-ish one:
http://softwarebakery.com/shrinking-images-on-linux

Softwarebakery
Shrinking images on LinuxWhen creating images from existing ISOs you often need to allocate a number of MB for the image to at least fit the files that are in the ISO. Predicting the exact size of the image is hard, even for a program. In this case you will create an image that is larger than actually needed: the image is much larger than the files on the image are combined.
This post will show how to shrink an existing image to a more optimal size. We will do this on Linux, since all required tools are available there: GParted, fdisk and truncate.
https://softwarebakery.com//shrinking-images-on-linux

Shrinking Raspberry Pi SD Card Images
http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php

Cloning a larger SD card to a smaller one (with a catch)
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=13028




5 comments:

  1. Anonymous16:18

    Check out sysmatt's script, i think it's exactly what you need. https://reddit.com/r/raspberry_pi/comments/2ct1gn/backup_restore_customize_and_clone_your_raspberry/

    http://sysmatt.blogspot.com/2014/08/backup-restore-customize-and-clone-your.html

    ReplyDelete
  2. Anonymous16:19

    You can something like this to make the file sparse saving space.

    cp -v --sparse=always pi.img ./tmp

    ReplyDelete
  3. Anonymous16:21

    Hi, as many others I was looking for a way to shrink the size of a rpi sd card partitions for backup/restore, and move to other sd cards.

    Eventually I wrote a script that does the following after you slot the RPI sd card in a (linux) computer.
    - List available block devices so you can select the sd card you just slotted in your computer.
    - Determine minimum possible size of the partition you want to shrink (the raspbian partition is the second ).
    - Resize the file system to minimum plus 8% added free space.
    - Resize the partition to match the file system
    - Backup the resized partitions to an image for restore.

    The script works well at my (ubuntu) pc: The images are shrunk back properly according to parted and e2fsck, and I have successfully tested the images from every backup I made.
    Once an image is written back to an sd card one can obviously use the standard expand tools in raspi-config.

    For who is interested I have posted the script below, and I would be happy with any comments that can help me to improve to script: syntax, logic, efficiency, error handling, robustness, naming conventions, tricks, tips, etc.

    https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=148519

    ReplyDelete
  4. Anonymous16:22

    Backup, Restore, Customize and Clone your Raspberry Pi SD Cards (tutorial)

    https://www.reddit.com/r/raspberry_pi/comments/2ct1gn/backup_restore_customize_and_clone_your_raspberry/

    ReplyDelete
  5. Anonymous16:41

    How to make smaller backup images of Rpi SD card?

    https://www.reddit.com/r/raspberry_pi/comments/3oluxc/how_to_make_smaller_backup_images_of_rpi_sd_card/

    ReplyDelete

Thanks for your comments, Comments may take a day to show up