Introduction
SquashFS is a compressed, read-only filesystem for Linux, written by Phillip Lougher. An image holds a
whole directory tree, with its permissions, owners, times, links and device nodes, compressed in blocks
that the kernel decompresses as files are read. It is used for live CDs and installers,
Snap packages, AppImages, router and
embedded firmware and container images. The files are named .squashfs, .sqsh or
.sfs, or have no extension at all, and are often found inside a larger file.
The format has changed over the years. Each version has its own layout, so each is a separate format on this site; the explorer tells them apart from the first bytes.
Variations
| Format | Variation | About | Open |
|---|---|---|---|
.SQUASHFS | SquashFS 4.0 filesystem | The current format: six compressors, xattrs, NFS export table, either byte order. | Open |
.SQUASHFS | SquashFS 3 filesystem | Gzip only, bit-field inodes, fragments, sparse blocks; found in 2006 to 2009 firmware. | Open |
.SQUASHFS | SquashFS 2 filesystem | The first version with fragments; no inode numbers or link counts. | Open |
.SQUASHFS | SquashFS 1 filesystem | The first version: 32 KiB blocks, no fragments, 3-byte inode headers. | Open |
SquashFS 4.0 filesystem
The current format, since 2009 and in the Linux kernel since 2.6.29: six compressors (gzip, lzma, lzo, xz,
lz4 and zstd), extended attributes, an NFS export table and up to 1 MiB blocks. The file starts with
hsqs (little-endian, nearly every image) or sqsh (big-endian), and the version at
byte 28 reads 4, then 0 at byte 30.
SquashFS 3 filesystem
The version of 2006 to 2009 that most router and set-top-box firmware used: gzip only, inodes packed into bit-fields, fragments, sparse blocks and, in 3.1, an inode lookup table for NFS. It starts with the same magic as version 4, with 3 at byte 28, and has a 119-byte superblock.
SquashFS 2 filesystem
The first version with fragments. It keeps no inode numbers or link counts, and a time only in file and directory inodes. 2.0 does not sort the entries of a directory, 2.1 does. It starts with the same magic, with 2 at byte 28.
SquashFS 1 filesystem
The first version: 16-bit block sizes, no fragments, 3-byte inode headers with the owner folded into the type. It starts with the same magic, with 1 at byte 28.
Telling the versions apart
Every version starts with a four-character magic and has its major version number at byte 28 and its minor
number at byte 30 (16 bits each), in the byte order the magic shows. hsqs is little-endian and
sqsh big-endian. Some vendors’ builds of version 3 that compress with LZMA change the magic to
shsq (little-endian) or qshs (big-endian) and keep the rest. The rest of the first
bytes differ: the superblock is 96 bytes in version 4 and 119 bytes in versions 1 to 3.
| Magic | Byte 28 | Byte 30 | Format |
|---|---|---|---|
hsqs, sqsh | 4 | 0 | SquashFS 4.0 |
hsqs, sqsh, shsq, qshs | 3 | 0 or 1 | SquashFS 3.0 and 3.1 |
hsqs, sqsh | 2 | 0 or 1 | SquashFS 2.0 and 2.1 |
hsqs, sqsh | 1 | 0 | SquashFS 1.0 |
Links
Software
- Squashfs-tools –
mksquashfsbuilds an image andunsquashfslists and extracts one (Linux, macOS) - squashfuse – mounts an image in user space (Linux, macOS)
- squashfs-tools-ng – a newer toolset that packs, unpacks and converts images (Linux, Windows)
Developers
- backhand – library and tools that read and write images (Rust)
- PySquashfsImage – library that reads images (Python)
Reference
- SquashFS binary format – Dr. David Alan Gilbert’s description of the on-disk format
- SquashFS in the Linux kernel documentation – the filesystem, its compressors and options