SquashFS is a compressed, read-only filesystem for Linux that stores an entire directory tree, including permissions, ownership, symbolic links and extended attributes, inside a single image file or block device. The kernel decompresses data on demand when files are read, so a large system can live in a small image without ever being unpacked to disk.
In the Linux filesystem landscape, SquashFS fills a niche that writable filesystems such as ext4, XFS and Btrfs do not: immutable, space-efficient distribution of complete trees. It underpins live installation media, embedded router firmware, Snap packages, AppImage bundles and many container and initramfs designs, usually combined with OverlayFS or tmpfs when a writable layer is needed.
How SquashFS stores and compresses data
SquashFS builds its image once, with the user-space tool mksquashfs, and the kernel only ever reads it. Because the layout never changes after creation, the format can pack metadata tightly and compress file data, inodes and directory tables separately, which a writable filesystem cannot do without heavy fragmentation.
File contents are split into data blocks of 4 KiB to 1 MiB, with 128 KiB as the default. Each block is compressed independently, so the kernel can decompress only the block that holds the requested byte range. Small files and file tails are gathered into shared fragment blocks, which avoids wasting a whole block on a 300-byte configuration file. Identical files are detected during creation and stored once through duplicate detection.
The image consists of a small number of regions in a fixed order. The following table lists them and what each one contributes.
| Region | Content | Purpose |
|---|---|---|
| Superblock | Magic number, block size, compressor, counts | Identifies the image and its parameters |
| Compression options | Compressor-specific settings | Tells the kernel how to decompress |
| Data blocks and fragments | Compressed file contents | Holds the actual file data |
| Inode table | Compressed inode records | Stores mode, owner, size and timestamps |
| Directory table | Compressed directory entries | Maps names to inodes |
| Fragment, export and ID tables | Lookup indexes | Locate fragments, support NFS export, map UIDs and GIDs |
| Extended attribute table | Compressed xattrs | Keeps SELinux labels and file capabilities |
Reads go through the normal page cache. Since kernel 5.x, SquashFS can also decompress directly into page cache pages and use multiple decompressor threads per CPU, which reduces the latency penalty that early versions showed on random access.
Compression algorithms and their trade-offs
The compressor is chosen when the image is built and recorded in the superblock; the kernel must have the matching decompressor enabled. The choice is a trade-off between image size, build time and read speed, and the right answer depends on whether storage or CPU is the scarcer resource.
| Compressor | Ratio | Decompression speed | Typical use |
|---|---|---|---|
| gzip | Good | Moderate | Default, maximum compatibility |
| xz | Best | Slow | Live media and firmware where size matters most |
| zstd | Very good | Fast | Modern distributions and Snap packages |
| lz4 | Modest | Very fast | Read-heavy workloads on slow CPUs |
| lzo | Modest | Fast | Older embedded systems |
| lzma | Best | Slow | Legacy images, superseded by xz |
zstd at levels 15 to 19 has become a common default because it approaches xz ratios while decompressing several times faster. xz with the BCJ filter for x86 or ARM shrinks executable code further, which is why firmware builders still favor it. Larger block sizes improve ratio but force more data to be decompressed for each small random read.
SquashFS compared with related Linux filesystems
SquashFS is best understood against the filesystems it is usually combined with or mistaken for. It is not a general-purpose disk filesystem, and it is not a replacement for archive formats when files must be extracted and modified.
| Technology | Writable | Compression | Main role |
|---|---|---|---|
| SquashFS | No | Always, whole image | Immutable compressed trees |
| EROFS | No | Optional, fixed-size output | Read-only system partitions with low latency |
| OverlayFS | Upper layer only | None of its own | Adds a writable layer over a read-only lower layer |
| tmpfs | Yes | None | RAM-backed scratch space |
| ext4 | Yes | None | General-purpose disk storage |
| Btrfs | Yes | Optional, per extent | Writable storage with transparent compression |
| tar.xz archive | No | Whole stream | Transfer; must be extracted before use |
The key difference from a tar archive is random access: a SquashFS image is mounted and individual files are read in place, whereas a compressed tarball must be read sequentially. Compared with EROFS, SquashFS usually achieves better compression ratios, while EROFS was designed for lower read latency on phones and is increasingly preferred for Android system partitions.
Creating and mounting SquashFS images
The workflow has two steps: build the image from a directory, then mount it. mksquashfs rootfs/ root.sqfs -comp zstd -b 1M creates an image with zstd and 1 MiB blocks, and mount -t squashfs -o loop root.sqfs /mnt attaches it through a loop device. The companion tool unsquashfs lists or extracts contents without mounting.
- Use `-all-root` or
-force-uidwhen building images from an unprivileged build tree so ownership is correct. - Use `-xattrs` (default in recent versions) to keep SELinux labels and file capabilities.
- Use
-eor an exclude file to keep caches and build artifacts out of the image. - Use `squashfuse` to mount images without root privileges through FUSE, as AppImage does.
- Add an fstab entry with the
loopoption when an image must mount at boot.
The choice of options depends on the workload. The decision table below summarizes common situations.
| Situation | Recommended settings | Reason |
|---|---|---|
| Live ISO for download | xz or zstd -Xcompression-level 19, 1 MiB blocks | Smallest download size |
| Router firmware on small flash | xz with BCJ filter, 256 KiB blocks | Fits limited flash, code compresses well |
| Application bundle launched often | zstd or lz4, 128 KiB blocks | Fast startup and random reads |
| Container base layers | zstd, default block size | Balance of size and access speed |
Limitations and common mistakes
The defining limitation is that SquashFS images cannot be modified in place. Any change, even a single byte, requires rebuilding the image or adding a writable layer. Designs that need updates therefore use OverlayFS on top of SquashFS, A/B image slots, or delta updates that replace the whole image atomically.
- Random-read performance on slow CPUs can suffer with xz and large blocks, causing slow application startup.
- Building on a host with the wrong UID mapping produces images where files belong to the build user instead of root.
- Forgetting
-xattrsstrips file capabilities, so tools such as ping may fail inside the image. - Mounting an image whose compressor is not enabled in the kernel fails with an unhelpful error.
- Treating SquashFS as tamper-proof is wrong: integrity requires dm-verity or a signed image, not compression alone.
The short version
SquashFS is a way to shrink a whole folder of files into one compact package that a Linux computer can open and use directly, without unpacking it first. Think of a vacuum-sealed bag of clothes that you could still reach into and pull out a single shirt.
The catch is that the package is sealed for reading only. To change anything, you build a new package or place a writable layer on top. That makes it ideal for things that should stay the same, such as an installer on a USB stick or the software inside a home router.
Where it makes a difference
A team that maintains firmware for a line of home routers has 16 MB of flash storage per device, but the root filesystem with its web interface, network daemons and libraries takes about 38 MB uncompressed. They build the root tree with mksquashfs using xz with the ARM BCJ filter and 256 KiB blocks, which brings the image down to roughly 11 MB.
At boot, the kernel mounts the SquashFS image as the read-only root, and a small writable JFFS2 or UBIFS partition is layered on top with OverlayFS to hold user settings. Firmware updates replace the whole image, and a factory reset simply wipes the overlay. The outcome is a device that fits its flash budget, recovers cleanly from configuration mistakes and cannot have its core system files accidentally altered.