User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

[SOLVED] Restore RPI to a smaller SD card

Fri Mar 04, 2016 3:52 am

Please read the last reply for solution.
A friend gave me an image of an 8GB card that was supposed to be the same as my cards. I tried to copy it to my card using win32disk imager. It reports that the image has 15564800 sectors and my card has 15564799. I have two identical cards that are supposed to be identical to his. Both were 15565799. He made the image using some linux command (dd I guess). Is this image not compatible with win32disk imager? If not, do I have to use linux to restore it? What is with that 1 sector difference? I have other 8GB cards that are 20MB less so I guess 1 sector less is not "real".
Last edited by liudr on Sat Mar 19, 2016 5:24 am, edited 1 time in total.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

drgeoff
Posts: 10765
Joined: Wed Jan 25, 2012 6:39 pm

Re: RPI image size 1 sector too big

Fri Mar 04, 2016 10:42 am

SD card sizes are nominal values. Faulty areas are disabled during testing by the manufacturer so even two cards from the same wafer can have different usable sizes. From different makers it is almost certain that sizes will be slightly different.

There are many posts here about that. Do a search (using an ordinary search engine, not the useless 'search' function on the forum) and you should find some ways to address the problem.

khaitom
Posts: 2
Joined: Fri Mar 04, 2016 11:45 am

Re: RPI image size 1 sector too big

Fri Mar 04, 2016 12:11 pm

Unfortunately there seems to be no solution to this problem for windows users that I can find. The linux solutions are many and varied (depending on the ability to read a new image or if you have to work from an existing image).

I won't tell you to search the forums or "google it" as I'm sure you already have and came here when you couldn't find an answer.There have been many posts on these forums and you'll get loads of hits but if you are looking for something simple then it seems to have been missed for the last 4 years.

It's one of the most the most disappointing aspects of the RPi for a new user. When you're first experimenting and may break things, being able to swap out the SD card for a backup is really useful. Something as simple as making an image and writing it to a new card, without another linux computer, is far too complicated when the sector size doesn't match exactly..

User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: RPI image size 1 sector too big

Fri Mar 04, 2016 4:14 pm

drgeoff,

So what you're saying is that I have to find two cards that both have zero of the same amount of sectors in order to make a clone? Will it matter where the bad/disabled sectors are as long as the source has the same total sectors as the target? I guess the two cards that I have are both 1 sector less than the one my friend got. Lucky him. I understand bad sectors, growing up with various floppies. Diskcopy on dos seemed to have always worked. I guess a linux file system is too complicated for simple beginners' solutions that khaitom wishes rpi has.

khaitom,

My problem is that now that I've got the image on a 16GB card, when I need to copy it out, I will likely get a 16GB image that requires 16GB cards and same issue if not more severe (double storage = more than double probability of bad sectors). Are there any GUI software that can shrink volumes? I got a dozen 8GB cards thinking that I was covered when I need clones or backups, in case of different brands. Alas. All for an illusion of safety.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: RPI image size 1 sector too big

Fri Mar 04, 2016 4:18 pm

use more intelligent backups
...
say backup
/boot
and rsync -vax / to a handy remote location and learn how to put them back on a SD card / disk as you want
or
reduce the size of the filesystem by 10% and backup that
or
various other methods can be done
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: RPI image size 1 sector too big

Fri Mar 04, 2016 4:21 pm

Maybe what raspi-config should do when it extends the filesystem is to leave say 50MB spare at the top end. Then you could usually copy it to a similar-sized card.

We would get bitter complaints about it though, so it would have to be an option and, by Murphy's Law, those who refuse to give up 50MB are going to be the only ones who need to take advantage of it later.

User avatar
GTR2Fan
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: RPI image size 1 sector too big

Fri Mar 04, 2016 4:23 pm

One possible workaround is to always create a backup image to the next size card down, assuming that its capacity is great enough to hold the entire occupied file space of the original. For example, my main Raspbian Jessie install is on a 32GB card, but actually occupies under 8GB of that, so it's possible to create an 8GB image of it that will fit onto any 16GB, 32GB, etc, card.

I wrote a guide on doing exactly this in-situ on the Pi with a handy utility written by Bill Wilson named rpi-clone. The guide also includes instructions on creating a shortcut with icon for accessing the utility without having to dive into a terminal to do so. You can find it here...

viewtopic.php?f=29&t=137693&p=914109#p914109

Re rurwin's comment above, I've sent a request to Bill to add an optional 'wiggle-room' switch to rpi-clone, so let's hope it happens as that would guarantee being able to clone to supposedly same-size cards if sufficient room is left vacant.
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: RPI image size 1 sector too big

Fri Mar 04, 2016 4:55 pm

There's also "rpi-wiggle" which lets you set the amount of "wiggle" room.

