- CopterRichie
- Posts: 131
- Joined: Tue Mar 26, 2013 3:14 am
- Location: Los Angeles CA.
Using dd to backup a PI SD
May I ask please, I want to use Linux DD to make a back up image of my Raspberry Pi SD card now that I have the apps installed.
What is the best way to proceed with this?
Thank you.
What is the best way to proceed with this?
Thank you.
Re: Using dd to backup a PI SD
Something like this:
Take note of how the SD card is identified.
In my case it is /dev/sdb1.
Then:
This will compress the image using gzip.
To restore the backup on SD card:
All this must be done on a linux PC.
It won't work on the raspi!
Code: Select all
sudo fdisk -l
In my case it is /dev/sdb1.
Then:
Code: Select all
sudo dd bs=4M if=/dev/sdb | gzip > /home/your_username/image`date +%d%m%y`.gz
To restore the backup on SD card:
Code: Select all
sudo gzip -dc /home/your_username/image.gz | dd bs=4M of=/dev/sdb
It won't work on the raspi!
Re: Using dd to backup a PI SD
In your restore example, I think you need sudo on the dd command rather than gzip, so your example should look like this:
Code: Select all
gzip -dc /home/your_username/image.gz | sudo dd bs=4M of=/dev/sdb
Re: Using dd to backup a PI SD
Code: Select all
I think you need sudo on the dd command
There is sudo in front of gzip so I guess it is also applied to the dd command.
The command lines posted are almost exactly the ones I use myself when backing my SD card.
Re: Using dd to backup a PI SD
Maybe it depends on the distribution or which shell you are using. I've had mine be picky about where I place the sudo, so I always put it on the command that specifically needs it.
-
- Posts: 15
- Joined: Fri Oct 25, 2013 1:13 pm
Re: Using dd to backup a PI SD
Great instructions on how to create a compressed backup but I'm struggling to restore the image to a different SD card.
The original SD card seems to have two partitions but the one created using the restore command only seems to have one and will not boot successfully. I've spent some time on the web trying to find how to backup and restore a Raspbian image but most only cover backing up.
Has anyone cracked the problem of restoring an image that will boot?
The original SD card seems to have two partitions but the one created using the restore command only seems to have one and will not boot successfully. I've spent some time on the web trying to find how to backup and restore a Raspbian image but most only cover backing up.
Has anyone cracked the problem of restoring an image that will boot?
Re: Using dd to backup a PI SD
Don't try to backup a live system - plug your card into your pi with a USB adapter while it runs on another card
-
- Posts: 15
- Joined: Fri Oct 25, 2013 1:13 pm
Re: Using dd to backup a PI SD
I've created an image from the original PI SD card while inserted in my laptop SD card reader.
Using the created image on the laptop I'm now trying to restore that image to a new blank SD card (to act as a spare). Every time I try to do this only one partition is created on the new SD card where the original Raspbian install has two partitions.
(I'm not trying to backup or restore with the SD card(s) connected directly to the PI but using my laptop).
All I'm trying to achieve is to create a clone of the existing system (via an image) to act as a backup. Sounds as though this should be simple but that is proving remarkably challenging.
Using the created image on the laptop I'm now trying to restore that image to a new blank SD card (to act as a spare). Every time I try to do this only one partition is created on the new SD card where the original Raspbian install has two partitions.
(I'm not trying to backup or restore with the SD card(s) connected directly to the PI but using my laptop).
All I'm trying to achieve is to create a clone of the existing system (via an image) to act as a backup. Sounds as though this should be simple but that is proving remarkably challenging.
Re: Using dd to backup a PI SD
Can we check that the backup contains what you think it should contain? (I'm assuming you are being cautious and still have the original of which you trying to make a clone?)
What are the sizes of the two original partitions reported by the 'sudo fdisk -l' command?
What is the size of the (uncompressed) image file that dd created as a backup?
Hint: the sum of the first two should equal the third.
What are the sizes of the two original partitions reported by the 'sudo fdisk -l' command?
What is the size of the (uncompressed) image file that dd created as a backup?
Hint: the sum of the first two should equal the third.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
-
- Posts: 15
- Joined: Fri Oct 25, 2013 1:13 pm
Re: Using dd to backup a PI SD
Sizes all check out OK so must be something to do with the restore command given in the post above?
Re: Using dd to backup a PI SD
Some thoughts -
1. in the restoration command presumably you are substituting your own backup file name with the date embedded in it?
2. if you have uncompressed the backup to check the size, you could try a simplified restore with (changing the details for the input file appropriately)
3. note that the output path is simply /dev/sdb - NOT /dev/sdb1
4. is the SD card reader/writer internal to the laptop? There is anecdotal evidence that some built-in SD card slots don't write data via dd correctly.
1. in the restoration command
Code: Select all
gzip -dc /home/your_username/image.gz | sudo dd bs=4M of=/dev/sdb
2. if you have uncompressed the backup to check the size, you could try a simplified restore with
Code: Select all
dd bs=4M of=/dev/sdb if=/path/to/my_backup.img
3. note that the output path is simply /dev/sdb - NOT /dev/sdb1
4. is the SD card reader/writer internal to the laptop? There is anecdotal evidence that some built-in SD card slots don't write data via dd correctly.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
-
- Posts: 15
- Joined: Fri Oct 25, 2013 1:13 pm
Re: Using dd to backup a PI SD
Thanks ..... tried all this again being very careful to get all the filenames etc correct and again the same result.DeeJay wrote: 4. is the SD card reader/writer internal to the laptop? There is anecdotal evidence that some built-in SD card slots don't write data via dd correctly.
Then tried the exercise using Windows 7 on the same laptop and all worked just fine.
I think you might be right that the problem is dd with this built in SD card slot on the laptop.
Thanks
Re: Using dd to backup a PI SD
I'm unsure how I would get this to work in one go when my SD card with Raspbian on is in two partitions:
/dev/mmcblk0p0
/dev/mmcblk0p1
The former containing the boot data.
Any ideas?
/dev/mmcblk0p0
/dev/mmcblk0p1
The former containing the boot data.
Any ideas?
- DougieLawson
- Posts: 42177
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: Using dd to backup a PI SD
dd if=/dev/mmcblk0 of=/some/file/name/here BS=1M
That reads the raw device and creates a complete (fuzzy) image of all partitions. It's fuzzy because the filesystem is in use while you're doing it.
That reads the raw device and creates a complete (fuzzy) image of all partitions. It's fuzzy because the filesystem is in use while you're doing it.
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.
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.
Re: Using dd to backup a PI SD
Cheers Dougie, I have given that a try and it appears to be churning away. Only diff. is that I came across a similar post on Stackexchange earlier which suggests the same thing except BS=4M. I'm assuming the block size doesn't make a massive difference and may just depend on the class of the SD card?DougieLawson wrote:dd if=/dev/mmcblk0 of=/some/file/name/here BS=1M
That reads the raw device and creates a complete (fuzzy) image of all partitions. It's fuzzy because the filesystem is in use while you're doing it.
Also, by "fuzzy" do you mean still working?
- DougieLawson
- Posts: 42177
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: Using dd to backup a PI SD
Fuzzy means some files may be open, some files may be updated while you're copying them. (Stuff in /tmp and /var/log which, mostly doesn't matter.) Your copied filesystems may need to be fsck'd before you can use the backup.
BS=nnnM tells dd how much data to read on each I/O operation.
BS=nnnM tells dd how much data to read on each I/O operation.
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.
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.
Re: Using dd to backup a PI SD
Be careful with these method. I have a lot of problems restore my backup because image is maked with filesystem mounted. So I suggest you shutdown properly the rasp. put sd in Linux and make the backup with sd unmounted
Re: Using dd to backup a PI SD
I never bother with the block size when using dd. It works fine with just if= and of= for Pi use.
I'd never attempt it on a 'live' system (trying to copy the card its running off) - its asking for trouble.
I'd never attempt it on a 'live' system (trying to copy the card its running off) - its asking for trouble.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......
I must not tread on too many sacred cows......
Re: Using dd to backup a PI SD
Hi,
insert the SD card into your computer and type:
Code:
dmesg
maybe you will see something like this:
mmc0: new ultra high speed SDR104 SDHC card at address aaaa
[519666.121873] mmcblk0: mmc0:aaaa SL16G 14.8 GiB
The important part about this output is "mmcblk0"
Type the following from inside the folder where your image is located (i use an OSMC image which i downloaded before):
Code:
dd bs=4M if=OSMC_TGT_rbp2_20150929.img | pv | dd of=/dev/mmcblk0
Notice "pv" you have to download pv before you use the "dd" command
Code:
sudo apt-get install pv
Try it again:
Code:
dd bs=4M if=OSMC_TGT_rbp2_20150929.img | pv | dd of=/dev/mmcblk0
You will see a progress bar of the hole process.
Have Fun.
insert the SD card into your computer and type:
Code:
dmesg
maybe you will see something like this:
mmc0: new ultra high speed SDR104 SDHC card at address aaaa
[519666.121873] mmcblk0: mmc0:aaaa SL16G 14.8 GiB
The important part about this output is "mmcblk0"
Type the following from inside the folder where your image is located (i use an OSMC image which i downloaded before):
Code:
dd bs=4M if=OSMC_TGT_rbp2_20150929.img | pv | dd of=/dev/mmcblk0
Notice "pv" you have to download pv before you use the "dd" command
Code:
sudo apt-get install pv
Try it again:
Code:
dd bs=4M if=OSMC_TGT_rbp2_20150929.img | pv | dd of=/dev/mmcblk0
You will see a progress bar of the hole process.
Have Fun.
Re: Using dd to backup a PI SD
The fun was had more than a year ago!aporeg wrote: Have Fun.
Quis custodiet ipsos custodes?
Re: Using dd to backup a PI SD
If you get only one partition when cloning the image to an sd card, make the block size smaller when executing the dd command. bs=32k works, but bs=1M or bigger does not. The other option is to not specify a block size and dd will use the default of 512. It will work but takes forever.
Re: Using dd to backup a PI SD
I have made a script to run on linux that can help you guys to make a backup and a restore. Tested on ubuntu 16.04.
https://github.com/BrixSat/SdcardBackupRestore
Thanks in advance,
https://github.com/BrixSat/SdcardBackupRestore
Thanks in advance,
Re: Using dd to backup a PI SD
Is there any way to avid a "fuzzy" copy when using dd on the fly?
I often have problem that the clone sd card doesn't boot while file contents seem to be OK.
When I mount such fuzzy clone sd card on other linux pc, the name of "ROOT" partition becomes strange.
I often have problem that the clone sd card doesn't boot while file contents seem to be OK.
When I mount such fuzzy clone sd card on other linux pc, the name of "ROOT" partition becomes strange.
- DougieLawson
- Posts: 42177
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: Using dd to backup a PI SD
Use the the SDCard copier process that's been added to Raspbian, that's supposed to be reliable and give you a good copy.
https://www.raspberrypi.org/blog/anothe ... -raspbian/
https://www.raspberrypi.org/blog/anothe ... -raspbian/
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.
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.
Re: Using dd to backup a PI SD
Thank you very much for helpful information!
I can't use the GUI tool, but I find a command line tool, rpi-clone, and it works nicely to duplicate the SD card on the fly.
I can't use the GUI tool, but I find a command line tool, rpi-clone, and it works nicely to duplicate the SD card on the fly.