Backup SD
Now I have got my SD card set up properly with the correct wifi drivers etc on Debian 19-04, what is the easiest way to create an identical bootable SD card? I have already had to start from the beginning a few times when something has gone wrong. I have an Ubuntu machine and win7 available to do this if needed.
I have seen a few discussions similar to this but no clear option recommended.
Thanks in advance,
I have seen a few discussions similar to this but no clear option recommended.
Thanks in advance,
Re: Backup SD
I would recommend looking into the "dd" command on your Ubuntu installation, but be incredibly careful with it as it has the potential to destroy data if used incorrectly. Backup first! 
In general, the command is used like so, where DISK is the device name such as sdc and where YOURUSER is your username:
This example would backup your stick to your home directory. You would then write the image back to another stick with a command like:
For more specific details, see the man page for dd, or look it up on the Ubuntu wiki.
Let us know how you get on.

In general, the command is used like so, where DISK is the device name such as sdc and where YOURUSER is your username:
Code: Select all
sudo dd if=/dev/DISK of=/home/YOURUSER/backup.img
Code: Select all
sudo dd if=/home/YOURUSER/backup.img of=/dev/DISK
Let us know how you get on.
Jam games and post-mortems: stevepdp.dev/games.html
- dhardingham
- Posts: 28
- Joined: Mon Jan 02, 2012 12:45 pm
- Location: Stevenage, UK
Re: Backup SD
I use the Windows Win32DiskImager program to read everything off my SD card and store it in a .img file. I can then write this to a different SD card, if I ever need to 

David Hardingham
Re: Backup SD
Thanks for both these replies , I will try both your suggestions and report back.
Re: Backup SD
I just tried this method but it only created a 77mb image file. How do you get it to read all partitions?dhardingham wrote:I use the Windows Win32DiskImager program to read everything off my SD card and store it in a .img file. I can then write this to a different SD card, if I ever need to
Update: This issue was resolved by using a USB card reader instead of the built-in one on my laptop.
- grumpyoldgit
- Posts: 1452
- Joined: Thu Jan 05, 2012 12:20 pm
Re: Backup SD
You have only backed up the FAT partition.
When I insert my SD card into the reader it is identified as SDD.
However, the Ubuntu disk utility gives more information than that. It identifies the FAT partition as SDD1 and the ext4 partition as SDD2.
What did you call your drive in the DD command?
When I insert my SD card into the reader it is identified as SDD.
However, the Ubuntu disk utility gives more information than that. It identifies the FAT partition as SDD1 and the ext4 partition as SDD2.
What did you call your drive in the DD command?
Re: Backup SD
The problem was experienced when using the windows disk imager. It was resolved by using a USB card reader instead of the inbuilt laptop reader. I haven't tried the dd method yet.
-Thanks
-Thanks
- grumpyoldgit
- Posts: 1452
- Joined: Thu Jan 05, 2012 12:20 pm
Re: Backup SD
I thought you had a Ubuntu PC.
Re: Backup SD
I have both Ubuntu and win7. I thought I would try the "safer" method first! However, I'm keen to get comfortable with using dd now, so will give that a go next.
Re: Backup SD
A word of warning. This may not always be possible.Nb8k wrote:I just tried this method but it only created a 77mb image file. How do you get it to read all partitions?dhardingham wrote:I use the Windows Win32DiskImager program to read everything off my SD card and store it in a .img file. I can then write this to a different SD card, if I ever need to
Update: This issue was resolved by using a USB card reader instead of the built-in one on my laptop.

