

Hmmm...does it? In this case I'm running an older version anyway, but even if I were - I've used the copier tool included with the Pixel releases and have not seen an option to create an .IMG file that I could then upload to dropbox for a rainy day - only the ability to make another actual card (which is great, but not what I'm hoping to do here). Have I missed something terribly simple and obvious? Wouldn't be the first time, lol.B.Goode wrote:Side-stepping your question a little, if you are running a recent version of Raspbian Jessie you have access to an SD Card Copier (PiClone) which I think is designed to make a backup that is as large as needed to capture all your data, but no bigger.
And of course that limitation in the behaviour of physical backups is the reason why my suggested way forward will not work...W. H. Heydt wrote:As regards the initial problem...gparted will change the partition sizes, but the usual backup tools (win32diskimager and dd) copy the entire contents of the SD card, whether or not those blocks are part of a file system or not. It's the difference between a logical copy and a physical copy. You need a backup process that recognizes and uses partition allocation information.
Code: Select all
#!/bin/bash
IMG="$1"
if [[ -e $IMG ]]; then
P_START=$( fdisk -lu $IMG | grep Linux | awk '{print $2}' ) # Start of 2nd partition in 512 byte sectors
P_SIZE=$(( $( fdisk -lu $IMG | grep Linux | awk '{print $3}' ) * 1024 )) # Partition size in bytes
losetup /dev/loop2 $IMG -o $(($P_START * 512)) --sizelimit $P_SIZE
fsck -f /dev/loop2
resize2fs -M /dev/loop2 # Make the filesystem as small as possible
fsck -f /dev/loop2
P_NEWSIZE=$( dumpe2fs /dev/loop2 2>/dev/null | grep '^Block count:' | awk '{print $3}' ) # In 4k blocks
P_NEWEND=$(( $P_START + ($P_NEWSIZE * 8) + 1 )) # in 512 byte sectors
losetup -d /dev/loop2
echo -e "p\nd\n2\nn\np\n2\n$P_START\n$P_NEWEND\np\nW\n" | fdisk $IMG
I_SIZE=$((($P_NEWEND + 1) * 512)) # New image size in bytes
truncate -s $I_SIZE $IMG
else
echo "Usage: $0 filename"
fiCode: Select all
sudo ./shrink-img-file.sh name of file to shrink goes here.imgAhh..may give that a shot. (But nope - you were looking at a shot of a card plugged into USB - operating off of another Pi.tpylkko wrote:Are you trying to shrink a partition that is in use? I mean you appear to be using gparted on pi itself.
If so, you can get around this by not using the same pi. Shut it down and take out the card. Then use a linux laptop, another pi (or the same pi with another raspian card) or live dvd/usb boot a Windows laptop temporarily with gparted live disk. Insert the raspbian card. Then the partitions will be offline and unmounted. Shrink said partition and copy-paste all of them on a smaller card or whereever you want. Gparted allows you to copy paste entire partitions. Then full physical back up that smaller card to your cloud as an image file that you can write with windows. Or even simpler, just copy the partitions and later use gparted again to copy paste them back without having to create img file