1 SQUASHFS 4.4 - A squashed read-only filesystem for Linux
3 Copyright 2002-2019 Phillip Lougher <phillip@squashfs.org.uk>
5 Released under the GPL licence (version 2 or later).
7 Welcome to Squashfs version 4.4. Please read the README-4.3 and CHANGES files
8 for details of changes.
10 Squashfs is a highly compressed read-only filesystem for Linux.
11 It uses either gzip/xz/lzo/lz4/zstd compression to compress both files, inodes
12 and directories. Inodes in the system are very small and all blocks are
13 packed to minimise data overhead. Block sizes greater than 4K are supported
14 up to a maximum of 1Mbytes (default block size 128K).
16 Squashfs is intended for general read-only filesystem use, for archival
17 use (i.e. in cases where a .tar.gz file may be used), and in constrained
18 block device/memory systems (e.g. embedded systems) where low overhead is
24 1. Data, inodes and directories are compressed.
26 2. Squashfs stores full uid/gids (32 bits), and file creation time.
28 3. In theory files up to 2^64 bytes are supported. In theory filesystems can
31 4. Inode and directory data are highly compacted, and packed on byte
32 boundaries. Each compressed inode is on average 8 bytes in length
33 (the exact length varies on file type, i.e. regular file, directory,
34 symbolic link, and block/char device inodes have different sizes).
36 5. Squashfs can use block sizes up to 1Mbyte (the default size is 128K).
37 Using 128K blocks achieves greater compression ratios than the normal
40 6. File duplicates are detected and removed.
42 7. Filesystems can be compressed with gzip, xz (lzma2), lzo, lz4
43 or zstd compression algorithms.
46 1.1 Introducing reproducible builds
47 -----------------------------------
49 Ever since Mksquashfs was parallelised back in 2006, there
50 has been a certain randomness in how fragments and multi-block
51 files are ordered in the output filesystem even if the input
54 This is because the multiple parallel threads can be scheduled
55 differently between Mksquashfs runs. For example, the thread
56 given fragment 10 to compress may finish before the thread
57 given fragment 9 to compress on one run (writing fragment 10
58 to the output filesystem before fragment 9), but, on the next
59 run it could be vice-versa. There are many different scheduling
60 scenarios here, all of which can have a knock on effect causing
61 different scheduling and ordering later in the filesystem too.
63 Mkquashfs doesn't care about the ordering of fragments and
64 multi-block files within the filesystem, as this does not
65 affect the correctness of the filesystem.
67 In fact not caring about the ordering, as it doesn't matter, allows
68 Mksquashfs to run as fast as possible, maximising CPU and I/O
71 But, in the last couple of years, Squashfs has become used in
72 scenarios (cloud etc) where this randomness is causing problems.
73 Specifically this appears to be where downloaders, installers etc.
74 try to work out the differences between Squashfs filesystem
75 updates to minimise the amount of data that needs to transferred
78 Additionally, in the last couple of years has arisen the notion
79 of reproducible builds, that is the same source and build
80 environment etc should be able to (re-)generate identical
81 output. This is usually for verification and security, allowing
82 binaries/distributions to be checked for malicious activity.
83 See https://reproducible-builds.org/ for more information.
85 Mksquashfs from release 4.4 now generates reproducible images
86 by default. Images generated by Mksquashfs will be ordered
87 identically to previous runs if the same input has been supplied,
88 and the same options used.
90 1.1.1 Dealing with timestamps
92 Timestamps embedded in the filesystem will stiil cause differences.
93 Each new run of Mksquashfs will produce a different mkfs (make filesystem)
94 timestamp in the super-block. Moreover if any file timestamps have changed
95 (even if the content hasn't), this will produce a difference.
97 To prevent timestamps from producing differences, the following
98 new Mksquashfs options have been added.
100 1.1.2 -mkfs-time <time>
102 This option takes a positive time value (which is the number
103 of seconds since the epoch of 1970-01-01 00:00:00 UTC), and sets
104 the file system timestamp to that.
106 Squashfs uses an unsigned 32-bit integer to store time, and the
107 time given should be in that range.
109 Obviously you can use the date command to convert dates into
112 % mksquashfs source source.sqsh -mkfs-time $(date +%s -d "Jan 1 2019 19:00")
114 1.1.3 -all-time <time>
116 This option takes a positive time value (which is the number
117 of seconds since the epoch of 1970-01-01 00:00:00 UTC), and sets
118 the timestamp on all files to that (but not the mkfs time).
120 1.1.4 environment variable SOURCE_DATE_EPOCH
122 As an alternative to the above command line options, you can
123 set the environment variable SOURCE_DATE_EPOCH to a time value.
125 This value will be used to set the mkfs time. Also any
126 file timestamps which are after SOURCE_DATE_EPOCH will be
127 clamped to SOURCE_DATE_EPOCH.
129 See https://reproducible-builds.org/docs/source-date-epoch/
130 for more information.
132 Note: both SOURCE_DATE_EPOCH and the command line options cannot
133 be used at the same time. They are different ways to do the same thing,
134 and both have FORCE sematics which mean they can't be over-ridden
135 elsewhere (otherwise it would defeat the purpose).
137 1.1.5 -not-reproducible
139 This option tells Mksquashfs that the files do not have to be
140 strictly ordered. This will make Mksquashfs behave like version 4.3.
142 1.2 Extended attributes (xattrs)
143 --------------------------------
145 Squashfs filesystems now have extended attribute support. The
146 extended attribute implementation has the following features:
148 1. Layout can store up to 2^48 bytes of compressed xattr data.
149 2. Number of xattrs per inode unlimited.
150 3. Total size of xattr data per inode 2^48 bytes of compressed data.
151 4. Up to 4 Gbytes of data per xattr value.
152 5. Inline and out-of-line xattr values supported for higher performance
153 in xattr scanning (listxattr & getxattr), and to allow xattr value
155 6. Both whole inode xattr duplicate detection and individual xattr value
156 duplicate detection supported. These can obviously nest, file C's
157 xattrs can be a complete duplicate of file B, and file B's xattrs
158 can be a partial duplicate of file A.
159 7. Xattr name prefix types stored, allowing the redundant "user.", "trusted."
160 etc. characters to be eliminated and more concisely stored.
161 8. Support for files, directories, symbolic links, device nodes, fifos
164 Extended attribute support is in 2.6.35 and later kernels. Filesystems
165 with extended attributes can be mounted on 2.6.29 and later kernels, the
166 extended attributes will be ignored with a warning.
171 Squashfs filesystems should be mounted with 'mount' with the filesystem type
172 'squashfs'. If the filesystem is on a block device, the filesystem can be
173 mounted directly, e.g.
175 %mount -t squashfs /dev/sda1 /mnt
177 Will mount the squashfs filesystem on "/dev/sda1" under the directory "/mnt".
179 If the squashfs filesystem has been written to a file, the loopback device
180 can be used to mount it (loopback support must be in the kernel), e.g.
182 %mount -t squashfs image /mnt -o loop
184 Will mount the squashfs filesystem in the file "image" under
185 the directory "/mnt".
190 3.1 Mksquashfs options and overview
191 -----------------------------------
193 As squashfs is a read-only filesystem, the mksquashfs program must be used to
194 create populated squashfs filesystems.
196 SYNTAX:mksquashfs source1 source2 ... dest [options] [-e list of exclude
199 Filesystem build options:
200 -comp <comp> select <comp> compression
201 Compressors available:
207 -b <block_size> set data block to <block_size>. Default 128 Kbytes
208 Optionally a suffix of K or M can be given to specify
209 Kbytes or Mbytes respectively
210 -reproducible build images that are reproducible (default)
211 -not-reproducible build images that are not reproducible
212 -mkfs-time <time> set mkfs time to <time> which is an unsigned int
213 -fstime <time> synonym for mkfs-time
214 -all-time <time> set all inode times to <time> which is an unsigned int
215 -no-exports don't make the filesystem exportable via NFS
216 -no-sparse don't detect sparse files
217 -no-xattrs don't store extended attributes
218 -xattrs store extended attributes (default)
219 -noI do not compress inode table
220 -noId do not compress the uid/gid table (implied by -noI)
221 -noD do not compress data blocks
222 -noF do not compress fragment blocks
223 -noX do not compress extended attributes
224 -no-fragments do not use fragments
225 -always-use-fragments use fragment blocks for files larger than block size
226 -no-duplicates do not perform duplicate checking
227 -all-root make all files owned by root
228 -root-mode <mode> set root directory permissions to octal <mode>
229 -force-uid <uid> set all file uids to <uid>
230 -force-gid <gid> set all file gids to <gid>
231 -nopad do not pad filesystem to a multiple of 4K
232 -keep-as-directory if one source directory is specified, create a root
233 directory containing that directory, rather than the
234 contents of the directory
236 Filesystem filter options:
237 -p <pseudo-definition> Add pseudo file definition
238 -pf <pseudo-file> Add list of pseudo file definitions
239 Pseudo definitions should be of the format
240 filename d mode uid gid
241 filename m mode uid gid
242 filename b mode uid gid major minor
243 filename c mode uid gid major minor
244 filename f mode uid gid command
245 filename s mode uid gid symlink
246 -sort <sort_file> sort files according to priorities in <sort_file>. One
247 file or dir with priority per line. Priority -32768 to
248 32767, default priority 0
249 -ef <exclude_file> list of exclude dirs/files. One per line
250 -wildcards Allow extended shell wildcards (globbing) to be used in
252 -regex Allow POSIX regular expressions to be used in exclude
255 Filesystem append options:
256 -noappend do not append to existing filesystem
257 -root-becomes <name> when appending source files/directories, make the
258 original root become a subdirectory in the new root
259 called <name>, rather than adding the new source items
262 Mksquashfs runtime options:
263 -version print version, licence and copyright message
264 -exit-on-error treat normally ignored errors as fatal
265 -recover <name> recover filesystem data using recovery file <name>
266 -no-recovery don't generate a recovery file
267 -quiet no verbose output
268 -info print files written to filesystem
269 -no-progress don't display the progress bar
270 -progress display progress bar when using the -info option
271 -processors <number> Use <number> processors. By default will use number of
273 -mem <size> Use <size> physical memory. Currently set to 4096M
274 Optionally a suffix of K, M or G can be given to specify
275 Kbytes, Mbytes or Gbytes respectively
277 Miscellaneous options:
278 -root-owned alternative name for -all-root
279 -offset <offset> Skip <offset> bytes at the beginning of <dest>.
280 Optionally a suffix of K, M or G can be given to specify
281 Kbytes, Mbytes or Gbytes respectively.
283 -o <offset> synonym for -offset
284 -noInodeCompression alternative name for -noI
285 -noIdTableCompression alternative name for -noId
286 -noDataCompression alternative name for -noD
287 -noFragmentCompression alternative name for -noF
288 -noXattrCompression alternative name for -noX
290 -Xhelp print compressor options for selected compressor
292 Compressors available and compressor specific options:
294 -Xcompression-level <compression-level>
295 <compression-level> should be 1 .. 9 (default 9)
296 -Xwindow-size <window-size>
297 <window-size> should be 8 .. 15 (default 15)
298 -Xstrategy strategy1,strategy2,...,strategyN
299 Compress using strategy1,strategy2,...,strategyN in turn
300 and choose the best compression.
301 Available strategies: default, filtered, huffman_only,
302 run_length_encoded and fixed
304 -Xalgorithm <algorithm>
305 Where <algorithm> is one of:
311 -Xcompression-level <compression-level>
312 <compression-level> should be 1 .. 9 (default 8)
313 Only applies to lzo1x_999 algorithm
316 Compress using LZ4 High Compression
318 -Xbcj filter1,filter2,...,filterN
319 Compress using filter1,filter2,...,filterN in turn
320 (in addition to no filter), and choose the best compression.
321 Available filters: x86, arm, armthumb, powerpc, sparc, ia64
322 -Xdict-size <dict-size>
323 Use <dict-size> as the XZ dictionary size. The dictionary size
324 can be specified as a percentage of the block size, or as an
325 absolute value. The dictionary size must be less than or equal
326 to the block size and 8192 bytes or larger. It must also be
327 storable in the xz header as either 2^n or as 2^n+2^(n+1).
328 Example dict-sizes are 75%, 50%, 37.5%, 25%, or 32K, 16K, 8K
331 -Xcompression-level <compression-level>
332 <compression-level> should be 1 .. 22 (default 15)
334 Source1 source2 ... are the source directories/files containing the
335 files/directories that will form the squashfs filesystem. If a single
336 directory is specified (i.e. mksquashfs source output_fs) the squashfs
337 filesystem will consist of that directory, with the top-level root
338 directory corresponding to the source directory.
340 If multiple source directories or files are specified, mksquashfs will merge
341 the specified sources into a single filesystem, with the root directory
342 containing each of the source files/directories. The name of each directory
343 entry will be the basename of the source path. If more than one source
344 entry maps to the same name, the conflicts are named xxx_1, xxx_2, etc. where
345 xxx is the original name.
347 To make this clear, take two example directories. Source directory
348 "/home/phillip/test" contains "file1", "file2" and "dir1".
349 Source directory "goodies" contains "goodies1", "goodies2" and "goodies3".
353 %mksquashfs /home/phillip/test output_fs
355 This will generate a squashfs filesystem with root entries
356 "file1", "file2" and "dir1".
360 %mksquashfs /home/phillip/test goodies output_fs
362 This will create a squashfs filesystem with the root containing
363 entries "test" and "goodies" corresponding to the source
364 directories "/home/phillip/test" and "goodies".
368 %mksquashfs /home/phillip/test goodies test output_fs
370 This is the same as the previous example, except a third
371 source directory "test" has been specified. This conflicts
372 with the first directory named "test" and will be renamed "test_1".
374 Multiple sources allow filesystems to be generated without needing to
375 copy all source files into a common directory. This simplifies creating
378 The -keep-as-directory option can be used when only one source directory
379 is specified, and you wish the root to contain that directory, rather than
380 the contents of the directory. For example:
384 %mksquashfs /home/phillip/test output_fs -keep-as-directory
386 This is the same as example 1, except for -keep-as-directory.
387 This will generate a root directory containing directory "test",
388 rather than the "test" directory contents "file1", "file2" and "dir1".
390 The Dest argument is the destination where the squashfs filesystem will be
391 written. This can either be a conventional file or a block device. If the file
392 doesn't exist it will be created, if it does exist and a squashfs
393 filesystem exists on it, mksquashfs will append. The -noappend option will
394 write a new filesystem irrespective of whether an existing filesystem is
397 3.2 Changing compression algorithm and compression specific options
398 -------------------------------------------------------------------
400 By default Mksquashfs will compress using the gzip compression
401 algorithm. This algorithm offers a good trade-off between compression
402 ratio, and memory and time taken to decompress.
404 Squashfs also supports LZ4, LZO and XZ (LZMA2) compression. LZO offers worse
405 compression ratio than gzip, but is faster to decompress. XZ offers better
406 compression ratio than gzip, but at the expense of greater memory and time
407 to decompress (and significantly more time to compress). LZ4 is similar
408 to LZO, but, support for it is not yet in the mainline kernel, and so
409 its usefulness is currently limited to using Squashfs with Mksquashfs/Unsquashfs
410 as an archival system like tar.
412 If you're not building the squashfs-tools and kernel from source, then
413 the tools and kernel may or may not have been built with support for LZ4, LZO or
414 XZ compression. The compression algorithms supported by the build of
415 Mksquashfs can be found by typing mksquashfs without any arguments. The
416 compressors available are displayed at the end of the help message, e.g.
418 Compressors available and compressor specific options:
420 -Xcompression-level <compression-level>
421 <compression-level> should be 1 .. 9 (default 9)
422 -Xwindow-size <window-size>
423 <window-size> should be 8 .. 15 (default 15)
424 -Xstrategy strategy1,strategy2,...,strategyN
425 Compress using strategy1,strategy2,...,strategyN in turn
426 and choose the best compression.
427 Available strategies: default, filtered, huffman_only,
428 run_length_encoded and fixed
430 -Xalgorithm <algorithm>
431 Where <algorithm> is one of:
437 -Xcompression-level <compression-level>
438 <compression-level> should be 1 .. 9 (default 8)
439 Only applies to lzo1x_999 algorithm
442 Compress using LZ4 High Compression
444 -Xbcj filter1,filter2,...,filterN
445 Compress using filter1,filter2,...,filterN in turn
446 (in addition to no filter), and choose the best compression.
447 Available filters: x86, arm, armthumb, powerpc, sparc, ia64
448 -Xdict-size <dict-size>
449 Use <dict-size> as the XZ dictionary size. The dictionary size
450 can be specified as a percentage of the block size, or as an
451 absolute value. The dictionary size must be less than or equal
452 to the block size and 8192 bytes or larger. It must also be
453 storable in the xz header as either 2^n or as 2^n+2^(n+1).
454 Example dict-sizes are 75%, 50%, 37.5%, 25%, or 32K, 16K, 8K
457 -Xcompression-level <compression-level>
458 <compression-level> should be 1 .. 22 (default 15)
460 If the compressor offers compression specific options (all the compressors now
461 have compression specific options except the deprecated lzma1 compressor)
462 then these options are also displayed (.i.e. in the above XZ is shown with two
463 compression specific options). The compression specific options are, obviously,
464 specific to the compressor in question, and the compressor documentation and
465 web sites should be consulted to understand their behaviour. In general
466 the Mksquashfs compression defaults for each compressor are optimised to
467 give the best performance for each compressor, where what constitutes
468 best depends on the compressor. For gzip/xz best means highest compression,
469 for LZO/LZ4 best means a tradeoff between compression and (de)-compression
470 overhead (LZO/LZ4 by definition are intended for weaker processors).
472 3.3 Changing global compression defaults used in mksquashfs
473 -----------------------------------------------------------
475 There are a large number of options that can be used to control the
476 compression in mksquashfs. By and large the defaults are the most
477 optimum settings and should only be changed in exceptional circumstances!
478 Note, this does not apply to the block size, increasing the block size
479 from the default of 128Kbytes will increase compression (especially
480 for the xz compressor) and should increase I/O performance too. However,
481 a block size of greater than 128Kbytes may increase latency in certain
482 cases (where the filesystem contains lots of fragments, and no locality
483 of reference is observed). For this reason the block size default is
484 configured to the less optimal 128Kbytes. Users should experiment
485 with 256Kbyte sizes or above.
487 The -noI, -noD and -noF options (also -noInodeCompression, -noDataCompression
488 and -noFragmentCompression) can be used to force mksquashfs to not compress
489 inodes/directories, data and fragments respectively. Giving all options
490 generates an uncompressed filesystem.
492 The -no-fragments tells mksquashfs to not generate fragment blocks, and rather
493 generate a filesystem similar to a Squashfs 1.x filesystem. It will of course
494 still be a Squashfs 4.0 filesystem but without fragments, and so it won't be
495 mountable on a Squashfs 1.x system.
497 The -always-use-fragments option tells mksquashfs to always generate
498 fragments for files irrespective of the file length. By default only small
499 files less than the block size are packed into fragment blocks. The ends of
500 files which do not fit fully into a block, are NOT by default packed into
501 fragments. To illustrate this, a 100K file has an initial 64K block and a 36K
502 remainder. This 36K remainder is not packed into a fragment by default. This
503 is because to do so leads to a 10 - 20% drop in sequential I/O performance, as a
504 disk head seek is needed to seek to the initial file data and another disk seek
505 is need to seek to the fragment block. Specify this option if you want file
506 remainders to be packed into fragment blocks. Doing so may increase the
507 compression obtained BUT at the expense of I/O speed.
509 The -no-duplicates option tells mksquashfs to not check the files being
510 added to the filesystem for duplicates. This can result in quicker filesystem
511 generation and appending although obviously compression will suffer badly if
512 there is a lot of duplicate files.
514 The -b option allows the block size to be selected, both "K" and "M" postfixes
515 are supported, this can be either 4K, 8K, 16K, 32K, 64K, 128K, 256K, 512K or
518 3.4 Specifying the UIDs/GIDs used in the filesystem
519 ---------------------------------------------------
521 By default files in the generated filesystem inherit the UID and GID ownership
522 of the original file. However, mksquashfs provides a number of options which
523 can be used to override the ownership.
525 The options -all-root and -root-owned (both do exactly the same thing) force all
526 file uids/gids in the generated Squashfs filesystem to be root. This allows
527 root owned filesystems to be built without root access on the host machine.
529 The "-force-uid uid" option forces all files in the generated Squashfs
530 filesystem to be owned by the specified uid. The uid can be specified either by
531 name (i.e. "root") or by number.
533 The "-force-gid gid" option forces all files in the generated Squashfs
534 filesystem to be group owned by the specified gid. The gid can be specified
535 either by name (i.e. "root") or by number.
537 3.5 Excluding files from the filesystem
538 ---------------------------------------
540 The -e and -ef options allow files/directories to be specified which are
541 excluded from the output filesystem. The -e option takes the exclude
542 files/directories from the command line, the -ef option takes the
543 exlude files/directories from the specified exclude file, one file/directory
546 Two styles of exclude file matching are supported: basic exclude matching, and
547 extended wildcard matching. Basic exclude matching is a legacy feature
548 retained for backwards compatibility with earlier versions of Mksquashfs.
549 Extended wildcard matching should be used in preference.
551 3.5.1 Basic exclude matching
552 ----------------------------
554 Each exclude file is treated as an exact match of a file/directory in
555 the source directories. If an exclude file/directory is absolute (i.e.
556 prefixed with /, ../, or ./) the entry is treated as absolute, however, if an
557 exclude file/directory is relative, it is treated as being relative to each of
558 the sources in turn, i.e.
560 %mksquashfs /tmp/source1 source2 output_fs -e ex1 /tmp/source1/ex2 out/ex3
562 Will generate exclude files /tmp/source1/ex2, /tmp/source1/ex1, source2/ex1,
563 /tmp/source1/out/ex3 and source2/out/ex3.
565 3.5.2 Extended exclude file handling
566 ------------------------------------
568 Extended exclude file matching treats each exclude file as a wildcard or
569 regex expression. To enable wildcard matching specify the -wildcards
570 option, and to enable regex matching specify the -regex option. In most
571 cases the -wildcards option should be used rather than -regex because wildcard
572 matching behaviour is significantly easier to understand!
574 In addition to wildcards/regex expressions, exclude files can be "anchored" or
575 "non-anchored". An anchored exclude is one which matches from the root of the
576 directory and nowhere else, a non-anchored exclude matches anywhere. For
577 example given the directory hierarchy "a/b/c/a/b", the anchored exclude
578 "a/b" will match "a/b" at the root of the directory hierarchy, but
579 it will not match the "/a/b" sub-directory within directory "c", whereas a
580 non-anchored exclude would.
582 A couple of examples should make this clearer.
586 1. mksquashfs example image.sqsh -wildcards -e 'test/*.gz'
588 Exclude all files matching "*.gz" in the top level directory "test".
590 2. mksquashfs example image.sqsh -wildcards -e '*/[Tt]est/example*'
592 Exclude all files beginning with "example" inside directories called
593 "Test" or "test", that occur inside any top level directory.
595 Using extended wildcards, negative matching is also possible.
597 3. mksquashfs example image.sqsh -wildcards -e 'test/!(*data*).gz'
599 Exclude all files matching "*.gz" in top level directory "test",
600 except those with "data" in the name.
602 Non-anchored excludes
604 By default excludes match from the top level directory, but it is
605 often useful to exclude a file matching anywhere in the source directories.
606 For this non-anchored excludes can be used, specified by pre-fixing the
611 1. mksquashfs example image.sqsh -wildcards -e '... *.gz'
613 Exclude files matching "*.gz" anywhere in the source directories.
614 For example this will match "example.gz", "test/example.gz", and
615 "test/test/example.gz".
617 2. mksquashfs example image.sqsh -wildcards -e '... [Tt]est/*.gz'
619 Exclude files matching "*.gz" inside directories called "Test" or
620 "test" that occur anywhere in the source directories.
622 Again, using extended wildcards, negative matching is also possible.
624 3. mksquashfs example image.sqsh -wildcards -e '... !(*data*).gz'
626 Exclude all files matching "*.gz" anywhere in the source directories,
627 except those with "data" in the name.
629 3.5.3 Exclude files summary
630 ---------------------------
632 The -e and -ef exclude options are usefully used in archiving the entire
633 filesystem, where it is wished to avoid archiving /proc, and the filesystem
634 being generated, i.e.
636 %mksquashfs / /tmp/root.sqsh -e proc /tmp/root.sqsh
638 Multiple -ef options can be specified on the command line, and the -ef
639 option can be used in conjuction with the -e option.
641 3.6 Appending to squashfs filesystems
642 -------------------------------------
644 Running squashfs with the destination directory containing an existing
645 filesystem will add the source items to the existing filesystem. By default,
646 the source items are added to the existing root directory.
648 To make this clear... An existing filesystem "image" contains root entries
649 "old1", and "old2". Source directory "/home/phillip/test" contains "file1",
654 %mksquashfs /home/phillip/test image
656 Will create a new "image" with root entries "old1", "old2", "file1", "file2" and
661 %mksquashfs /home/phillip/test image -keep-as-directory
663 Will create a new "image" with root entries "old1", "old2", and "test".
664 As shown in the previous section, for single source directories
665 '-keep-as-directory' adds the source directory rather than the
666 contents of the directory.
670 %mksquashfs /home/phillip/test image -keep-as-directory -root-becomes
673 Will create a new "image" with root entries "original-root", and "test". The
674 '-root-becomes' option specifies that the original root becomes a subdirectory
675 in the new root, with the specified name.
677 The append option with file duplicate detection, means squashfs can be
678 used as a simple versioning archiving filesystem. A squashfs filesystem can
679 be created with for example the linux-2.4.19 source. Appending the linux-2.4.20
680 source will create a filesystem with the two source trees, but only the
681 changed files will take extra room, the unchanged files will be detected as
684 3.7 Appending recovery file feature
685 -----------------------------------
687 Recovery files are created when appending to existing Squashfs
688 filesystems. This allows the original filesystem to be recovered
689 if Mksquashfs aborts unexpectedly (i.e. power failure).
691 The recovery files are called squashfs_recovery_xxx_yyy, where
692 "xxx" is the name of the filesystem being appended to, and "yyy" is a
693 number to guarantee filename uniqueness (the PID of the parent Mksquashfs
696 Normally if Mksquashfs exits correctly the recovery file is deleted to
697 avoid cluttering the filesystem. If Mksquashfs aborts, the "-recover"
698 option can be used to recover the filesystem, giving the previously
699 created recovery file as a parameter, i.e.
701 mksquashfs dummy image.sqsh -recover squashfs_recovery_image.sqsh_1234
703 The writing of the recovery file can be disabled by specifying the
704 "-no-recovery" option.
706 3.8 Pseudo file support
707 -----------------------
709 Mksquashfs supports pseudo files, these allow fake files, directories, character
710 and block devices to be specified and added to the Squashfs filesystem being
711 built, rather than requiring them to be present in the source directories.
712 This, for example, allows device nodes to be added to the filesystem without
713 requiring root access.
715 Mksquashfs 4.1 added support for "dynamic pseudo files" and a modify operation.
716 Dynamic pseudo files allow files to be dynamically created when Mksquashfs
717 is run, their contents being the result of running a command or piece of
718 shell script. The modifiy operation allows the mode/uid/gid of an existing
719 file in the source filesystem to be modified.
721 Mksquashfs 4.4 adds support for Symbolic links.
723 Two Mksquashfs options are supported, -p allows one pseudo file to be specified
724 on the command line, and -pf allows a pseudo file to be specified containing a
725 list of pseduo definitions, one per line.
727 3.8.1. Creating a dynamic file
728 ------------------------------
732 Filename f mode uid gid command
734 mode is the octal mode specifier, similar to that expected by chmod.
736 uid and gid can be either specified as a decimal number, or by name.
738 command can be an executable or a piece of shell script, and it is executed
739 by running "/bin/sh -c command". The stdout becomes the contents of
744 Running a basic command
745 -----------------------
747 /somedir/dmesg f 444 root root dmesg
749 creates a file "/somedir/dmesg" containing the output from dmesg.
751 Executing shell script
752 ----------------------
754 RELEASE f 444 root root \
755 if [ ! -e /tmp/ver ]; then \
758 ver=`cat /tmp/ver`; \
760 echo $ver > /tmp/ver; \
761 echo -n `cat /tmp/release`; \
762 echo "-dev #"$ver `date` "Build host" `hostname`
764 Creates a file RELEASE containing the release name, date, build host, and
765 an incrementing version number. The incrementing version is a side-effect
766 of executing the shell script, and ensures every time Mksquashfs is run a
767 new version number is used without requiring any other shell scripting.
769 The above example also shows that commands can be split across multiple lines
770 using "\". Obviously as the script will be presented to the shell as a single
771 line, a semicolon is need to separate individual shell commands within the
774 Reading from a device (or fifo/named socket)
775 --------------------------------------------
777 input f 444 root root dd if=/dev/sda1 bs=1024 count=10
779 Copies 10K from the device /dev/sda1 into the file input. Ordinarily Mksquashfs
780 given a device, fifo, or named socket will place that special file within the
781 Squashfs filesystem, the above allows input from these special files to be
782 captured and placed in the Squashfs filesystem.
784 3.8.2. Creating a block or character device
785 -------------------------------------------
789 Filename type mode uid gid major minor
792 b - for block devices, and
793 c - for character devices
795 mode is the octal mode specifier, similar to that expected by chmod.
797 uid and gid can be either specified as a decimal number, or by name.
801 /dev/chr_dev c 666 root root 100 1
802 /dev/blk_dev b 666 0 0 200 200
804 creates a character device "/dev/chr_dev" with major:minor 100:1 and
805 a block device "/dev/blk_dev" with major:minor 200:200, both with root
806 uid/gid and a mode of rw-rw-rw.
808 3.8.3. Creating a directory
809 ---------------------------
813 Filename d mode uid gid
815 mode is the octal mode specifier, similar to that expected by chmod.
817 uid and gid can be either specified as a decimal number, or by name.
821 /pseudo_dir d 666 root root
823 creates a directory "/pseudo_dir" with root uid/gid and mode of rw-rw-rw.
825 3.8.4. Creating a symbolic link
826 -------------------------------
830 Filename s mode uid gid symlink
832 uid and gid can be either specified as a decimal number, or by name.
834 Note mode is ignored, as symlinks always have "rwxrwxrwx" permissions.
838 symlink s 0 root root example
840 creates a symlink "symlink" to file "example" with root uid/gid.
842 3.8.5. Modifying attributes of an existing file
843 -----------------------------------------------
847 Filename m mode uid gid
849 mode is the octal mode specifier, similar to that expected by chmod.
851 uid and gid can be either specified as a decimal number, or by name.
855 dmesg m 666 root root
857 Changes the attributes of the file "dmesg" in the filesystem to have
858 root uid/gid and a mode of rw-rw-rw, overriding the attributes obtained
859 from the source filesystem.
861 3.9 Miscellaneous options
862 -------------------------
864 The -info option displays the files/directories as they are compressed and
865 added to the filesystem. The original uncompressed size of each file
866 is printed, along with DUPLICATE if the file is a duplicate of a
867 file in the filesystem.
869 The -nopad option informs mksquashfs to not pad the filesystem to a 4K multiple.
870 This is performed by default to enable the output filesystem file to be mounted
871 by loopback, which requires files to be a 4K multiple. If the filesystem is
872 being written to a block device, or is to be stored in a bootimage, the extra
873 pad bytes are not needed.
878 Unsquashfs allows you to decompress and extract a Squashfs filesystem without
879 mounting it. It can extract the entire filesystem, or a specific
882 Unsquashfs can decompress all official Squashfs filesystem versions.
884 The Unsquashfs usage info is:
886 SYNTAX: unsquashfs [options] filesystem [directories or files to extract]
887 -v[ersion] print version, licence and copyright information
888 -d[est] <pathname> unsquash to <pathname>, default "squashfs-root"
889 -q[uiet] no verbose output
890 -n[o-progress] don't display the progress bar
891 -no[-xattrs] don't extract xattrs in file system
892 -x[attrs] extract xattrs in file system (default)
893 -u[ser-xattrs] only extract user xattrs in file system.
894 Enables extracting xattrs
895 -p[rocessors] <number> use <number> processors. By default will use
896 number of processors available
897 -i[nfo] print files as they are unsquashed
898 -li[nfo] print files as they are unsquashed with file
899 attributes (like ls -l output)
900 -l[s] list filesystem, but don't unsquash
901 -ll[s] list filesystem with file attributes (like
902 ls -l output), but don't unsquash
903 -lln[umeric] -lls but with numeric uids and gids
904 -lc list filesystem concisely, displaying only files
905 and empty directories. Don't unsquash
906 -llc list filesystem concisely with file attributes,
907 displaying only files and empty directories.
909 -o[ffset] <bytes> skip <bytes> at start of <dest>
910 Optionally a suffix of K, M or G can be given to specify
911 Kbytes, Mbytes or Gbytes respectively.
913 -f[orce] if file already exists then overwrite
914 -ig[nore-errors] Treat errors writing files to output as non-fatal
915 -st[rict-errors] Treat all errors as fatal
916 -s[tat] display filesystem superblock information
917 -UTC Use UTC rather than local time zone when displaying time
918 -mkfs-time display filesystem superblock time
919 -fstime synonym for -mkfs-time
920 -e[f] <extract file> list of directories or files to extract.
922 -da[ta-queue] <size> Set data queue to <size> Mbytes. Default 256
924 -fr[ag-queue] <size> Set fragment queue to <size> Mbytes. Default
926 -r[egex] treat extract names as POSIX regular expressions
927 rather than use the default shell wildcard
930 Decompressors available:
937 To extract a subset of the filesystem, the filenames or directory
938 trees that are to be extracted can be specified on the command line. The
939 files/directories should be specified using the full path to the
940 files/directories as they appear within the Squashfs filesystem. The
941 files/directories will also be extracted to those positions within the specified
942 destination directory.
944 The extract files can also be given in a file using the "-e[f]" option.
946 Similarly to Mksquashfs, wildcard matching is performed on the extract
947 files. Wildcard matching is enabled by default.
951 1. unsquashfs image.sqsh 'test/*.gz'
953 Extract all files matching "*.gz" in the top level directory "test".
955 2. unsquashfs image.sqsh '[Tt]est/example*'
957 Extract all files beginning with "example" inside top level directories
958 called "Test" or "test".
960 Using extended wildcards, negative matching is also possible.
962 3. unsquashfs image.sqsh 'test/!(*data*).gz'
964 Extract all files matching "*.gz" in top level directory "test",
965 except those with "data" in the name.
968 4.1 Unsquashfs options
969 ----------------------
971 The "-ls" option can be used to list the contents of a filesystem without
972 decompressing the filesystem data itself. The "-lls" option is similar
973 but it also displays file attributes (ls -l style output). The "-lln"
974 option is the same but displays uids and gids numerically.
976 The "-lc" option is similar to the -ls option except it only displays files
977 and empty directories. The -llc option displays file attributes.
979 The "-info" option forces Unsquashfs to print each file as it is decompressed.
980 The -"linfo" is similar but it also displays file attributes.
982 The "-dest" option specifies the directory that is used to decompress
983 the filesystem data. If this option is not given then the filesystem is
984 decompressed to the directory "squashfs-root" in the current working directory.
986 The "-force" option forces Unsquashfs to output to the destination
987 directory even if files or directories already exist. This allows you
988 to update an existing directory tree, or to Unsquashfs to a partially
989 filled directory. Without the "-force" option, Unsquashfs will
990 refuse to overwrite any existing files, or to create any directories if they
991 already exist. This is done to protect data in case of mistakes, and
992 so the "-force" option should be used with caution.
994 The "-stat" option displays filesystem superblock information. This is
995 useful to discover the filesystem version, byte ordering, whether it has a NFS
996 export table, and what options were used to compress the filesystem, etc.
998 The -mkfs-time option displays the make filesystem time contained
999 in the super-block. This is displayed as the number of seconds since
1000 the epoch of 1970-01-01 00:00:00 UTC.
1002 The -UTC option makes Unsquashfs display all times in the UTC time zone
1003 rather than using the default local time zone.
1005 4.2. Dealing with errors
1006 ------------------------
1008 Unsquashfs splits errors into two categories: fatal errors and non-fatal
1011 Fatal errors are those which cause Unsquashfs to abort instantly.
1012 These are generally due to failure to read the filesystem (corruption),
1013 and/or failure to write files to the output filesystem, due to I/O error
1014 or out of space. Generally anything which is unexpected is a fatal error.
1016 Non-fatal errors are generally where support is lacking in the
1017 output filesystem, and it can be considered to be an expected failure.
1018 This includes the inability to write extended attributes (xattrs) to
1019 a filesystem that doesn't support them, the inability to create files on
1020 filesystem that doesn't support them (i.e. symbolic links on VFAT), and the
1021 inability to execute privileged operations as a user-process.
1023 The user may well know the filesystem cannot support certain operations
1024 and would prefer Unsquashfs to ignore then without aborting.
1026 In the past Unsquashfs was much more tolerant of errors, in this
1027 release a significant number of errors that were non-fatal have been
1030 4.2.1. -ignore-errors
1032 This makes Unsquashfs behave like previous versions, and treats more
1033 errors as non-fatal.
1035 4.2.2 -strict-errors
1037 This makes Unsquashfs treat every error as fatal, and it will abort
1040 5. FILESYSTEM LAYOUT
1041 --------------------
1043 A squashfs filesystem consists of a maximum of nine parts, packed together on a
1073 Compressed data blocks are written to the filesystem as files are read from
1074 the source directory, and checked for duplicates. Once all file data has been
1075 written the completed super-block, compression options, inode, directory,
1076 fragment, export, uid/gid lookup and xattr tables are written.
1078 5.1 Compression options
1079 -----------------------
1081 Compressors can optionally support compression specific options (e.g.
1082 dictionary size). If non-default compression options have been used, then
1083 these are stored here.
1088 Metadata (inodes and directories) are compressed in 8Kbyte blocks. Each
1089 compressed block is prefixed by a two byte length, the top bit is set if the
1090 block is uncompressed. A block will be uncompressed if the -noI option is set,
1091 or if the compressed block was larger than the uncompressed block.
1093 Inodes are packed into the metadata blocks, and are not aligned to block
1094 boundaries, therefore inodes overlap compressed blocks. Inodes are identified
1095 by a 48-bit number which encodes the location of the compressed metadata block
1096 containing the inode, and the byte offset into that block where the inode is
1097 placed (<block, offset>).
1099 To maximise compression there are different inodes for each file type
1100 (regular file, directory, device, etc.), the inode contents and length
1101 varying with the type.
1103 To further maximise compression, two types of regular file inode and
1104 directory inode are defined: inodes optimised for frequently occurring
1105 regular files and directories, and extended types where extra
1106 information has to be stored.
1111 Like inodes, directories are packed into compressed metadata blocks, stored
1112 in a directory table. Directories are accessed using the start address of
1113 the metablock containing the directory and the offset into the
1114 decompressed block (<block, offset>).
1116 Directories are organised in a slightly complex way, and are not simply
1117 a list of file names. The organisation takes advantage of the
1118 fact that (in most cases) the inodes of the files will be in the same
1119 compressed metadata block, and therefore, can share the start block.
1120 Directories are therefore organised in a two level list, a directory
1121 header containing the shared start block value, and a sequence of directory
1122 entries, each of which share the shared start block. A new directory header
1123 is written once/if the inode start block changes. The directory
1124 header/directory entry list is repeated as many times as necessary.
1126 Directories are sorted, and can contain a directory index to speed up
1127 file lookup. Directory indexes store one entry per metablock, each entry
1128 storing the index/filename mapping to the first directory header
1129 in each metadata block. Directories are sorted in alphabetical order,
1130 and at lookup the index is scanned linearly looking for the first filename
1131 alphabetically larger than the filename being looked up. At this point the
1132 location of the metadata block the filename is in has been found.
1133 The general idea of the index is ensure only one metadata block needs to be
1134 decompressed to do a lookup irrespective of the length of the directory.
1135 This scheme has the advantage that it doesn't require extra memory overhead
1136 and doesn't require much extra storage on disk.
1141 Regular files consist of a sequence of contiguous compressed blocks, and/or a
1142 compressed fragment block (tail-end packed block). The compressed size
1143 of each datablock is stored in a block list contained within the
1146 To speed up access to datablocks when reading 'large' files (256 Mbytes or
1147 larger), the code implements an index cache that caches the mapping from
1148 block index to datablock location on disk.
1150 The index cache allows Squashfs to handle large files (up to 1.75 TiB) while
1151 retaining a simple and space-efficient block list on disk. The cache
1152 is split into slots, caching up to eight 224 GiB files (128 KiB blocks).
1153 Larger files use multiple slots, with 1.75 TiB files using all 8 slots.
1154 The index cache is designed to be memory efficient, and by default uses
1157 5.5 Fragment lookup table
1158 -------------------------
1160 Regular files can contain a fragment index which is mapped to a fragment
1161 location on disk and compressed size using a fragment lookup table. This
1162 fragment lookup table is itself stored compressed into metadata blocks.
1163 A second index table is used to locate these. This second index table for
1164 speed of access (and because it is small) is read at mount time and cached
1167 5.6 Uid/gid lookup table
1168 ------------------------
1170 For space efficiency regular files store uid and gid indexes, which are
1171 converted to 32-bit uids/gids using an id look up table. This table is
1172 stored compressed into metadata blocks. A second index table is used to
1173 locate these. This second index table for speed of access (and because it
1174 is small) is read at mount time and cached in memory.
1179 To enable Squashfs filesystems to be exportable (via NFS etc.) filesystems
1180 can optionally (disabled with the -no-exports Mksquashfs option) contain
1181 an inode number to inode disk location lookup table. This is required to
1182 enable Squashfs to map inode numbers passed in filehandles to the inode
1183 location on disk, which is necessary when the export code reinstantiates
1184 expired/flushed inodes.
1186 This table is stored compressed into metadata blocks. A second index table is
1187 used to locate these. This second index table for speed of access (and because
1188 it is small) is read at mount time and cached in memory.
1193 The xattr table contains extended attributes for each inode. The xattrs
1194 for each inode are stored in a list, each list entry containing a type,
1195 name and value field. The type field encodes the xattr prefix
1196 ("user.", "trusted." etc) and it also encodes how the name/value fields
1197 should be interpreted. Currently the type indicates whether the value
1198 is stored inline (in which case the value field contains the xattr value),
1199 or if it is stored out of line (in which case the value field stores a
1200 reference to where the actual value is stored). This allows large values
1201 to be stored out of line improving scanning and lookup performance and it
1202 also allows values to be de-duplicated, the value being stored once, and
1203 all other occurences holding an out of line reference to that value.
1205 The xattr lists are packed into compressed 8K metadata blocks.
1206 To reduce overhead in inodes, rather than storing the on-disk
1207 location of the xattr list inside each inode, a 32-bit xattr id
1208 is stored. This xattr id is mapped into the location of the xattr
1209 list using a second xattr id lookup table.
1214 Squashfs was written by Phillip Lougher, email phillip@squashfs.org.uk,
1215 in Chepstow, Wales, UK. If you like the program, or have any problems,
1216 then please email me, as it's nice to get feedback!