• Blog
  • Papers
  • Datasets
  • Raspberry Pi Card Image Too Big

    04 July, 2017 | General Hackery

    No two SD cards are equal. Many are different capacities, despite claiming to be the same. On many occasions I've taken a backup of a card and attempted to copy it to another card of the same capacity from a different manufacturer, only to be told, at the last few kilobytes, "card not big enough". There is a horrible, horrible hack that will let you get around this.

    Bear in mind, if the card is anything approaching full, don't do this. You will lose data from the end of the card.

    First, DD the image onto the card

    dd if=./image.img of=/dev/sdb

    Obviously replace the filename of the image with your file, and sdb with the id of the card reader. Wait for the process to complete (bearing in mind there's no progress bar) and you'll end up with an error when it runs out of room.

    Now do this

    e2fsck -f /dev/sdb2

    and the command should throw a warning right away telling you the superblock is a different size to the card. Continue anyway and the command should give you a lot of information about the card but no further errors other than the one about the superblock. Now you can do this

    resize2fs /dev/sdb2

    This attempts to resize the partition, which will replace the superblock, eliminating your problem.

    If you do not understand what any of this is doing, please do not try it. I can't stress this enough, this is a dirty hack and you are highly likely to lose data. It's really here mainly for my own benefit.

    One further hint, once you've done this and it works, it makes sense to re-dd the image backup so it's of the smaller size so hopefully you won't need to do this again.