Posts: 38
Joined: Sat Jul 25, 2015 10:07 am

Backup/Restore with dd - Having issues

Mon Nov 28, 2016 4:18 am

Hello all.

After configuring my Pi 3, I shut down, put the microSD into my laptop, and basically ran:
sudo dd if=/dev/mmcblk0 of=/home/mike/raspberry.img

Then after a few months, the SD card corrupted, so I found the backup image, put the card back into my laptop, and ran:
sudo dd if=/home/mike/raspberry.img of=/dev/mmcblk0

The Pi now fails to boot. It doesn't even boot a little bit - monitor doesn't even come on. This is also the second time I've had to completely reconfigure the Pi, over a dd backup not working. Am I doing this wrong? I have done backup/restore with dd on laptops before with success, but they were normal hard drives.

Some questions:
  • /dev/mmcblk0 is the correct file to dd to/from, right? I'm trying to backup/restore the entire 16GB sd card. I also typically have /dev/mmcblk0p1 and /dev/mmcblk0p2 for the partitions.
  • If I instead just backup the main partition (/dev/mmcblk0p2), could I write the plain vanilla installer image (raspbian/jessie) to the card, and then over write just the second partition with my backup? As in copy raspbian-release-whatever.img to /dev/mmcblk0 ... then write my backup-raspbian-part1.img to /dev/mmcblk0p2 ? Trying to figure out a way around this issue.
Also something I noticed that might explain what I'm doing wrong. When I issue command "blkid" on the raspbian install image (right now "2016-09-23-raspbian-jessie-lite.img"), it replies with:
2016-09-23-raspbian-jessie-lite.img: PTUUID="5a7089a1" PTTYPE="dos"
.. which to me means the image has a partition table, with other inner partitions, thus is a whole-disk image file. But then, I issued: sudo dd if=/path/to/2016-09-23-raspbian-jessie-lite.img of=/dev/mmcblk0 conv=fsync, and then run "blkid" on /dev/mmcblk0 ... the output instead becomes:
/dev/mmcblk0: UUID="f39781f6-b968-4738-93ef-4d1af6861b99" TYPE="ext4"

This is why I think I'm doing something terribly wrong. I've written an image directly to the SD card (I think), but suddenly it's just a partition and no longer a partition table? It *does* work, if I then insert that card into the raspberry Pi. But maybe my understanding of how to properly backup/restore the Pi is severely lacking somehow?

Thank you all for your time. I'm seriously stumped here, and would love to be able to restore my img file without re-configuring everything all over again :|

Posts: 38
Joined: Sat Jul 25, 2015 10:07 am

Re: Backup/Restore with dd - Having issues

Mon Nov 28, 2016 4:33 am

Something else I just noticed. If I issue the command
sudo parted /path/to/2016-09-23-raspbian-jessie-lite.img
and then issue a "print" command, I get an expected layout with two partitions:

Code: Select all

Number  Start   End     Size    Type     File system  Flags
 1      4194kB  70.3MB  66.1MB  primary  fat16        lba
 2      70.3MB  1389MB  1319MB  primary  ext4
However, if I go over to my backed up image file, and issue the same command:
sudo parted /path/to/raspbian-backup.img
then issue a "print", I get this strange single-partition thing:

Code: Select all

Number  Start  End     Size    File system  Flags
 1      0.00B  15.5GB  15.5GB  ext4
Clearly this is the entire sd card, as it spans from zero all the way out to the 16GB limit (I think), yet the fat16 boot partition is mysteriously gone. I'm sure I made a huge mistake somewhere, but the chances of me accidentally typing in "/dev/mmcblk0p2" instead of "/dev/mmcblk0" several times in a row, while deliberately attempting to avoid doing that, seems a bit far fetched.

Also, if I use "losetup" to mount the img file to loopback device, I can then actually mount the whole thing to a folder and browse the entire OS! So somehow I'm making a dd backup copy totally wrong, or making a good copy and then totally ruining it somehow.

Oh My Stars!!! What I am doing wrong!?

User avatar
Posts: 16110
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Backup/Restore with dd - Having issues

Mon Nov 28, 2016 6:46 am

After doing the dd command to write to the SD card, are you ejecting the card and reinserting it to make the system pick up the new partition table?

Also, it looks like your backed up image file may be wrong. It shouldn't show a single partition like that. It almost looks like you used /dev/mmcblk0p2 when you created the backup, instead of /dev/mmcblk0

Posts: 38
Joined: Sat Jul 25, 2015 10:07 am

Re: Backup/Restore with dd - Having issues

Mon Nov 28, 2016 7:18 am

Hey man thanks for the input. I wasn't popping the card out and re-inserting after using dd. I was just popping it out of my laptop and inserting it directly into the Pi. Is there something special that happens when you reinsert to your laptop?

Yeah I know ... it totally looks like I used /dev/mmcblk0p2 ... but as stated, I'm 99.999% sure I simply used /dev/mmcblk0 only.

Return to “Troubleshooting”