aristosv
Posts: 159
Joined: Mon Dec 08, 2014 7:47 pm

Clone to slightly smaller SD

Sun Apr 05, 2015 3:39 pm

I create an image of my RPi's SD card using Win32DiskImager. While working on the Pi, I never expanded the operating system to use the whole SD, hoping that this would keep the size of the image file smaller.

Now I want to copy that image on another SD card, which was supposed to be the same size as the one I was uisng on the Pi (16GB). Bu it seems this new SD is slightly smaller, so it wont let me burn the image.

Since I never expanded the operating system to use the whole SD, how can I create an image of the RPi while keeping the size of the image small?

thanks

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Clone to slightly smaller SD

Sun Apr 05, 2015 5:13 pm

Use a Linux system with gparted to reduce the size of the partition so it will fit the smaller card.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Clone to slightly smaller SD

Sun Apr 05, 2015 5:19 pm

DougieLawson wrote:Use a Linux system with gparted to reduce the size of the partition so it will fit the smaller card.
Um, no.

He already said that he never expanded the image, so his image (i.e., partition) is right now around 2Gb (or is it now 4Gb - well, it doesn't matter which).

I think the problem is that Wind32DiskWhatever just isn't smart enough to handle this (which is why I have never downloaded it, never used it, and never intend to).

So, the first part of your post (Use a Linux system ...) is entirely correct, but after that, it drifts off into nothingness (heh heh).

The right way to do this is to ditch Windows and Windows software, and then find any of the recent threads on this forum which explain how to do this in Linux (either on the Pi itself [best] or on a Linux bootup on your PC)
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Clone to slightly smaller SD

Sun Apr 05, 2015 5:22 pm

Did I mention using Win32DiskScrambler?

Er, no!
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

RobHenry
Posts: 452
Joined: Fri Sep 21, 2012 9:04 pm
Location: UK

Re: Clone to slightly smaller SD

Sun Apr 05, 2015 5:32 pm

aristosv wrote:I create an image of my RPi's SD card using Win32DiskImager. While working on the Pi, I never expanded the operating system to use the whole SD, hoping that this would keep the size of the image file smaller.

Now I want to copy that image on another SD card, which was supposed to be the same size as the one I was uisng on the Pi (16GB). Bu it seems this new SD is slightly smaller, so it wont let me burn the image.

Since I never expanded the operating system to use the whole SD, how can I create an image of the RPi while keeping the size of the image small?

thanks
Win32diskimager does a byte for byte copy of the SD card so it doesn't matter what size the underlying partitions are. As indicated by the other replies, there is no easy solution for this using windows software. You can temporarily turn your windows machine into a Linux machine using a live bootable CD - google will turn up many images you can use to make one.

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Clone to slightly smaller SD

Sun Apr 05, 2015 5:44 pm

You can use a Raspberry Pi booted from another SDCard with a USB SDCard reader or two.

That's a perfect Linux system to run gparted and dd although it's a bit slow.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

djole94hns
Posts: 53
Joined: Tue Mar 12, 2013 7:33 pm
Location: Novi Sad, Serbia

Re: Clone to slightly smaller SD

Sun Apr 05, 2015 7:05 pm

On Linux, use this script: http://sirlagz.net/2013/03/10/script-au ... downsizer/

If you get an "Error : Not an image file, or file doesn't exist", just comment out this line:

if [[ ! -e $1 || ! $(file $1) =~ "x86" ]]; then
echo "Error : Not an image file, or file doesn't exist"
#exit <-- THIS ONE
fi

It's a common bug, just ignore it.

This script works like magic, it's great at resizing partitions automatically.

troombatzia
Posts: 501
Joined: Fri Jun 29, 2012 4:27 pm

Re: Clone to slightly smaller SD

Sun Apr 05, 2015 8:41 pm

djole94hns wrote:On Linux, use this script: http://sirlagz.net/2013/03/10/script-au ... downsizer/

If you get an "Error : Not an image file, or file doesn't exist", just comment out this line:

if [[ ! -e $1 || ! $(file $1) =~ "x86" ]]; then
echo "Error : Not an image file, or file doesn't exist"
#exit <-- THIS ONE
fi

It's a common bug, just ignore it.

This script works like magic, it's great at resizing partitions automatically.
Thanks for posting. If you're the author of the script, double thanks ;)
English isn’t my first language, so please excuse any mistakes.

User avatar
Can-Toi
Posts: 68
Joined: Sat Mar 28, 2015 12:41 pm
Contact: Website

Re: Clone to slightly smaller SD

Sun Apr 05, 2015 8:53 pm

djole94hns wrote:On Linux, use this script: http://sirlagz.net/2013/03/10/script-au ... downsizer/

If you get an "Error : Not an image file, or file doesn't exist", just comment out this line:

if [[ ! -e $1 || ! $(file $1) =~ "x86" ]]; then
echo "Error : Not an image file, or file doesn't exist"
#exit <-- THIS ONE
fi

It's a common bug, just ignore it.

This script works like magic, it's great at resizing partitions automatically.
I don't know the script nor do I have the time to read review it, so I won't comment on the usefulness of it.

However, I do want to add, for the absolute beginners, that, in bash scripts, you can "comment out [a] line" by adding a #-character at the start of the line. The interpreter will then interpret everything after that character as a comment instead of as a to-be-executed command. By commenting out the exit line (where djole94hns added the #-character), the interpreter does not exit as that to-be-executed command is now a to-be-ignored comment. It will still echo the warning, as that line is not commented out.

One additional thing: This "if"-block is used to check whether or not the file specified actually exists and has the right format. Commenting out the exit command causes this check to be circumvented. The reason for this is that the check was probably to restrictive (only "x86" files) to function in this instance, but this also means that a check the original author thought necessary is now no longer in place. This may lead to problems, so be sure to select the appropriate file. (Imagine fuses in a electrical set-up: They offer protection against overcurrent. If you circumvent them, it's no problem as long as you can guarantee safe currents, but it's easy to see the danger of circumventing such a fail-safe...)
"The mind is the effect, not the cause"
- Daniel Dennett

jwatte
Posts: 203
Joined: Sat Aug 13, 2011 7:28 pm

Re: Clone to slightly smaller SD

Sun Apr 05, 2015 9:46 pm

The ability to read/write an extra sdcard on the pi is important!
There are USB microSD card readers for $6 or so.
Then you can transfer individual partitions using "dd," or you can use something like "cpio" to transfer files rather than blocks.

Return to “General discussion”