I have been reading back the partion data so if I break something I can re-write the disk and get back to a usable SD. I tried to write the saved image to different SD card, using Win32diskimager, and got a message "Not enough space on disk". Both SD cards I am using are Sandisk 16GB so I thought would be the same capacity. Turns out one, the one I read the original image from, has a slightly greater capacity than the second SD card and the image from the first SD card was too big to fit on the second one even though they were both supposedly the same capacity.
Reading the image from one SD card gave a size of 15,633,408KB and the other gave a size of 15,558,144KB. A difference in capacity of 75264KB.
At some stage I would like to find some way of altering the image sizes so they all fit on both SD cards but as they contain Linux partitions, which windows doesn't normally see, I'm not sure how to at the moment. Just need to investigate the many partition management programs I guess - what a pain.
Hopefully you won't have the same problem.
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra
Please post ALL technical questions on the forum. Please Do Not send private messages.
Please post ALL technical questions on the forum. Please Do Not send private messages.
- RaspberryPiBeginners
- Posts: 224
- Joined: Fri May 11, 2012 6:54 am
- Location: Soham, Cambridgeshire
Re: Backup SD
I'm not sure if mine went wrong but i tried Win32DiskImager, and i wasn't able to restore it but might have been bad luck. Really need a spare card to try swapping the image into.dhardingham wrote:I use the Windows Win32DiskImager program to read everything off my SD card and store it in a .img file. I can then write this to a different SD card, if I ever need to
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD
Re: Backup SD
I had a similar problem where someone posted an 8Gb image for OpenElec. I tried loading it onto my 8Gb SD card but it failed saying I was a few thousand kb short of space. It seems not all SD cards have the same capacity.MrEngman wrote: .................................................
Reading the image from one SD card gave a size of 15,633,408KB and the other gave a size of 15,558,144KB. A difference in capacity of 75264KB.
...............................................
Hopefully you won't have the same problem.
- grumpyoldgit
- Posts: 1452
- Joined: Thu Jan 05, 2012 12:20 pm
Re: Backup SD
Just reduce the size of the Linux partition slightly with Gparted or similar.
Re: Backup SD
gparted can change the partion sizes BUT it makes no difference when using Win32DiskImager to write and read images. I use Win32DiskImager to write and read my SD card images. When saving an image from an SD card Win32DiskImager, as far as I can tell, reads the complete SD card regardless of what is on it, valid partitions or blank/unused space, so you get an image the size of the card. If you then try and copy the image to another SD card that is any smaller than the original one Win32diskimager complains about insufficient space and will not write it. Using dd (Windd) to write the image to a slightly smaller SD card may work as if I remember correctly dd, not sure about Windd but I guess it should work the same way, takes no notice of the size of where it is copying to until it actually runs out of space and then it complains of course. If the end of the image is unused space then using dd will write the image and fail at the end because of insufficent space on the smaller SD card but provided the part of the image not written contains only unused space and not part of any valid partition then the newly written SD card should be perfectly OK to use.grumpyoldgit wrote:Just reduce the size of the Linux partition slightly with Gparted or similar.
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra
Please post ALL technical questions on the forum. Please Do Not send private messages.
Please post ALL technical questions on the forum. Please Do Not send private messages.
Re: Backup SD
Did someone resolve the issue with capacity of different SD cards?
I'm having the same problem migrating an image originally backed up from a Sandisk SDHC 8gb and restoring to a Micro SDHC 8gb (I'm using a ModMyPi SD to Micro SD converter).
I'm having the same problem migrating an image originally backed up from a Sandisk SDHC 8gb and restoring to a Micro SDHC 8gb (I'm using a ModMyPi SD to Micro SD converter).
Re: Backup SD
The basic steps to get around the SD card capacity issue is to use Gparted on a Linux setup to reduce the size of the ext4 partition a bit (say 0.5G), then use dd to make an image of it then swap to smaller card and use dd to put this image onto the smaller card.
You will get an error msg at the end of the process that says that dd couldn't write the whole image to the new card but it doesn't matter.
You can test out your new smaller SD card and make sure everything is fine.
And then - stick with using the smaller SD card as your master copy and you can then use WinDiskImager in future to make backup copies of it that should fit on any SD card of the same stated capacity
regards
Simon
You will get an error msg at the end of the process that says that dd couldn't write the whole image to the new card but it doesn't matter.
You can test out your new smaller SD card and make sure everything is fine.
And then - stick with using the smaller SD card as your master copy and you can then use WinDiskImager in future to make backup copies of it that should fit on any SD card of the same stated capacity
regards
Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
Re: Backup SD
Does that actually work though unless you copy the partitions separately?
You can shrink the partitions on an SD card with Parted/GParted but when you image the card, doesn't it copy the empty space as well?
I had to reinstall Ubuntu last week because my system got messed up when I accidentally filled the hard disk when doing a DD from a 32 Gig SD card with a 2 Gig image on it.
You can shrink the partitions on an SD card with Parted/GParted but when you image the card, doesn't it copy the empty space as well?
I had to reinstall Ubuntu last week because my system got messed up when I accidentally filled the hard disk when doing a DD from a 32 Gig SD card with a 2 Gig image on it.

Alex Eames RasPi.TV, RasP.iO
Re: Backup SD
What you are doing is making he total of the 2 partitions fit well inside the "same" sized SD card.You can shrink the partitions on an SD card with Parted/GParted but when you image the card, doesn't it copy the empty space as well?
When you use dd to write this image back to a smaller card - the extra bytes don't fit - you get an error - but the error doesn't matter.
Then, when you use win32diskimager to take an image of the smaller card, you now have an image that will fit on any card that is at least the same size as the smaller card

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
Re: Backup SD
That's the bit I missed. I didn't bother checking to see if the "errored" card actually worked. No need to mess about doing separate partitions then.simplesi wrote:What you are doing is making he total of the 2 partitions fit well inside the "same" sized SD card.You can shrink the partitions on an SD card with Parted/GParted but when you image the card, doesn't it copy the empty space as well?
When you use dd to write this image back to a smaller card - the extra bytes don't fit - you get an error - but the error doesn't matter.

