Move the system to a smaller microSD card

I initially installed one of my systems on a 32Gb card, because it was the only one I had available at that moment.
Now I need it for another purpose, and I was wondering whether there is any easy way to transfer the system onto a smaller memory card, instead of having to reinstall everything from scratch.
Any suggestions?

You’ll need to resize the 2nd partition (shrink).

  • Put SD card into USB reader, then plug into a linux system with desktop.
  • Install gparted apt-get install gparted
  • then run gparted /dev/sda
  • Resize ext4 partition as needed

Then use Odroid win32diskimager (which supports reading only allocated partitions) to read to image file:

Then write to another card as needed.

That sounds easy enough.
Is there any Linux alternatives to the use of the Odroid DiskImager? I only have Linux at the office, and this would speed up the process (otherwise I’ll have to bring the card home for this step.
Thanks a bunch!

Yep, you can use DD, but you’ll need to define the total read size, else, will read the whole SD card:

dd if=/dev/sda of=mysuperimage.img bs=2GB count=1

Will read 2GB of data to image.

Although, you may need to read 4K block size and increase count accordingly (eg: count=128 = 128*4K).

I went with the DiskImager for Odroid way, but I can’t seem to be able to make it read the shrinked partition only.
It reads the whole card.
What am I missing? It actually looks like the “normal” Win32DiskImager to me. :open_mouth:

Sorry, I possibily gave wrong link, I’ve uploaded one i’am using:

Make sure box is ticked, then read image:

Yep, this is the correct one. Thanks!
Unfortunately I have not the time to try now, though. Will do tomorrow and update the thread.

EDIT: curiosity won, and I made time to finish the procedure. It seems like it worked, although I will have to wait until tomorrow to test it properly.
I might have the opposite problem now: it looks like I shrinked the image too much and now there’s a lot of free space on the card. Will I need to use gparted again to stretch it, or is there a way to do it from inside DietPi (I bet on the second, since this is what it does on first boot, isn’t it?)?

OK, I can confirm the procedure went fine and that everything is working smoothly.
How can I expand the partition to occupy the whole card now? I guess I could still put the card in my linux desktop and use gparted to do this, but since the pi’s usually do this after first run, I guess there is a proper command to achieve this directly in DietPi, isn’t it?

DietPi does this very early on in the boot process, else, you’ll get no end of issue with filesystem. Ideally, unplug + gparted would be safer, however, heres the code we use:

If it’s safer with gparted I’ll stick with it.
I thought there was some kind of option to expand the partition to its maximum size, like raspbian (maybe, not sure) does. :nerd:

EDIT: I went with the GParted solution, easy peasy :slight_smile: