Ubuntu Fix Squashfs 3 Create Corrupt Filesystems

=Using firmware mod kit=

Building with any mksquashfs 2.0, 3, 3.2, 3.4 versions from firmware mod kit with x64 ubuntu (I tried 14.04 to 15.10 + centos7) will create corrupt squashfs filesystems. (mksquashfs using squashfs v4 seems ok, although only tried on 15.04)

Errors like this where its munged together

squashfs-root/www/nmp.htmg��minus.gifh��minusbottom.gifi���msg.jsj���nfsd.htmk� squashfs_opendir: inode block -233897631 not found! dir_scan: Failed to read directory squashfs-root/www/nmp.htmg��minus.gifh��minusbottom.gifi���msg.jsj���nfsd.htmk�	 (f20f0161:dad) �.plusbottom.gifp�us.gifo� �Uredbull.gifq���Arestart_sequence.jpgr����roundedcornr_input.gifs���router-info squashfs-root/www/� squashfs-root/www/wan.htm���1start_update.htm���

Building on a x64 system with 32 bit mksquashfs binaries is ok on 14.04 and 14.10 but fails after 15.04.

From installing these;

sudo apt-get install lib32gcc1 lib32stdc++6 lib32z1 libc6-i386

<= 14.10 has these (ok, no corruption) ii lib32z1        1:1.2.8.dfsg amd64        compression library - 32 bit runt ii lib32stdc++6   4.9.1-16ubun amd64        GNU Standard C++ Library v3 (32 b ii  lib32gcc1      1:4.9.1-16ub amd64        GCC support library (32 bit Versi ii libc6-i386     2.19-10ubunt amd64        GNU C Library: 32-bit shared libr

>= 15.04 has these (corruption problem) ii lib32z1                 1:1.2.8.dfsg-2ub amd64            compression library - 32 bit runtime ii lib32stdc++6            4.9.2-10ubuntu13 amd64            GNU Standard C++ Library v3 (32 bit Version) ii lib32gcc1               1:5.1~rc1-0ubunt amd64            GCC support library (32 bit Version) ii libc6-i386              2.21-0ubuntu4    amd64            GNU C Library: 32-bit shared libraries for AMD64

CentOS7's i686 libc (32 bit) was even older 2.17 and also worked.

So the upshot is you need 32bit glibc 2.19 or older to not cause corruption.

=The fix/workaround= My method was to get the debs from 14.10 and extract them (dpkg -x), then copying the relevant libs to a folder (lib32).

Note libz is same 1.2.8 in all releases from last few eyars, just added for completeness)

-rwxr-xr-x  1 rich rich  134380 Oct 30 17:59 ld-linux.so.2 -rwxr-xr-x  1 rich rich 1738492 Oct 30 17:52 libc.so.6 -rw-r--r--  1 rich rich  116244 Oct 11  2014 libgcc_s.so.1 -rw-r--r--  1 rich rich  280108 Oct 30 17:52 libm.so.6 -rwxr-xr-x  1 rich rich  707488 Oct 30 17:53 libpthread.so.0 -rw-r--r--  1 rich rich  975360 Oct 30 17:53 libstdc++.so.6 -rw-r--r--. 1 rich rich  99888 Oct 30 20:07 libz.so.1

rich@830:/media/rich/Toshiba2TB/lib32$ for i in $(ls); do file $i; done ld-linux.so.2: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=6daaced2a28de6b5df98bbfe87c93d25fa800a71, stripped libc.so.6: ELF 32-bit LSB shared object, Intel 80386, version 1 (GNU/Linux), dynamically linked (uses shared libs), BuildID[sha1]=78c0362905c145cfc28aa2ff409962f3c8b2cb6b, for GNU/Linux 2.6.32, stripped libgcc_s.so.1: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=fe734d2cebb571337209b545f6828e922b365247, stripped libm.so.6: ELF 32-bit LSB shared object, Intel 80386, version 1 (GNU/Linux), dynamically linked (uses shared libs), BuildID[sha1]=c16d02069a24fb63d81b44ad1a3e23cb18c9d3b8, for GNU/Linux 2.6.32, stripped libpthread.so.0: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), BuildID[sha1]=8144e778c28f58027bda9b46bfb8877128e64297, for GNU/Linux 2.6.32, not stripped libstdc++.so.6: ELF 32-bit LSB shared object, Intel 80386, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=e0486d8e6f5bd1b07484e9125f141e78ee28f3e5, stripped libz.so.1: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=259d049fcdd8bb383f2a97e1b2f11f778c359649, stripped

Then pre-load them, the trick here is to use LD_PRELOAD for the libs and then feed that through the loader ld-linux.so.2

This example is packing a folder 'fs' big endian using the special hg612 mksquashfs (using one here that came with GPL'd firmware) to output rootfs_x.img.

LD_PRELOAD="lib32/libc.so.6 lib32/libgcc_s.so.1 lib32/libm.so.6 lib32/libpthread.so.0 lib32/libstdc++.so.6 lib32/libz.so.1" lib32/ld-linux.so.2 "hostTools/mksquashfs" fs rootfs_x.img -be -noappend -all-root

or rather than specifying each one;

export LD_LIBRARY_PATH=lib32 lib32/ld-linux.so.2 "hostTools/mksquashfs" fs rootfs_x.img -be -noappend -all-root

You can then build squashfs 3 filesystems on 15.04, 15.10 etc ok :)

=Testing= All the 32 and 64bit unpackers seem ok, so to test you can just list the contents of the archive.

./fmk_x64/src/others/squashfs-3.2-r2-hg612-lzma/unsquashfs -l rootfs_x.img

=Comments=