https://github.com/devotox/rpiwiggle/bl ... rpi-wiggle
viewtopic.php?t=17573&p=297385#p896113

User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: RPI image size 1 sector too big

Fri Mar 04, 2016 6:18 pm

Many thanks! I'll start with the raspi-clone, and move on to the next if I am too stupid to figure out :D

By the way, RPI foundation posts its images in a zipped file. The unzipped sizes are around 4GB for jessie. I wonder what methods they are using. In can case, a nice raspi-config of creating a clone (squeeze) is very much needed for beginners and people that don't use linux all day.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

khaitom
Posts: 2
Joined: Fri Mar 04, 2016 11:45 am

Re: RPI image size 1 sector too big

Sat Mar 05, 2016 7:06 pm

liudr wrote:drgeoff,
<snip> ... I guess a linux file system is too complicated for simple beginners' solutions that khaitom wishes rpi has.
The problem is more that for many RPi users it's their first experience with Linux and the only Linux machine they have. Telling them that the best way to put an IMG back onto an SD is to download and write a Linux boot CD, then jump through hoops to mount, resize, copy and save their IMG to make it small enough to put back onto another SD card is unnecessarily complicated. If they've come from a background of hitting a "Clone" in a GUI then it's a huge step.
liudr wrote:khaitom,

My problem is that now that I've got the image on a 16GB card, when I need to copy it out, I will likely get a 16GB image that requires 16GB cards and same issue if not more severe (double storage = more than double probability of bad sectors). Are there any GUI software that can shrink volumes? I got a dozen 8GB cards thinking that I was covered when I need clones or backups, in case of different brands. Alas. All for an illusion of safety.
I've been using a modified version of Win32DiskImager, the current version, 0.9.9 - not downloadable as a compiled binary, allows you to override the warnings that the card is too small, you may get another warning that the parts you will miss aren't empty and ignoring the second warning will probably leave you with a card that won't boot, but it can be successful.

I modified Win32DiskImage to make changes to the IMG file that I knew I could get away with for my purposes. My mods allow me to write previously unwritable images but is not at all stable or error resistant. Certainly not suitable for anyone to trust.

You can download both the source for Win32DiskImager (pick a snapshot of anything more recent than the "size matters" commits in the "code" section) and the tools to compile it (QT 5) from the sourceforge page. Compile the snapshot, rename the resultant .EXE to DangerousExperimantalWriter.exe (or similar) and copy it to the folder where Win32DiskImager was installed (as all the requisite .DLLs are already there).

...and, good luck.

User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: RPI image size 1 sector too big

Tue Mar 08, 2016 3:58 pm

Thanks. I found a windows GUI solution using Paragon's free software:

http://www.paragon-software.com/free/index.html

You have to install both backup and recovery, and partition manager.
With backup and recovery, you can back up both boot and linux partitions to hard drive. Then you can restore boot to another sd card, then the linux partition. It will automatically resize the linux partition if the remaining space on the sd card is not enough. You just can't use .img files. It has to be the actual card. With Partition manager you can resize partitions. So if you want, you can resize the linux partition before doing backups.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

W. H. Heydt
Posts: 12648
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: RPI image size 1 sector too big

Tue Mar 08, 2016 4:59 pm

khaitom wrote: I've been using a modified version of Win32DiskImager, the current version, 0.9.9 - not downloadable as a compiled binary, allows you to override the warnings that the card is too small, you may get another warning that the parts you will miss aren't empty and ignoring the second warning will probably leave you with a card that won't boot, but it can be successful.
Sounds like an excellent effort and I hope you get things to the point that they are moderately "idiot proof". Perhaps what is needed (and would, indeed, be very useful) would be an option to shrink an image down to near minimum size before creating the backup. Win32DiskImager may not be the ideal tool for that, though.

(It would be nice, even just for disk space, to be able to take an image backup that doesn't include more than a very small amount of free space, thus not only allowing one to go down in card size where possible, but write to cards that just aren't *quite* big enough.)

User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: RPI image size 1 sector too big

Tue Mar 08, 2016 11:59 pm

Paragon backup and restore does exactly that. You can either resize then backup or resize when restoring. I doubt win32disk imager understands file systems. Paragon also compresses images to selectable compression ratios. Blank space on card costs nothing. My Jessie lite that I expanded to the whole 8Gb card only takes 1 Gb with moderate compression.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

User avatar
GTR2Fan
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: RPI image size 1 sector too big

Wed Mar 09, 2016 12:30 am

liudr wrote:Paragon backup and restore does exactly that. You can either resize then backup or resize when restoring.
Thanks for letting us know this. I shall add it to my little notebook of alternative ways to get the job done. :)
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.

Return to “Troubleshooting”