0

I burnt a 2GB OS image on a 16GB sd card and went thru the whole configuration process (a good half day of work to adapt it to our needs) except for the resizing of the partition.

I would now, before expanding the filesystem and copying the databases on the SD, like to get a .img of the SD card for backup purposes. More precisely, I want to back up the 2GB partition of it containing the configured OS and not the whole card`s 16GB (of which 14 unformatted).

How to?

thank you

3
  • Please state a reason for downvoting - this is a commong problem when employing RPi in an industrial setting and has no clear answer on the internet. May 4, 2017 at 13:08
  • Not really relevant, I did not expand the image. I am looking for a way to take an image of the SD card with the unexpanded, configured OS without ending up imaging also the 14 GB of unallocated space. May 4, 2017 at 13:21

1 Answer 1

2

Re-writing answer adhering to Stackechange`s guidelines:

"trimming" an image is is quite easy, it takes just two linux commands -

First, determine the size of the actual partition of your interest inside the image

Second, trim it.

Be sure you have read-write permission to the disk partition containing the image file of you interest (i.e. if you are a windows user and are using a live linux distro just for this operation, mount your windows partition with r/w permissions) then run the command:

$ fdisk -l /filelocationofmyimage/myimage.img

this will return information in the format

Device Boot Start End Blocks Id System

Write down the highest end block value amongst the partition(s) of your interest contained in the image file lets call this value mypartendvalue

Trim the image running truncate --size=$[(mypartendvalue+1)*512]/filelocationofmyimage/myimage.img

The "+1" is needed since blocks are counted from zero and the parametrs we are passing to truncate is a size so without the +1 we`d lose one block.

3
  • If you had posted some information (what OS, output of sudo fdisk -l and what system you were using) you may have got an answer. The first is wrong for SD, the second is a clumsy kludge.
    – Milliways
    May 5, 2017 at 0:50
  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. Thanks.
    – Ghanima
    May 5, 2017 at 4:49
  • roger- fixing that now May 11, 2017 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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