1

I was restoring a backup of my Raspberry Pi on a new micro SD card.
The original card was 16Gb and the destination card was 16Gb, too. However, during the transfer dd complained that there isn't any space left.
Now, I know that every card has a different real size, but how can I fix that? Is it possible to "chop" off few bytes and make the disk image fit in the card?

  • 1
    dd is not a good tool to backup, there may be data at the end of the image. You could get a bigger SD, and not do this again. instead use tar. You can also mount the image in your desktop Gnu/Linux, and create a tar from it. – ctrl-alt-delor Apr 18 at 17:58
  • Can you please elaborate it, maybe in an answer? How could I prime a raw disk from a tar archive? – tampe125 Apr 18 at 18:25
  • You would have to create the file-system, mount it, then un-tar into it. However there is a bit more to it for the PI (partitioning, and boot file-system) – ctrl-alt-delor Apr 18 at 18:29
1

Yes, you can "chop" bytes off a raw disk image file using truncate.

truncate -s 15G image.raw

Obviously, this will affect the data within the disk image. You probably want to shrink the contained filesystems so they are not truncated along the way. gparted is a tool with nice UI to achieve this.

gparted image.raw

Just shrink and move partitions until there is enough "unallocated space" at the end of the disk. If your disks partitions are defined in the MBR, you are done at this point. If a GPT is used, you need to leave a few bytes more and re-generate the secondary GPT after truncating.

How do I resize a disk image device? is somewhat related.

  • This answer is almost perfect, for anyone interested in further details, I'd suggest to take a look at superuser.com/a/1170779/83585 , since there's the full list of commands to use (gparted can't read directly from the file, you have to mount it first) – tampe125 Apr 29 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.