Move the system to a smaller microSD card

Having issues with your DietPi installation, or, found a bug? Post it here.
Post Reply
User avatar
Sciamano
Posts: 264
Joined: Sat Oct 15, 2016 12:18 pm
Location: Italy

Move the system to a smaller microSD card

Post by Sciamano »

Hello,
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?
Thanks
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: Move the system to a smaller microSD card

Post by Fourdee »

Sciamano wrote:Hello,
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?
Thanks
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:
http://dn.odroid.com/DiskImager_ODROID/ ... binary.zip

Then write to another card as needed.
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
User avatar
Sciamano
Posts: 264
Joined: Sat Oct 15, 2016 12:18 pm
Location: Italy

Re: Move the system to a smaller microSD card

Post by Sciamano »

Fourdee wrote: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:
http://dn.odroid.com/DiskImager_ODROID/ ... binary.zip

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!
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: Move the system to a smaller microSD card

Post by Fourdee »

Sciamano wrote: 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:

Code: Select all

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).
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
User avatar
Sciamano
Posts: 264
Joined: Sat Oct 15, 2016 12:18 pm
Location: Italy

Re: Move the system to a smaller microSD card

Post by Sciamano »

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. :shock:
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: Move the system to a smaller microSD card

Post by Fourdee »

Sciamano wrote: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. :shock:
Sorry, I possibily gave wrong link, I've uploaded one i'am using:
http://dietpi.com/downloads/misc/Win32D ... id-v1.3.7z

Make sure box is ticked, then read image:
Untitled.png
Untitled.png (11.47 KiB) Viewed 5858 times
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
User avatar
Sciamano
Posts: 264
Joined: Sat Oct 15, 2016 12:18 pm
Location: Italy

Re: Move the system to a smaller microSD card

Post by Sciamano »

Fourdee wrote:
Sciamano wrote: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. :shock:
Sorry, I possibily gave wrong link, I've uploaded one i'am using:
http://dietpi.com/downloads/misc/Win32D ... id-v1.3.7z
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?)?
User avatar
Sciamano
Posts: 264
Joined: Sat Oct 15, 2016 12:18 pm
Location: Italy

Re: Move the system to a smaller microSD card

Post by Sciamano »

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?
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: Move the system to a smaller microSD card

Post by Fourdee »

Sciamano wrote: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:
https://github.com/Fourdee/DietPi/blob/ ... #L102-L114
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
User avatar
Sciamano
Posts: 264
Joined: Sat Oct 15, 2016 12:18 pm
Location: Italy

Re: Move the system to a smaller microSD card

Post by Sciamano »

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. :geek:

EDIT: I went with the GParted solution, easy peasy :)
Post Reply