Alex Eames RasPi.TV, RasP.iO
Re: Backup SD
I've just made a backup copy of the 4GB SD card supplied with my RPi from Maplin.
I used Win32diskimager and the 'img' file created is about 4GB. I thought it might create a file containing only the space actually used on the card, but it seems to have included 'empty' SD card space.
If I later restore the img file to a new 16GB SD card, does it matter that the img file size is 12GB less than the capacity of the new card?
Will I still be able to use this extra 12GB for programs/data storage etc?
Thanks
clipper
I used Win32diskimager and the 'img' file created is about 4GB. I thought it might create a file containing only the space actually used on the card, but it seems to have included 'empty' SD card space.
If I later restore the img file to a new 16GB SD card, does it matter that the img file size is 12GB less than the capacity of the new card?
Will I still be able to use this extra 12GB for programs/data storage etc?
Thanks
clipper
Re: Backup SD
Will I still be able to use this extra 12GB for programs/data storage etc?
No and Yes
At the start - no - but you can just use raspi-config to expand the main partition to fill the card
Simon
No and Yes

At the start - no - but you can just use raspi-config to expand the main partition to fill the card

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
Re: Backup SD
Thanks Simon,
I'll buy a 16GB card now I know I can use it fully.
I'll buy a 16GB card now I know I can use it fully.
Re: Backup SD
I get a error at the start before it has written any data with Win 32 Dsik Imager.
I have 4GB image but it is really only a 1GB setup of xbmc and I wanted to copy to a 2GB card. I thought this trick would work but unfortunately not unless I miss something.
I have 4GB image but it is really only a 1GB setup of xbmc and I wanted to copy to a 2GB card. I thought this trick would work but unfortunately not unless I miss something.
Re: Backup SD
Thanks this helped me backup my openelec XBMC SD card for my RPi on my Ubuntu partitions Home folder.
Just a note, my SD card was named :-
Just a note, my SD card was named :-
Code: Select all
/dev/mmcblk0
Who ate all the Pi's?
Re: Backup SD
This looks clear but I wonder what the right 'dev' is because if I do a 'df' command or I list the /dev contents, there are loads of things in there.
My goal is to have a 'ready-to-write' image of the SD card so I can recover/copy the whole Pi in a couple of minutes.
My goal is to have a 'ready-to-write' image of the SD card so I can recover/copy the whole Pi in a couple of minutes.
Code: Select all
root@raspberrypi:/dev# ls
autofs loop6 ram14 tty10 tty30 tty50 usbdev1.1
block loop7 ram15 tty11 tty31 tty51 usbdev1.2
btrfs-control loop-control ram2 tty12 tty32 tty52 usbdev1.3
bus MAKEDEV ram3 tty13 tty33 tty53 vchiq
cachefiles mapper ram4 tty14 tty34 tty54 vc-mem
char mem ram5 tty15 tty35 tty55 vcs
console mmcblk0 ram6 tty16 tty36 tty56 vcs1
cpu_dma_latency mmcblk0p1 ram7 tty17 tty37 tty57 vcs2
disk mmcblk0p2 ram8 tty18 tty38 tty58 vcs3
fb0 net ram9 tty19 tty39 tty59 vcs4
fd network_latency random tty2 tty4 tty6 vcs5
full network_throughput raw tty20 tty40 tty60 vcs6
fuse null root tty21 tty41 tty61 vcsa
input ppp shm tty22 tty42 tty62 vcsa1
kmsg ptmx snd tty23 tty43 tty63 vcsa2
log pts sndstat tty24 tty44 tty7 vcsa3
loop0 ram0 stderr tty25 tty45 tty8 vcsa4
loop1 ram1 stdin tty26 tty46 tty9 vcsa5
loop2 ram10 stdout tty27 tty47 ttyAMA0 vcsa6
loop3 ram11 tty tty28 tty48 ttyprintk xconsole
loop4 ram12 tty0 tty29 tty49 uinput zero
loop5 ram13 tty1 tty3 tty5 urandom
Code: Select all
root@raspberrypi:/dev# df
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 7579104 3984488 3209768 56% /
/dev/root 7579104 3984488 3209768 56% /
devtmpfs 224436 0 224436 0% /dev
tmpfs 44900 236 44664 1% /run
tmpfs 5120 0 5120 0% /run/lock
tmpfs 89780 0 89780 0% /run/shm
/dev/mmcblk0p1 57288 16920 40368 30% /boot
stevepdp wrote:I would recommend looking into the "dd" command on your Ubuntu installation, but be incredibly careful with it as it has the potential to destroy data if used incorrectly. Backup first!
In general, the command is used like so, where DISK is the device name such as sdc and where YOURUSER is your username:
This example would backup your stick to your home directory. You would then write the image back to another stick with a command like:Code: Select all
sudo dd if=/dev/DISK of=/home/YOURUSER/backup.img
For more specific details, see the man page for dd, or look it up on the Ubuntu wiki.Code: Select all
sudo dd if=/home/YOURUSER/backup.img of=/dev/DISK
Let us know how you get on.
Mimi: Where'd you come from?
Doyle: My mom and the authorities are still trying to figure that out.
Doyle: My mom and the authorities are still trying to figure that out.