[GTALUG] Compressing an image of a microSD card

Lennart Sorensen lsorense at csclub.uwaterloo.ca
Thu May 14 15:38:37 EDT 2020


On Thu, May 14, 2020 at 02:26:53PM -0400, El Fontanero via talk wrote:
> Firstly, there's a good chance that if the space is unused, it can be made
> compressible.  If it were zeroed, it would have compressed very well.  Since
> the unit is linux-based, you have a very good chance of being able to
> loop-mount it. If, furthermore, you're lucky enough to be dealing with an
> old-style partition table on the card:
> 
>  * Start by seeing if you get a partition table: 'fdisk -l
>    RG350.SD.2020-05-14.img'
>  * Loop mount, e.g. 'mount -o loop,offset=$((512 * xxxx))
>    RG350.SD.2020-05-14.img tmp/' where xxx is the number of, e.g.,
>    512-byte sectors
>  * explicitly zero empty space: 'dd if=/dev/zero of=tmp/zero.dat bs=1M'
>  * rm tmp/zero.dat; umount tmp/
>  * recompress
> 
> If the partitioning isn't obvious, I would still look for a filesystem
> superblock in there somewhere, and then loopmount etc. as above.

If you enable partition support on your loop driver you don't need to
deal with the offset calculations and such.  It is unfortunately not
enabled by default for legacy reasons I believe.

modprobe -r loop
modprobe loop max_part=16

Then losetup /dev/loop0 imagefile

and you should have /dev/loop0p1 /dev/loop0p2 etc.

If the filesystem is ext based, zerofree is a nice tool to zero unused
space that seems to run faster than using dd and rm with a zero filled
file.

-- 
Len Sorensen


More information about the talk mailing list