Home > Development, Linux > Make squashfs Disk Image

Make squashfs Disk Image

Raspberry Pi (and Cubieboard) SD disk images typically have two (or three) partitions: the first is Fat32 (50-100MB) and includes the boot files, while the second (>1GB) contains the main Linux image. With compression, the combined image can be reduced from several GB (of mostly empty space) to a couple hundred MB.

With a regular Linux desktop computer that has kpartx and mksquashfs installed, you can convert the second partition to SquashFS like this:

$ sudo kpartx -av image_you_want_to_convert.img
add map loop0p1 (252:5): 0 117187 linear /dev/loop0 1
add map loop0p2 (252:6): 0 3493888 linear /dev/loop0 118784
$ sudo mount /dev/mapper/loop0p2 /mnt
$ sudo mksquashfs /mnt converted_image.img -comp lzo -e lib/modules
$ sudo umount /mnt
$ sudo kpartx -d image_you_want_to_convert.img

  1. kaineanung
    May 22nd, 2014 at 05:46 | #1

    It is possible to do that on a virtual VMWare-machine?
    It is possible to do that with an backuped Image from a Raspberry with Win 32 Disk Imager?

    I am asking because I run into troubles in the 2nd Step: mounting!
    My Linux-machine tells me that the disk file type is missing! When I add the ‘-t’ Option with any filesystem-type I run into errors like ‘unknowned’ or ‘not found’?

    I think my Image have no Filesystem because when I run fdisk or testdisk over the Image it shows me that a FS is missing.
    Any ideas?

  1. No trackbacks yet.