What you are trying to do is not a good approach;
it will force a surely too big TFTP transfer.
It is better if you mod the initrd in order to turn on the SAMBA/NFS client or even using wget for an HTTP transfer that will bring at boot time your squashfs file.
You can see how this approach is used by Serva (I'm related to Serva development) when PXE booting/installing most of the live distros available today.
http://vercot.com/~serva/an/NonWindowsPXE3.html
you do not need to assembly a completely new initrd just create a complementary one adding the missing components (if any) and the correspondingly updated init script.
unsquashfs -s
did not have the capability of displaying the compression type used until this commit on 07 August 2009. This means that if you are running squashfs-tools
4.0 or older, you wouldn't be able to see the compression method used.
From this information, I derived a way to read the SquashFS 4.0 superblock to determine the compression method used (where $SQUASHFS
is the path to your SquashFS file):
dd if=$SQUASHFS bs=1 count=2 skip=20 2>/dev/zero | od -An -tdI | xargs
Alternatively, here's a function for those who would like to type in the filename at the end of the line:
sqsh_comp_method(){ dd if="$1" bs=1 count=2 skip=20 2>/dev/zero|od -An -tdI | xargs;};sqsh_comp_method
You will get a number (between 1 and 6 as of SquashFS 4.4). You can match that number to the following table to see what compression method was used:
╔═══╦════════════════════╦════════════════════╗
║ # ║ Compression Method ║ Compatible Version ║
╠═══╬════════════════════╬════════════════════╣
║ 1 ║ gzip ║ 1.0 and newer ║
║ 2 ║ lzma ║ 4.1 and newer ║
║ 3 ║ lzo ║ 4.1 and newer ║
║ 4 ║ xz ║ 4.2 and newer ║
║ 5 ║ lz4 ║ 4.3 and newer ║
║ 6 ║ zstd ║ 4.4 and newer ║
╚═══╩════════════════════╩════════════════════╝
(Source)
Note that the above dd
command will only provide a reliable output if the file you specified had a SquashFS 4.0 superblock. The following command will output "Not SquashFS 4.0
" if the file $SQUASHFS
does not have the SquashFS 4.0 magic number:
if [[ "$(dd if="$SQUASHFS" bs=1 count=4 skip=28 2>/dev/zero | xxd -p)" != "04000000" ]] ; then echo -n "Not " ; fi ; echo "SquashFS 4.0"
Explanation
In SquashFS 4.0 filesystems, the compression method is stored on the 21st and 22nd bytes of the superblock as a data type short
. dd bs=1 count=2 skip=20
will retrieve the short
, od -An -tdI
will turn the short
into a human-readable number, and xargs
is just to get rid of the leading spaces.
Before SquashFS 4.0, there was only the gzip method.
Old answer
unsquashfs
has the -s
flag for displaying SquashFS filesystem information.
Example usage:
deltik@node51 [/tmp]# unsquashfs -s template.squashfs
Found a valid SQUASHFS 4:0 superblock on template.squashfs.
Creation or last append time Thu Apr 30 23:07:23 2015
Filesystem size 47225242.44 Kbytes (46118.40 Mbytes)
Compression gzip
Block size 131072
Filesystem is exportable via NFS
Inodes are compressed
Data is compressed
Fragments are compressed
Always_use_fragments option is not specified
Xattrs are compressed
Duplicates are removed
Number of fragments 23629
Number of inodes 437076
Number of ids 1
If you just want the compression type identified, you could pipe the output through awk '/^Compression/{print $2}'
. Example:
deltik@node51 [/tmp]# unsquashfs -s template.squashfs | awk '/^Compression/{print $2}'
gzip
Best Answer
Doing this is suppported in Squashfs-tools 4.6 and later (released last year).
Converting a Squashfs filesystem from one compression type to another is mentioned in the documentation here (https://github.com/plougher/squashfs-tools/blob/master/README-4.6.1#L289).
As I wrote the above documentation (and Squashfs), there is no problem with me copying it here.
Sometimes you have an existing Squashfs filesystem which you want to regenerate using a different set of compression options, such as compression algorithm, block-size, tail-packing etc. Or you want to modify some parts of the filesystem such as excluding files, change ownership etc.
Obviously you have been able to mount the Squashfs filesystem and regenerate the filesystem by running
mksquashfs
on the mounted directory. But, this requires root access (which sometimes isn't available). The only other alternative until now has been to extract the Squashfs filesystem to an intermediate uncompressed directory, and then regenerate the filesystem by runningmksquashfs
on that. This, however, is slow and requires storage to store the uncompressed filesystem.unsquashfs
can now output a Pseudo file representing the input filesystem to stdout, andmksquashfs
can now read a Pseudo file from stdin. This allows the output ofunsquashfs
to be piped tomksquashfs
.Some examples follow.
If you had a GZIP filesystem and wanted to convert it to ZSTD, you can do:
If you wanted to change to XZ compression, increase to a 1 Mbyte block size, and use
-tailend
packing, you could do:If you only want the directory
foobar
you can tell Unsquashfs to only extract that:If you had inadvertently stored binary
.o
files, you can remove them by using the new "non-anchored"unsquashfs
exclude file functionality:If you want to update all the file timestamps to
now
, and make every file owned byphillip
: