Page 1 of 1

SD error not enough sectors to replace image

Posted: Wed May 31, 2017 4:21 pm
by Canedje
I had a problem that my SD 16Gb card was broken.
I bought a new 16GB SD card and tried to replace the image by Win32Diskimager.
This is generating an error saying not enough sectors to install image (there is a small difference between image and SD).
How can I still get the image on the SD???
Please help and give some advice.

What make sense to make a back-up and not able to use it anymore?
The actuall used space is only about 30% of the total amount of space.
So frustrating this :evil:

Re: SD error not enough sectors to replace image

Posted: Wed May 31, 2017 6:37 pm
by drgeoff
1. When making a backup Win32DiskImager writes a file which contains every byte of the SD card. It does not know what is files and what is empty space.

2. SD card capacities are nominal values. Even cards from the same manufacturing batch can have slightly different actual capacities depending on how many bad blocks are mapped out during the testing phase.

3. The problem you encountered has been discussed here many times. Any decent search engine (not the forum's search feature) will find those and solutions.

Re: SD error not enough sectors to replace image

Posted: Wed May 31, 2017 6:52 pm
by Canedje
Thanks for the clear answer.
I did found the next solution and I tried:

https://raspberrypi.stackexchange.com/q ... 3796#13796

Unfortunatly after writing this image the raspberry won't start up ending the last boot message:

Code: Select all

3.231573] ---[ end kernel panic - not syncing: VFS: unable to mount root fs on unknown -block(179.7)
It looks like that Win32Diskmanager is not the right tool to make backup from a SD image to another SD (for example after crashing)
Is there a better way to make backup of a SD card fitting to another SD independing its slightly smaller new size?

Re: SD error not enough sectors to replace image

Posted: Wed May 31, 2017 7:40 pm
by rpdom
Canedje wrote:Is there a better way to make backup of a SD card fitting to another SD independing its slightly smaller new size?
In Raspbian there is the SD card copier program (piclone) that will copy the contents of the SD card in the Pi to another SD card in a USB card reader. It will resize the contents to fit the new card.

Re: SD error not enough sectors to replace image

Posted: Wed May 31, 2017 7:51 pm
by Canedje
Thanks for the answer.
I'm using NOOBS is it the same over there?

I did google on picloner but couldn't find a fitting link?

Did you mean: "SD card copier" from Raspbian?

Re: SD error not enough sectors to replace image

Posted: Wed May 31, 2017 7:59 pm
by rpdom
NOOBS is just an installer and boot manager, your real OS is probably Raspbian, in which case you will have piclone installed already. It should be available from one of the desktop menus, or from the command line. All my Pis are headless (no screen/keyboard/etc) running Raspbian Jessie Lite, so I can't check.

Re: SD error not enough sectors to replace image

Posted: Wed May 31, 2017 8:08 pm
by Canedje
Did you mean: "SD card copier" from Raspbian?
mentioned at this link?

https://www.raspberrypi.org/blog/anothe ... -raspbian/

Re: SD error not enough sectors to replace image

Posted: Wed May 31, 2017 8:11 pm
by rpdom
Canedje wrote:Did you mean: "SD card copier" from Raspbian?
mentioned at this link?

https://www.raspberrypi.org/blog/anothe ... -raspbian/
Yes. I thought I was clear with "In Raspbian there is the SD card copier program"

Re: SD error not enough sectors to replace image

Posted: Wed May 31, 2017 8:57 pm
by Canedje
Thanks again.

I was looking for "picloner" :roll:

Re: SD error not enough sectors to replace image

Posted: Sat Jun 03, 2017 7:01 pm
by Canedje
I'm not able to find SD Card copier in the menu
I do have a Raspberry Pi 2B
If I'm looking in the first line of the menu it says "Debian" does this mean I do not have Raspbian running? (I do not remember what I installed)
If I'm looking in the menu: Accessories I can not find "sd Card copier"
I only see an option called: "Disks"
If I do run that I do see the SD card and the SD card connected to the USB. (/dev/sdb)
I do not see an option to make a backup.
I only can mak an image copy of the SD card but do not find the USB connected SD card to place the IMG file.
In the basic I just want to make a clone.
How can I make a runnable clone from the SD card tot the USB SD card now?
Eather from running RPI desktop or RPI Shell
Or are there other options to shrink current Image files? (I tried by the method mentioned before but that corrupted the file )
Please help.

will this command makes a runnable clone??
sudo dd if=/dev/mmcblk0 of=/dev/sdb BS=1M

Re: SD error not enough sectors to replace image

Posted: Sun Jun 04, 2017 8:07 am
by pcmanbob
Hi.

if you have a desktop pc running Linux then you could use this script to shrink an existing image file. ( raspbian pixel or lite NOT noobs ).

Code: Select all

#!/bin/bash

IMG="$1"

if [[ -e $IMG ]]; then
	P_START=$( fdisk -lu $IMG | grep Linux | awk '{print $2}' ) # Start of 2nd partition in 512 byte sectors
	P_SIZE=$(( $( fdisk -lu $IMG | grep Linux | awk '{print $3}' ) * 1024 )) # Partition size in bytes
	losetup /dev/loop2 $IMG -o $(($P_START * 512)) --sizelimit $P_SIZE
	fsck -f /dev/loop2
	resize2fs -M /dev/loop2 # Make the filesystem as small as possible
	fsck -f /dev/loop2
	P_NEWSIZE=$( dumpe2fs /dev/loop2 2>/dev/null | grep '^Block count:' | awk '{print $3}' ) # In 4k blocks
	P_NEWEND=$(( $P_START + ($P_NEWSIZE * 8) + 1 )) # in 512 byte sectors
	losetup -d /dev/loop2
	echo -e "p\nd\n2\nn\np\n2\n$P_START\n$P_NEWEND\np\nW\n" | fdisk $IMG
	I_SIZE=$((($P_NEWEND + 1) * 512)) # New image size in bytes
	truncate -s $I_SIZE $IMG 
else
	echo "Usage: $0 filename"
fi
# sudo ./shrink-img-file.sh name of file #
To use save script as shrink-img-file.sh and make it executable
now with script and img file in same directory "sudo ./shrink-img-file.sh name of image file"
example sudo ./shrink-img-file.sh basebuild.img

it will shrink the image as small as possible leaving just enough room to allow it to boot.
once booted run raspi-config and expand to use all the SD card.

I got this script from this very forum a long time ago and never had any problems with it.

Re: SD error not enough sectors to replace image

Posted: Sun Jun 04, 2017 10:54 am
by Canedje
Thanks for the help.
Unfortunitly I do not run a desktop with Linux
Imbelevable how difficult it looks like to make just a clone/ backup of a RPI SD card.
I just thought I was enough to have Win32Diskimager to use.
I was wrong.
Until Now I still don't have a clone.
And it lookes like I have to do a lot of difficult things to get it arranged.
That worries me.
No I'm trying to install Ubuntu as a virtual machine on my desktop with Oracle VM VirtualBox.
Until now without succes

Re: SD error not enough sectors to replace image

Posted: Sun Jun 04, 2017 1:16 pm
by pcmanbob
So I have another option for you.

some assumptions.
1. you are running jessie pixel on your pi
2. you have a usb card reader that works on windows pc and pi
3. you have a spare sd card that is bigger than the image you want to shrink. ( IE 8gb image you need spare 16gb SD card.)

so place spare SD card in read and attach to windows pc, now COPY the img file on to the SD card. now thats copy as you would any windows file. it will take a while so don't panic.

while its copying on your pi create the scrip file I posted earlier and make it executable. making sure it called shrink-img-file.sh and its in the /home/pi directory.

once the the img file has finished copying to the SD card eject it and then plug the reader with SD card in to the pi. it should auto mount, and ask you if you want to open open file manager click OK

you should find the SD card has mounted at /media/pi/disk, but if it mounts some were else just make a note of the full path. now rename the image to some thing simple I will use test.img

next open a terminal window and type this sudo ./shrink-img-file.sh /media/pi/disk/test.img and hit enter.
once you are returned to the command prompt close you should find the img file has shrunk in size. so you can close all and eject you sd card.
now you can reconnect the card read and SD card to your windows pc and copy the img file on to your windows pc and now you have a small img to right to your SD card. don't for get on first boot you must run sudo raspi-config and expand the the os to use all the SD card.

Re: SD error not enough sectors to replace image

Posted: Mon Jun 05, 2017 8:35 am
by Canedje
Thanks again for this help.
The image itself is to big to copy to my new SD card, missing some Mb's.

Is it also possible to connect a USB HD with the image on it to my RPI and use your programm?

Re: SD error not enough sectors to replace image

Posted: Mon Jun 05, 2017 10:40 am
by pcmanbob
Canedje wrote:Thanks again for this help.
The image itself is to big to copy to my new SD card, missing some Mb's.

Is it also possible to connect a USB HD with the image on it to my RPI and use your programm?
If you USB HD is formatted NTFS then yes, it wont work if its FAT32 because FAT32 cant handle files bigger than 4Gb.

(note my SD card method worked because SD card was formatted RAW because I used my camera to format it, you cant use a flash drive because they are formatted FAT32.)

I have tested this on a USB HD and I have some advice before you try it.
1. don't use a HD which has any data already on it that you may want, best to use empty drive.

2. if you can re-partition the drive so you have a smaller drive ( twice the size of the file you are wanting to shrink ) and format it NTFS now this is not strictly necessary but if you are using a big HD it will take ages to run the program especially as you are accessing it over USB.

3. make sure the drive name has no spaces in it ( you can change this on windows pc using properties by right click on drive in question in my computer.)

4. rename the image file to some thing simple ( I.E clone.img) while the drive is connected to windows pc.

5. when you come to run the program you will find the USB HD is mounted under its own name so you need to change the path to the file remember I said you can get the full path from file manager. ( I.E /media/pi/HD because my drive was named HD )

Hope this helps.

Edit.
Been doing some more testing , found shrunk image will boot but cant expand it to use full SD card. raspi-config reports its not an SD card ? now this may be because HD was formatted NTFS or it may be because my psu is only 2A and kept getting low power warning which may have corrupted image. will try again when my replacement 2.5A psu arrives.

Re: SD error not enough sectors to replace image

Posted: Wed Jun 07, 2017 11:14 am
by Tanya_Raspberry
If it suits here, there is a possibility to set up an automatic backup directly on Raspbian via CrashPlan. Read the article - https://eltechs.com/crashplan-on-raspberry-pi/ (this is not an affiliate link)