Pegasus InfoCorp: Web site design and web software development company

3. The mksquashfs tool, exposed

3.1. Using mksquashfs

mksquashfs is the tool for creating new squashed file systems, and for appending new data to existing squashed file systems. The general command-line format for mksquashfs is:


	bash# mksquashfs source1 source2 ... destination [options]

  • source1, source2, etc.: files and directories to be added to the resulting filke system, given with relative and/or absolute paths
  • destination: a regular file (filesystem image file), or a block device (such as /dev/fd0or /dev/hda3) where you want to have your squashed file system

Notes for default mksquashfs behavior:

  • When the new files are added to the new file system or appended to an existing one, mksquashfswill automatically rename files with duplicate names: if two or more files named textwill appear in the same resulting directory, the second file will be renamed to text_1, third one to text_2and so on.
  • Duplicate files will be removed, so there will be only one physical instance (with SquashFS 2.x, you can disable the detection/rtemoval of the duplicates with the -no-duplicatesoption).
  • If destinationhas a pre-existing SquashFS file system on it, by default, the new sourceitems will be appended to the existing root directory. Examine the options table below to force mksquashfsto overwrite the whole destination and/or change the way new source items are added. Please note that it is not possible to append to a file system created with mksquashfs1.x using mksquashfs2.x. You will need to mount the SquashFS-1.x file system and copy the files to some location, and then join them with other needed files to create a SquashFS-2.x file system.
  • If a single source file or directory is given, it becomes the root in a newly created file system. If two or more source files and/or directories are given, they will all become sub-items in the root of the new file system.
  • The resulting filesystem will be padded to a multiple of 4 Kb: this is required for filesystems to be used on block devices. If you are very sure you don't ned this, use the -nopadoption to disable this operation.

See the next section for more details about all possible options.

3.2. Command-line options

All possible options for mksquashfs are shown in the table below.

Table 1. Command-line options of the mksquashfs tool

OptionDescription
-2.0force mksquashfs version 2.1 to create a version 2.0 filesystem
-all-root or -root-ownedmake all files in the target file system owned by root (UID=0, GID=0)
-always-use-fragmentsdivide all files greater than block size into fragments (2.x only, will result in greater compression ratios)
-b [block size]use [block size] filesystem block size (32 Kbytes default) - this can be either 512, 1024, 2048, 4096, 8192, 16384 or 32768
-be or -leforce a big or little endian file system, respectively
-check-dataenable additional file system checks
-e [file1] ( [file2] ... )specify which files and/or directories to omit from the new file system that is to be created
-ef [file]specify a file which contains the list of files/directories to exclude
-force-gid [GID]set all group IDs in target file system to [GID] (can be specified as a name or a number)
-force-uid [UID]set all user IDs in target file system to [UID] (can be specified as a name or a number)
-infoprint files, their original size and compression ratio, as they are added to the file system
-keep-as-directoryif the source is a single directory, force this directory to be a subdirectory of the root in the created file system
-noappendif the destination file/device already contains a squashed file system, overwrite it, rather than append the new data to an existing file system
-no-duplicatesdo not detect/remove duplicate file names
-noD or -noDataCompressiondo not compress the data
-noF or -noFragmentCompressiondo not compress the fragments (2.x only)
-no-fragmentsdo not generate fragment blocks (2.x only, this will produce almost the same filesystem as 1.x did)
-noI or -noInodeCompressiondo not compress the inode table
-nopaddo not pad the resulting file system to a multiple of 4 KBytes
-root-becomes [name]can be used while appending to a pre-existing squashed file system: it will make a new root, and [name] directory will contain all pre-existing files/directories
-versionprint the version, copyright and license message

In most cases, you should leave all compression/block options by default, as they allow mksquashfs to achieve the best possible compression ratios.