Gert
Posts: 230
Joined: Wed Oct 24, 2012 10:19 pm

Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 6:42 am

Hello All,

I want to use 'Win32DiskImager.exe' to image an 8GB SD card (with RPI OS on it) onto a new one. (I believe the old one has started to get bad). I read the image from the old card into a 'img' file on my Win7 PC using aforementioned program. When launching the write operation from the image the program gives following error:

Code: Select all

Not enough space on disk: Size: 15759360 sectors Available: 15523840 sectors Sector size 512
Now what? Both are 8GB SanDisk SD Cards. (Bought in different years) But actual storage is ever so slightly different. I'm sure the RPI OS actually doesn't need the last bytes on the card (there was still plenty open space shown on the RPI with that card before I shut it down)

Any debug ideas are much appreciated.

Thanks,
Gert

fruitoftheloom
Posts: 27225
Joined: Tue Mar 25, 2014 12:40 pm

Re: Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 8:46 am

Raspbian Jessie now includes PiClone SD Card Copier, no need for another machine, just a USB SDHC Card Reader:

https://www.raspberrypi.org/blog/anothe ... e-raspbian
Take what I advise as advice not the utopian holy grail, and it is gratis !!

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

Re: Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 9:54 am

Have you tried formatting those cards with the SD Assoc. card formatter? Or format them in your camera, phone or tablet?
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

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

Re: Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 10:38 am

DougieLawson wrote:Have you tried formatting those cards with the SD Assoc. card formatter? Or format them in your camera, phone or tablet?
Another useless answer from Dougie becuase he failed to read the question properly.

When writing an image, the card is completely overwritten. How it was previously formatted is irrelevant.
Quis custodiet ipsos custodes?

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

Re: Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 10:52 am

drgeoff wrote:
DougieLawson wrote:Have you tried formatting those cards with the SD Assoc. card formatter? Or format them in your camera, phone or tablet?
Another useless answer from Dougie becuase he failed to read the question properly.

When writing an image, the card is completely overwritten. How it was previously formatted is irrelevant.
Hardly, since that will determine whether the SDCards are end-of-life and need to be dropped in the bin.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 11:37 am

Isn't the issue here that two "identical" cards - new ones even - from the same manufacturer, of the same nominal capacity, will have varying capacities due to their varying number of de-allocated bad blocks or whatever?

Gert just got unlucky in that he happened to choose the slightly bigger card to clone onto the smaller one, which W32DI won't attempt.

So, do as fruit recommended, use a tool which copies file by file.

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

Re: Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 12:32 pm

DougieLawson wrote:
drgeoff wrote:
DougieLawson wrote:Have you tried formatting those cards with the SD Assoc. card formatter? Or format them in your camera, phone or tablet?
Another useless answer from Dougie becuase he failed to read the question properly.

When writing an image, the card is completely overwritten. How it was previously formatted is irrelevant.
Hardly, since that will determine whether the SDCards are end-of-life and need to be dropped in the bin.
The OP included the error message from Win32DiskImager:

Code: Select all

Not enough space on disk: Size: 15759360 sectors Available: 15523840 sectors Sector size 512
Quis custodiet ipsos custodes?

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am

Re: Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 1:37 pm

I had the same issue a few years back.
But I was desperate and I needed the image NOW! (And I had 15 more cards which where too small...)
So I wrote a small C-program to throw away the last X bytes.
Then used the image.

As I said, a desperate act but it worked, although I must stress that I never needed more then 5% of the file system

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 1:46 pm

Likewise, you may use linux's dd to write the (slightly) oversized image file. It will simply fail/stop at the point of writing the last possible byte IIRC. Then you can run gparted to fix the partition (again, IIRC).

Brad_Pieeater
Posts: 5
Joined: Wed Jan 04, 2017 6:31 pm

Re: Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 4:47 pm

