3

I use 32gb micro sd card for my raspibian. I use dd this command to backup it. But, I found it is too large. How to shrink it before I backup it? Thanks.

Add words:
I had used a 16gb sd card. Then, I used sudo dd if=/dev/sdx of=~/myraspibianbackup.img bs=1m for backup. Later, I just used 32gb card for recovering image.

The df -h show me as below:

<code>
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        15G  5.2G  8.6G  38% /
devtmpfs        458M     0  458M   0% /dev
tmpfs           462M     0  462M   0% /dev/shm
tmpfs           462M   13M  450M   3% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           462M     0  462M   0% /sys/fs/cgroup
/dev/mmcblk0p1   63M   22M   42M  35% /boot
</code>

But, why my /dev/root is still 15G, not 31G. (eg. 16gb card=>15G 32gb card=>31G)

flakeshake
  • 6,244
  • 1
  • 16
  • 35
jefferyear
  • 193
  • 1
  • 3
  • 9

3 Answers3

3

Working with Raspberry Pi SD cards is painful on Windows.

I suggest using a gparted Live CD (based on Linux) to modify RPi partitions. You can boot from such a disk without touching your Windows install at all. This is much safer.

gparted Screenshot

A better option is the SD card copier (piclone) included in Raspbian itself , since it works with cards both smaller and bigger than the original. You must be running Raspbian on the Pi and need to use an additional USB cardreader (or USB harddisk/pendrive).

SD card copier screenshot

flakeshake
  • 6,244
  • 1
  • 16
  • 35
1

If you don't need an exact image clone or image file, but instead just need a logical mSD clone, then have a look at rpi-clone which is a terminal script. It allows to "clone" to a physically different mSD, and creates bootable mSDs.

A simple rpi-clone -f sda creates a fresh copy from the running system. Lateron, rpi-clone sda does a delta update.

Project is on GitHub: https://github.com/billw2/rpi-clone

TheDiveO
  • 1,591
  • 1
  • 11
  • 16
0

If you need to generate a compressed image, first overwrite free space with a contiguous stream of zeroes.

nice -20 dd if=/dev/zero bs=1M of ~/nulls ; sync ; rm ~/nulls

Then halt and make your image.

xz -e9v image.dd this will usually generate a highly compressed file, usually smaller than the used space on the card.

xz -e5v is a lower-memory alternative.

MatsK
  • 2,882
  • 3
  • 17
  • 22
user2497
  • 681
  • 5
  • 8