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

Caterpillaraoz
  • 263
  • 1
  • 2
  • 9
  • 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. – Caterpillaraoz May 04 '17 at 13:08
  • https://raspberrypi.stackexchange.com/questions/47773/disable-auto-file-system-expansion-in-new-jessie-image-2016-05-10 – Steve Robillard May 04 '17 at 13:19
  • 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. – Caterpillaraoz May 04 '17 at 13:21

1 Answers1

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.

Caterpillaraoz
  • 263
  • 1
  • 2
  • 9