Hi Guys, I have the exact same issue as the OP and I wouldn't have a clue how to write a c program to fix the issue.
I'm new to RPi and so far have managed to create a working RPi 3 Rispbian Jessie Pixel solution running Kodi. I'm happy with where I've got to so far and have created a backup of the SD card using win32diskimager. I'm now testing restoring the image to a brand new (FAT32) SD card of the exact same size but am getting the same error as the OP.
Is there a fix for a techy numpty who only has a Windows 10 laptop to sort this out, or is there an alternate backup / restore strategy which I should be using so that I can clone SD cards.
Thanks

fruitoftheloom
Posts: 27225
Joined: Tue Mar 25, 2014 12:40 pm

Re: Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 5:16 pm

Brad_Pieeater wrote:Hi Guys, I have the exact same issue as the OP and I wouldn't have a clue how to write a c program to fix the issue.
I'm new to RPi and so far have managed to create a working RPi 3 Rispbian Jessie Pixel solution running Kodi. I'm happy with where I've got to so far and have created a backup of the SD card using win32diskimager. I'm now testing restoring the image to a brand new (FAT32) SD card of the exact same size but am getting the same error as the OP.
Is there a fix for a techy numpty who only has a Windows 10 laptop to sort this out, or is there an alternate backup / restore strategy which I should be using so that I can clone SD cards.
Thanks
As above I stated use PiClone all you need is an USB Card Reader and a microSD Card plugged into the RPi, not faffing around with Windows NT OS no worries with different byte sizes... Then just swap cards as and when needed, I do this weekly after updating Jessie..
Take what I advise as advice not the utopian holy grail, and it is gratis !!

Brad_Pieeater
Posts: 5
Joined: Wed Jan 04, 2017 6:31 pm

Re: Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 5:58 pm

Thanks for the advice fruit. Before I order a USB card reader could you give some (very) simple instructions on how to invoke / use piclone, or post a link to instructions. I've searched the forum and the wider net but am struggling to find a "how to".
My Pi 3 boots straight to the Raspbian / Pixel desktop (the one with a picture of a road) and I can't find piclone in any of the menus. Do I need to install it or is it something used from command line.
Assuming I get piclone working will it do as I wish i.e make an exact copy of an existing card which can then be inserted straight into the same Pi or a different Pi and work immediately without any tinkering, or am I being too naive ?
Thanks for the advice and assistance, it's much appreciated by us novices.

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am

Re: Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 6:00 pm

I have written something under windows but not tested extensively.
Especially not tested on images > 2Gbytes. (The 32-bit file-size limit)
as I have no data that big at the moment.

Tested with 2.9G image.

Code: Select all

//
// limit_file.cpp 
// Copy file limiting to certain kilobytes
// Quick hack for Raspberry-Pi cards
// Yes I know this program is far from perfect.
// But I spend only 20 minutes on it!
//

#include <stdio.h>
#include <io.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>

#define BUFFER_SIZE 4096*1024 // 4 Mbyte

int fdi,fdo; // file descriptor in/out

uint8_t buffer[BUFFER_SIZE]; // data buffer 

