1

I've been trying to make a backup of this raspberry pi SD card and I keep failing. I just needed it a little bit smaller so it would fit on another 32GB SD card that I have. After a lot of failures following tutorials (like pishrink) I shrank my root fs down to around 8GiB which should fit just fine. Then I copied it over with DD like this:

dd if=/dev/mmcblk0 of=small.img bs=1M count=10240 

and to the target like this

dd if=small.img of=/dev/mmcblk0 bs=1M count=10240 

Whenever I do this the root partition ends up with an unknown filetype. It is originally ext4, here is the working SD Card in gparted. You can see the root partition is happy as ext4.

enter image description here

And here is gparted on the second card after I try to write it. The boot partition is fine but something happened to the ext4 root partition. The PI actually boots up until it tries to load the root partition. This happens no matter how many times I try to copy the image, or even if I try to leave off the size in the dd command. What could I be missing here?

enter image description here

I should say that I did all of this copying on my ubuntu machine after removing the SD card from the PI. So the filesystem was not in use on the card when copying it.

I was finally able to get it to boot though by putting the bad SD card into my ubuntu machine and running fsck -l /dev/mmcblk0p2. I ctrl-c'd when it started talking to me about garbage.

enter image description here

And now gparted sees it as ext4 and it boots... But what the heck :) I don't get why this happened.

4
  • 1
    Try again but make sure the partition you are copying is not mounted. It appears to be mounted in your first picture presumably to your Ubuntu machine Commented Aug 5, 2022 at 18:35
  • @PonJar okay I just tried this, it takes about half an hour to do a run. I unmounted, checked with gparted that there were no locks but I got the same results. Commented Aug 5, 2022 at 19:09
  • 1
    Use mount to check if it's mounted or not Commented Aug 5, 2022 at 19:09
  • Okay, I tried it again. This time I checked to make sure it was not mounted by running mount. When it is mounted I see it, after I unmount and run mount they are gone. Same results though. Commented Aug 5, 2022 at 19:28

1 Answer 1

3

Don't try copying a filesystem that's in use - at best you'll get a bad copy that falls but at worst you'll get a filesystem that has hidden corruption. Instead, use a different system to copy the SD Card.

Remember that although you now say you use a separate system to perform the copy,

  1. The filesystem must still not be mounted (use mount to list the set of mounted filesystems - it must not be listed)
  2. Make sure you sync after writing to the SD Card to ensure everything has completed before pulling it to test in the target system

Next time you copy out the filesystem, consider using cat instead of dd. At best it'll be no slower and it's likely it'll be faster. (The cat command must be run as root - use sudo -s to get a root shell):

cat small.img >/dev/mmcblk0 # Write image sync # Guarantee completion on slow media 

If you were simply copying a full SD Card you could also use cat to copy it completely:

cat /dev/mmcblk0 >full.img # Read image 

In either case you could replace cat with pv to get a running progress report. (pv also had options to stop processing after a certain amount of data; see man pv.)

3
  • Okay I tried this but it ended with pv: write failed: No space left on the device. This is because the new SD card is slightly smaller than the original. They are both 32GB cards. Commented Aug 5, 2022 at 20:02
  • 1
    Hah :) The card did work though. I killed pv, and called sync. And it booted in the Pi Commented Aug 5, 2022 at 20:05
  • 1
    @confused good point - dd has an upper limit that I forgot to consider. Nevertheless the copy of valid data should have succeeded anyway Commented Aug 5, 2022 at 20:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.