int main(int argc, char* argv[])
{ uint32_t max_kbytes;
  uint64_t max_bytes; 
  uint32_t count_in,count_out,count;
  // process file arguments: <program name> <maxbytes> <infile> <outfile>
  if (argc!=4)
  { fprintf(stderr,"Usage %s <filesize in bytes> <inputfilename> <outputfilename>\n",argv[0]);
    fprintf(stderr,"%s copies the <inputfilename> <outputfilename> limiting the size to  <filesize in bytes>\n",argv[0]);
    fprintf(stderr,"limiting the size to <filesize in bytes>\n");
    return 1;
  }
  // get max_kbytes 
  count = sscanf(argv[1],"%ld",&max_kbytes);
  if (count!=1)
  { fprintf(stderr,"Can't read byte count number '%s'\n",argv[1]);
    return 1;
  }
  max_bytes = (uint64_t)max_kbytes*(uint64_t)1024;
  // Open input file
  fdi = _open(argv[2],O_RDONLY|O_BINARY);
  if (fdi==-1)
  { fprintf(stderr,"Can't open '%s' for reading\n",argv[2]);
    return 1;
  }
  // Open output file 
  fdo = _open(argv[3],O_WRONLY|O_CREAT|O_BINARY,_S_IWRITE);
  if (fdo==-1)
  { fprintf(stderr,"Can't open '%s' for writing\n",argv[3]);
    close(fdi);
    return 1;
  }
  // Now copy
  do {
    count_in = read(fdi,buffer,BUFFER_SIZE);
    // Output minimum of what was read or what is left to do
    count_out = count_in < max_bytes ? count_in:max_bytes;
    count = write(fdo,buffer,count_out);
    if (count!=count_out)
    { fprintf(stderr,"Error while writing '%s' (disk full?)\n",argv[3]);
      close(fdi);
      close(fdo);
      return 1;
    }
    max_bytes -= count_out;
  } while (count_in==BUFFER_SIZE && max_bytes>0);
  close(fdi);
  close(fdo);
  return 0;
} // main 
Last edited by Gert van Loo on Mon Jan 23, 2017 7:57 pm, edited 1 time in total.

Gert
Posts: 230
Joined: Wed Oct 24, 2012 10:19 pm

Re: Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 7:27 pm

Hello All,

A quick update from my experiments.

I tried dd on a kubuntu VM using the existing image file from 'Win32DiskImager' tool. As expected it dumped tons of data onto the new card and exited out with error message at the end.

Code: Select all

dd bs=4M if=rpi1_backup_20170121.img of=/dev/sdb
...
dd: error writing ‘/dev/sdb’: No space left on device
1896+0 records in
1895+0 records out
Ignoring the message I plugged the newly written SD card into the RPI. On power up it didn't even boot. Not even showing a flicker on the red LED.

I wanted to try the newly written SD card in a second RPI and got the same failure.
The second RPI is a slightly different model version. So I am uncertain if that experiment proved bad SD card or incompatible RPI version.

RPI#1 = Model B Rev 1.0 256MB
RPI#2 = Model B Rev 2.0 512MB

I might try the new SD card copy tool next.
What about running gparted tool on the mounted 'original' SD card to make the partition smaller and then create new image?

Cheers,
Gert

fruitoftheloom
Posts: 27225
Joined: Tue Mar 25, 2014 12:40 pm

Re: Win32DiskImager two 8GB cards not same bytecount

Sun Jan 22, 2017 8:02 pm

Brad_Pieeater wrote:Thanks for the advice fruit. Before I order a USB card reader could you give some (very) simple instructions on how to invoke / use piclone, or post a link to instructions. I've searched the forum and the wider net but am struggling to find a "how to".
My Pi 3 boots straight to the Raspbian / Pixel desktop (the one with a picture of a road) and I can't find piclone in any of the menus. Do I need to install it or is it something used from command line.
Assuming I get piclone working will it do as I wish i.e make an exact copy of an existing card which can then be inserted straight into the same Pi or a different Pi and work immediately without any tinkering, or am I being too naive ?
Thanks for the advice and assistance, it's much appreciated by us novices.
It is in the Official Blog I linked to........
Take what I advise as advice not the utopian holy grail, and it is gratis !!

Gert
Posts: 230
Joined: Wed Oct 24, 2012 10:19 pm

Re: Win32DiskImager two 8GB cards not same bytecount

Mon Jan 23, 2017 4:10 am

@fruitoftheloom
fruitoftheloom wrote:Raspbian Jessie now includes PiClone SD Card Copier, no need for another machine, just a USB SDHC Card Reader:

https://www.raspberrypi.org/blog/anothe ... e-raspbian
The way I read the info on that app it does not have the ability to create an image file.
This does not work for me as I need to perform the steps:
  • 1. Save old SD card into image file
    2. In SD card reader replace old card with new card
    3. Write image into new card
Could you please comment?

I have USB devices attached to the RPI but they all contain important data and must not be overwritten.

Thanks,
Gert

Return to “Troubleshooting”