.\" generated with Ronn-NG/v0.10.1 .\" http://github.com/apjanke/ronn-ng/tree/0.10.1 .TH "MKDWARFS" "1" "April 2024" "" .SH "NAME" \fBmkdwarfs\fR \- create highly compressed read\-only file systems .SH "SYNOPSIS" \fBmkdwarfs\fR \fB\-i\fR \fIpath\fR \fB\-o\fR \fIfile\fR|\fB\-\fR [\fIoptions\fR\|\.\|\.\|\.] .br \fBmkdwarfs\fR \fB\-\-input\-list=\fR\fIfile\fR|\fB\-\fR \fB\-o\fR \fIfile\fR|\fB\-\fR [\fIoptions\fR\|\.\|\.\|\.] .br \fBmkdwarfs\fR \fB\-i\fR \fIfile\fR \fB\-o\fR \fIfile\fR|\fB\-\fR \fB\-\-recompress\fR [\fIoptions\fR\|\.\|\.\|\.] .SH "DESCRIPTION" \fBmkdwarfs\fR allows you to create highly compressed, read\-only file systems in the DwarFS format\. DwarFS is similar to file systems like SquashFS, cramfs or CromFS, but it has some distinct features\. For more detail, see dwarfs(1)\. .P In its simplest usage form, you can create a file system containing the full contents of \fB/path/dir\fR with: .IP "" 4 .nf mkdwarfs \-i /path/dir \-o image\.dwarfs .fi .IP "" 0 .P After that, you can mount it using dwarfs(1): .IP "" 4 .nf dwarfs image\.dwarfs /path/to/mountpoint .fi .IP "" 0 .SH "OPTIONS" There are two mandatory options for specifying the input and output: .TP \fB\-i\fR, \fB\-\-input=\fR\fIpath\fR|\fIfile\fR Path to the root directory containing the files from which you want to build a file system\. If the \fB\-\-recompress\fR option is given, this argument is the source filesystem\. .TP \fB\-\-input\-list=\fR\fIfile\fR|\fB\-\fR Read list of file paths to add to the file system from this file or from stdin\. The path names will be interpreted relative to the path given with \fB\-\-input\fR\. If \fB\-\-input\fR is omitted, the path names will be interpreted relative to the current directory\. If you want files to be stored in the exact same order as read from this list (because, for example, you have already sorted them by similarity or access frequency), you must also pass \fB\-\-order=none\fR\. This option implicitly enables both \fB\-\-with\-devices\fR and \fB\-\-with\-specials\fR\. .TP \fB\-o\fR, \fB\-\-output=\fR\fIfile\fR|\fB\-\fR File name of the output filesystem or \fB\-\fR to write the filesystem to stdout\. .TP \fB\-f\fR, \fB\-\-force\fR Force the output file to be overwritten if it already exists\. .P Most other options are concerned with compression tuning: .TP \fB\-l\fR, \fB\-\-compress\-level=\fR\fIvalue\fR Compression level to use for the filesystem\. \fBIf you are unsure, please stick to the default level of 7\.\fR This is intended to provide some sensible defaults and will depend on which compression libraries were available at build time\. \fBThe default level has been chosen to provide you with the best possible compression while still keeping the file system very fast to access\.\fR Levels 8 and 9 will switch to LZMA compression (when available), which will likely reduce the file system image size, but will make it about an order of magnitude slower to access, so reserve these levels for cases where you only need to access the data infrequently\. This \fB\-l\fR option is meant to be the "easy" interface to configure \fBmkdwarfs\fR, and it will actually pick defaults for seven distinct options: \fB\-\-block\-size\-bits\fR, \fB\-\-compression\fR, \fB\-\-schema\-compression\fR, \fB\-\-metadata\-compression\fR, \fB\-\-window\-size\fR, \fB\-\-window\-step\fR and \fB\-\-order\fR\. See the output of \fBmkdwarfs \-\-help\fR for a table listing the exact defaults used for each compression level\. .TP \fB\-\-categorize\fR[\fB=\fR\fIcategorizer\fR[\fB,\fR\|\.\|\.\|\.]] Enable one or more categorizers in the given order\. See \fICATEGORIZERS\fR for more details\. .TP \fB\-S\fR, \fB\-\-block\-size\-bits=\fR\fIvalue\fR The block size used for the compressed filesystem\. The actual block size is two to the power of this value\. Larger block sizes will offer better overall compression ratios, but will be slower and consume more memory when actually using the filesystem, as blocks will have to be fully or at least partially decompressed into memory\. Values between 20 and 26, i\.e\. between 1MiB and 64MiB, usually work quite well\. .TP \fB\-N\fR, \fB\-\-num\-workers=\fR\fIvalue\fR Number of worker threads used for building the filesystem\. This defaults to the number of processors available on your system\. Use this option if you want to limit the resources used by \fBmkdwarfs\fR or to optimize build speed\. This option affects only the compression phase\. During the compression phase, the worker threads are used to compress the individual filesystem blocks in the background\. Ordering, segmenting and block building are single\-threaded and run independently\. .TP \fB\-\-compress\-niceness=\fR\fIvalue\fR Set the niceness of compression worker threads\. Defaults to 5\. This ensures the ordering and segmenting threads are prioritised over compression as they provide the data to the compression workers\. On Windows, the values are mapped as follows: 0 (zero) is mapped to "normal" priority, 1 to 5 are mapped to "below normal" priority, 6 to 10 are mapped to "lowest" priority and values greater than 10 are mapped to "background" priority\. .TP \fB\-\-num\-scanner\-workers=\fR\fIvalue\fR Number of worker threads used for scanning the filesystem\. Use this option if you want to limit the resources used by \fBmkdwarfs\fR or to optimize build speed\. This option affects only the scanning phase\. By default, the same value is used as for \fB\-\-num\-workers\fR\. In the scanning phase, the worker threads are used to scan files in the background as they are discovered\. File scanning includes checksumming for de\-duplication as well as (optionally) checksumming for similarity computation, depending on the \fB\-\-order\fR option\. File discovery itself is single\-threaded and runs independently from the scanning threads\. .TP \fB\-\-num\-segmenter\-workers=\fR\fIvalue\fR Number of worker threads used for segmenting the input data\. By default, the same value is used as for \fB\-\-num\-workers\fR\. Segmenting the input data is one of the most time consuming tasks when building a file system, and cannot easily be parallelized\. However, when using the categorizer, a separate segmenter will be used for each category (and subcategory, if present)\. This option controls how many segmenters can run simultaneously\. When \fB\-\-compress\-niceness\fR is set to the default, segmenter threads will always have a higher priority than compression threads, making sure that compression doesn't slow down segmentation\. This option also controls the number of threads used for ordering the input to the segmenter\. .TP \fB\-B\fR, \fB\-\-max\-lookback\-blocks=[*category*\fR::\fB]\fR\fIvalue\fR Specify how many of the most recent blocks to scan for duplicate segments\. By default, only the current block will be scanned\. The larger this number, the more duplicate segments will likely be found, which may further improve compression\. Impact on compression speed is minimal, but this could cause resulting filesystem to be slightly less efficient to use, as single small files can now potentially span multiple filesystem blocks\. Passing \fB\-B0\fR will completely disable duplicate segment search\. .TP \fB\-W\fR, \fB\-\-window\-size=[*category*\fR::\fB]\fR\fIvalue\fR Window size of cyclic hash used for segmenting\. This is an exponent to a base of two\. Cyclic hashes are used by \fBmkdwarfs\fR for finding identical segments across multiple files\. This is done on top of duplicate file detection\. If a reasonable amount of duplicate segments is found, this means less blocks will be used in the filesystem and potentially less memory will be used when accessing the filesystem\. It doesn't necessarily mean that the filesystem will be much smaller, as this removes redundancy that cannot be exploited by the block compression any longer\. But it shouldn't make the resulting filesystem any bigger\. This option is used along with \fB\-\-window\-step\fR to determine how extensive this segment search will be\. The smaller the window sizes, the more segments will obviously be found\. However, this also means files will become more fragmented and thus the filesystem can be slower to use and metadata size will grow\. Passing \fB\-W0\fR will completely disable duplicate segment search\. .TP \fB\-w\fR, \fB\-\-window\-step=[*category*\fR::\fB]\fR\fIvalue\fR This option specifies how often cyclic hash values are stored for lookup\. It is specified relative to the window size, as a base\-2 exponent that divides the window size\. As a concrete example, if \fB\-\-window\-size=16\fR and \fB\-\-window\-step=1\fR, then a cyclic hash across 65536 bytes will be stored at every 32768 bytes of input data\. If \fB\-\-window\-step=2\fR, then a hash value will be stored at every 16384 bytes\. This means that not every possible 65536\-byte duplicate segment will be detected, but it is guaranteed that all duplicate segments of (\fBwindow_size\fR + \fBwindow_step\fR) bytes or more will be detected (unless they span across block boundaries, of course)\. If you use a larger value for this option, the increments become \fIsmaller\fR, and \fBmkdwarfs\fR will be slightly slower and use more memory\. .TP \fB\-\-bloom\-filter\-size\fR=[\fIcategory\fR\fB::\fR]\fIvalue\fR The segmenting algorithm uses a bloom filter to determine quickly if there is \fIno\fR match at a given position\. This will filter out more than 90% of bad matches quickly with the default bloom filter size\. The default is pretty much where the sweet spot lies\. If you have copious amounts of RAM and CPU power, feel free to increase this by one or two and you \fImight\fR be able to see some improvement\. If your system is tight on memory, then decreasing this will potentially save a few MiBs\. .TP \fB\-L\fR, \fB\-\-memory\-limit=\fR\fIvalue\fR Approximately how much memory you want \fBmkdwarfs\fR to use during filesystem creation\. Note that currently this will only affect the block manager component, i\.e\. the number of filesystem blocks that are in flight but haven't been compressed and written to the output file yet\. So the memory used by \fBmkdwarfs\fR can certainly be larger than this limit, but it's a good option when building large filesystems with expensive compression algorithms\. Also note that most memory is likely used by the compression algorithms, so if you're short on memory it might be worth tweaking the compression options\. .TP \fB\-C\fR, \fB\-\-compression=\fR[\fIcategory\fR\fB::\fR]\fIalgorithm\fR[\fB:\fR\fIalgopt\fR[\fB=\fR\fIvalue\fR][\fB:\fR\|\.\|\.\|\.]] The compression algorithm and configuration used for file system data\. The value for this option is a colon\-separated list\. The first item is the compression algorithm, the remaining item are its options\. Options can be either boolean or have a value\. For details on which algorithms and options are available, see the output of \fBmkdwarfs \-\-help\fR\. \fBzstd\fR will give you the best compression while still keeping decompression \fIvery\fR fast\. \fBlzma\fR will compress even better, but decompression will be around ten times slower\. .TP \fB\-\-schema\-compression=\fR\fIalgorithm\fR[\fB:\fR\fIalgopt\fR[\fB=\fR\fIvalue\fR][\fB,\fR\|\.\|\.\|\.]] The compression algorithm and configuration used for the metadata schema\. Takes the same arguments as \fB\-\-compression\fR above\. The schema is \fIvery\fR small, in the hundreds of bytes, so this is only relevant for extremely small file systems\. The default (\fBzstd\fR) has shown to provide considerably better results than any other algorithms\. .TP \fB\-\-metadata\-compression=\fR\fIalgorithm\fR[\fB:\fR\fIalgopt\fR[\fB=\fR\fIvalue\fR][\fB,\fR\|\.\|\.\|\.]] The compression algorithm and configuration used for the metadata\. Takes the same arguments as \fB\-\-compression\fR above\. The metadata has been optimized for very little redundancy and leaving it uncompressed, the default for all levels below 7, has the benefit that it can be mapped to memory and used directly\. This improves mount time for large file systems compared to e\.g\. an lzma compressed metadata block\. If you don't care about mount time, you can safely choose \fBlzma\fR compression here, as the data will only have to be decompressed once when mounting the image\. .TP \fB\-\-history\-compression=\fR\fIalgorithm\fR[\fB:\fR\fIalgopt\fR[\fB=\fR\fIvalue\fR][\fB,\fR\|\.\|\.\|\.]] The compression algorithm and configuration used for the file system history\. Takes the same arguments as \fB\-\-compression\fR above\. Like the schema, history blocks are typically very small, so the default is the same as for schema compression\. This is irrelevant if \fB\-\-no\-history\fR is present\. .TP \fB\-\-recompress\fR[\fB=all\fR|\fB=block\fR|\fB=metadata\fR|\fB=none\fR] Take an existing DwarFS file system and recompress it using different compression algorithms\. If no argument or \fBall\fR is given, all sections in the file system image will be recompressed\. Note that \fIonly\fR the compression algorithms, i\.e\. the \fB\-\-compression\fR, \fB\-\-schema\-compression\fR and \fB\-\-metadata\-compression\fR options, have an impact on how the new file system is written\. Other options, e\.g\. \fB\-\-block\-size\-bits\fR or \fB\-\-order\fR, have no impact\. If \fBnone\fR is given as an argument, none of the sections will be recompressed, but the file system is still rewritten in the latest file system format\. This is an easy way of upgrading an old file system image to a new format\. If \fBblock\fR or \fBmetadata\fR is given, only the block sections (i\.e\. the actual file data) or the metadata sections are recompressed\. This can be useful if you want to switch from compressed metadata to uncompressed metadata without having to rebuild or recompress all the other data\. .TP \fB\-\-recompress\-categories=\fR[\fB!\fR]\fIcategory\fR[\fB,\fR\|\.\|\.\|\.] When \fB\-\-recompress\fR is set to \fBall\fR or \fBblock\fR, this option controls which categories of blocks will be recompressed\. Adding a \fB!\fR in front of the list allows you to specify which categories will \fInot\fR be recompressed\. .TP \fB\-P\fR, \fB\-\-pack\-metadata=auto\fR|\fBnone\fR|[\fBall\fR|\fBchunk_table\fR|\fBdirectories\fR|\fBshared_files\fR|\fBnames\fR|\fBnames_index\fR|\fBsymlinks\fR|\fBsymlinks_index\fR|\fBforce\fR|\fBplain\fR[\fB,\fR\|\.\|\.\|\.]] Which metadata information to store in packed format\. This is primarily useful when storing metadata uncompressed, as it allows for smaller metadata block size without having to turn on compression\. Keep in mind, though, that \fImost\fR of the packed data must be unpacked into memory when reading the file system\. If you want a purely memory\-mappable metadata block, leave this at the default (\fBauto\fR), which will turn on \fBnames\fR and \fBsymlinks\fR packing if these actually help save data\. Tweaking these options is mostly interesting when dealing with file systems that contain hundreds of thousands of files\. See \fIMetadata Packing\fR for more details\. .TP \fB\-\-set\-owner=\fR\fIuid\fR Set the owner for all entities in the file system\. This can reduce the size of the file system\. If the input only has a single owner already, setting this won't make any difference\. .TP \fB\-\-set\-group=\fR\fIgid\fR Set the group for all entities in the file system\. This can reduce the size of the file system\. If the input only has a single group already, setting this won't make any difference\. .TP \fB\-\-set\-time=now\fR|\fIiso\-8601\-string\fR|\fIunix\-timestamp\fR Set the time stamps for all entities to this value\. This can significantly reduce the size of the file system\. You can pass the string \fBnow\fR for the current time, an ISO 8601 string, or a unix timestamp (seconds since epoch)\. The ISO 8601 string supports a space character instead of the \fBT\fR between date and time and supports dashes as separators\. Seconds or the full time part may be omitted as long as this doesn't turn the whole string into a single number (i\.e\. \fB2008\-03\-17\fR is supported, but \fB20080317\fR is not)\. .TP \fB\-\-keep\-all\-times\fR As of release 0\.3\.0, by default, \fBmkdwarfs\fR will only save the contents of the \fBmtime\fR field in order to save metadata space\. If you want to save \fBatime\fR and \fBctime\fR as well, use this option\. .TP \fB\-\-time\-resolution=\fR\fIsec\fR|\fBsec\fR|\fBmin\fR|\fBhour\fR|\fBday\fR Specify the resolution with which time stamps are stored\. By default, time stamps are stored with second resolution\. You can specify "odd" resolutions as well, e\.g\. something like 15 second resolution is entirely possible\. Moving from second to minute resolution, for example, will save roughly 6 bits per file system entry in the metadata block\. .TP \fB\-\-chmod=\fR\fImode\fR[\fB,\fR\fImode\fR]\|\.\|\.\|\.|\fBnorm\fR Recursively changes the mode bits of all entries in the generated file system\. Accepts the same mode specifications as the \fBchmod\fR utility and additionally supports the \fBD\fR and \fBF\fR modifiers to limit a specification to directories or non\-directories\. As a special case, you can pass \fB\-\-chmod=norm\fR to "normalize" the permissions across the file system; this is equivalent to using \fB\-\-chmod=ug\-st,=Xr\fR\. .TP \fB\-\-order=\fR[\fIcategory\fR\fB::\fR]\fBnone\fR|\fBpath\fR|\fBrevpath\fR|\fBsimilarity\fR|\fBnilsimsa\fR[\fB:\fR\fIopt\fR[\fB=\fR\fIvalue\fR][\fB:\fR\|\.\|\.\|\.]] The order in which inodes will be written to the file system\. Choosing \fBnone\fR, the inodes will be stored in the order in which they are discovered\. With \fBpath\fR, they will be sorted asciibetically by path name of the first file representing this inode\. With \fBrevpath\fR, they will also be ordered by path name, but the path is being traversed from the leaf to the root, i\.e\. files with the same name will be sorted next to each other\. With \fBsimilarity\fR, they will be ordered using a simple, yet fast and efficient, similarity hash function\. \fBnilsimsa\fR ordering uses a more sophisticated similarity function that is typically better than \fBsimilarity\fR, but can be significantly slower to determine a good ordering\. However, the new implementation of this algorithm can be parallelized and will perform much better on huge numbers of files\. \fBnilsimsa\fR ordering can be tweaked by specifying \fBmax\-children\fR and \fBmax\-cluster\-size\fR\. In general, larger values for \fBmax\-cluster\-size\fR tend to result in better compression, but will slow down the algorithm quadratically\. There is no point in setting \fBmax\-cluster\-size\fR larger than the number of files in the input\. Unlike the old implementation, \fBnilsimsa\fR ordering is now completely deterministic\. See \fINilsimsa Ordering\fR for a detailed description of the algorithm\. .TP \fB\-\-max\-similarity\-size=\fR\fIvalue\fR Don't perform similarity ordering for fragments (or files if they are not split into fragments by a categorizer) larger than this size\. This helps speed up scanning, especially on slow file systems\. For large fragments, the gains from similarity ordering are relatively small\. When this option is set to a non\-zero value, fragments larger than the limit will be stored first, ordered by size in descending order\. .TP \fB\-F\fR, \fB\-\-filter=\fR\fIrule\fR Add a filter rule\. This option can be specified multiple times\. See \fIFILTER RULES\fR for more details\. .TP \fB\-\-debug\-filter\fR[\fB=all\fR|\fB=excluded\fR|\fB=excluded\-files\fR|\fB=files\fR|\fB=included\fR|\fB=included\-files\fR] Show the effect of the filter rules without creating a file system\. If no argument is passed to the option, all included/excluded files and directories are shown (same as with \fBall\fR)\. \fBfiles\fR will omit all directories\. \fBincluded\fR and \fBexcluded\fR will only show the corresponding set of files/directories\. \fBincluded\-files\fR and \fBexcluded\-files\fR work as before, but again omit all directories\. .TP \fB\-\-remove\-empty\-dirs\fR Removes all empty directories from the output file system, recursively\. This is particularly useful when using scripts that filter out a lot of file system entries\. .TP \fB\-\-with\-devices\fR Include character and block devices in the output file system\. These are not included by default, and due to security measures in FUSE, they will never work in the mounted file system\. However, they can still be copied out of the mounted file system, for example using \fBrsync\fR\. .TP \fB\-\-with\-specials\fR Include named fifos and sockets in the output file system\. These are not included by default\. .TP \fB\-\-header=\fR\fIfile\fR Read header from file and place it before the output filesystem image\. Can be used with \fB\-\-recompress\fR to add or replace a header\. .TP \fB\-\-remove\-header\fR Remove header from a filesystem image\. Only useful with \fB\-\-recompress\fR\. .TP \fB\-\-no\-section\-index\fR Don't add section index to file system\. The section index is usually tiny and is used to speed up mount times for large file systems, as it avoids a full scan through the file system blocks to figure out their location\. .TP \fB\-\-no\-history\fR Don't add any history information to a file system\. .TP \fB\-\-no\-history\-timestamps\fR Don't add timestamps to history entries\. This is necessary, along with \fB\-\-no\-create\-timestamp\fR, when trying to produce bit\-identical file system images\. .TP \fB\-\-no\-history\-command\-line\fR Don't record command line arguments in history entries\. .TP \fB\-\-no\-create\-timestamp\fR Don't add a creation timestamp\. This is useful when bit\-identical file system images are required to be produced from the same input\. .TP \fB\-\-file\-hash=none\fR|\fIname\fR Select the hashing function to be used for file deduplication\. If \fBnone\fR is chosen, file deduplication is disabled\. By default, the built\-in \fBXXH3\-128\fR hash is used\. This is not a secure hash function, but it is significantly faster\. The full list of supported hash function depends on the version of OpenSSL that the binary is linked against and is shown in the output of \fBmkdwarfs \-h\fR\. .TP \fB\-\-log\-level=\fR\fIname\fR Specifiy a logging level\. .TP \fB\-\-log\-with\-context\fR Enable logging context regardless of level\. By default, context is enabled if the level is \fBverbose\fR, \fBdebug\fR or \fBtrace\fR\. .TP \fB\-\-no\-progress\fR Don't show progress output while building filesystem\. .TP \fB\-\-progress=none\fR|\fBsimple\fR|\fBascii\fR|\fBunicode\fR Choosing \fBnone\fR is equivalent to specifying \fB\-\-no\-progress\fR\. \fBsimple\fR will print a single line of progress information whenever the progress has significantly changed, but at most once every 2 seconds\. This is also the default when the output is not a tty\. \fBunicode\fR is the default behaviour, which shows a nice progress bar and lots of additional information\. If your terminal cannot deal with unicode characters, you can switch to \fBascii\fR, which is like \fBunicode\fR, but looks less fancy\. .TP \fB\-\-incompressible\-min\-input\-size=\fR\fIvalue\fR The minimum size of a file to be checked for incompressibility when the \fBincompressible\fR categorizer is active\. .TP \fB\-\-incompressible\-block\-size=\fR\fIvalue\fR The block size used to test data for compressibility\. This will also be the size of the fragments when \fB\-\-incompressible\-fragments\fR is used\. .TP \fB\-\-incompressible\-fragments\fR Categorize individual fragments of a file as incompressible instead of only the file as a whole\. .TP \fB\-\-incompressible\-ratio=\fR\fIvalue\fR The ratio above which a file or fragment is categorized as \fBincompressible\fR\. .TP \fB\-\-incompressible\-zstd\-level=\fR\fIvalue\fR The ZSTD compression level used for incompressible categorization\. .TP \fB\-h\fR, \fB\-\-help\fR Show usage and the most common basic options\. .TP \fB\-H\fR, \fB\-\-long\-help\fR Show full usage with all options, including defaults, compression level detail and supported compression algorithms\. .TP \fB\-\-man\fR If the project was built with support for built\-in manual pages, this option will show the manual page\. If supported by the terminal and a suitable pager (e\.g\. \fBless\fR) is found, the manual page is displayed in the pager\. .SH "EXIT CODES" Upon successful completion, \fBmkdwarfs\fR will exit with exit code 0\. If an unrecoverable error occurs (i\.e\. no valid file system image has been produced), it will exit with exit code 1\. If any errors have occurred (e\.g\. not all input files could be read), the exit code will be 2\. .SH "CATEGORIZERS" Categorizers will inspect the input files in the scanning phase and try to assign them a category\. Each categorizer can define a set of categories, and each of these categories can optionally support subcategories\. .P Running \fBmkdwarfs\fR with the \fB\-H\fR or \fB\-\-long\-help\fR option will display the list of available categorizers and the categories they emit\. At the moment, \fBmkdwarfs\fR supports two categorizers, \fBincompressible\fR and \fBpcmaudio\fR\. The \fBincompressible\fR categorizer comes with its own set of options while the \fBpcmaudio\fR categorizer doesn't need any further configuration\. .P Categorizers are only useful if at least some of the \fBmkdwarfs\fR configuration is category\-dependent\. The options that can be configured per category are \fB\-\-compression\fR, \fB\-\-order\fR, \fB\-\-max\-lookback\-blocks\fR, \fB\-\-window\-size\fR, \fB\-\-window\-step\fR, and \fB\-\-bloom\-filter\-size\fR\. .P The resulting configuration matrix can be quite overwhelming, which is why \fBmkdwarfs\fR will run with a reasonable set of defaults if you specify the \fB\-\-categorize\fR option with no arguments\. These defaults are also dependent on the chosen compression level\. .P Note that in case of the \fBpcmaudio\fR categorizer, you can override each option per category (in this case \fBpcmaudio/waveform\fR and \fBpcmaudio/metadata\fR)\. .P It's also worth noting that the order in which the categorizers are given is important\. The first categorizer that will successfully categorize a file wins and, if possible, no other categorizers will run on the same file\. .SS "\"incompressible\" Categorizer" The \fBincompressible\fR categorizer will try to compress each input with a very fast compression algorithm (\fBzstd\fR using a negative compression level by default)\. If it turns out that this doesn't reduce the size of the input significantly, the input will be categorized as \fBincompressible\fR\. .P You can use the \fBincompressible\fR categorizer in two modes: whole\-file or fragmented categorization\. In the former, the whole input file will be categorized, whereas in the latter, each file can be further broken down into compressible and incompressible fragments\. The size of these fragments will be equal to the block size used for categorization\. .P It makes sense to use this categorizer as the last in a list of multiple categorizers\. Not only because it'll likely have the biggest overhead, but also because it can wrongly classify data as incompressible that can be compressed properly with a specialized algorithm (e\.g\. audio data)\. .SS "\"pcmaudio\" Categorizer" The \fBpcmaudio\fR categorizer can identify and categorize a wide range of uncompressed audio data such as \fB\.wav\fR, \fB\.aiff\fR and more obscure formats\. .P It produces two different categories: \fBpcmaudio/waveform\fR for the actual waveform data, and \fBpcmaudio/metadata\fR for all other data in the file such as the file header\. The \fBpcmaudio/waveform\fR category is again divided into many subcategories depending on the type of waveform data (e\.g\. number of channels, bit depth, byte order, etc\.)\. .P In order to efficiently compress \fBpcmaudio/waveform\fR data, a suitable compression algorithm must be selected for this category\. \fBmkdwarfs\fR currently supports \fBflac\fR compression, which offers the best ratio of compression speed and achievable compression ratio\. .P It is worth noting that options such as \fB\-\-window\-size\fR will operate on \fIsample\fR granularity instead of \fIbyte\fR granularity when processing \fBpcmaudio/waveform\fR data, where \fIsample\fR granularity means one sample for each channel\. For example, a 16\-bit stereo file would have a granularity of 4 bytes and thus \fB\-\-window\-size=10\fR would refer to a 4 KiB window instead of a 1 KiB windows\. .SH "TIPS & TRICKS" .SS "Compression Ratio vs Decompression Speed" If high compression ratio is your primary goal, definitely go for lzma compression\. However, I've found that it's only about 10% better than zstd at the highest level\. The big advantage of zstd over lzma is that its decompression speed is about an order of magnitude faster\. So if you're extensively using the compressed file system, you'll probably find that it's much faster with zstd\. .SS "Block, Schema and Metadata Compression" DwarFS filesystems consist of three distinct parts of data: A potentially large number of blocks, which store actual file data and are decompressed on demand, as well as one schema and one metadata section\. The schema is tiny, typically less than 1000 bytes, and holds the details for how to interpret the metadata\. The schema needs to be read into memory once and is subsequently never accessed again\. The metadata itself is compressed by default, but it doesn't have to be\. Actually, if you drop the compression level from 7 (the default) to 6, the only difference is that the metadata is left uncompressed\. This can be useful if mounting speed of the file system is important, as the uncompressed metadata part of the file can then simply be mapped into memory\. .SS "Metadata Packing" The filesystem metadata is stored in Frozen \fIhttps://github\.com/facebook/fbthrift/blob/master/thrift/lib/cpp2/frozen/Frozen\.h\fR, a library that allows serialization of structures defined in Thrift IDL \fIhttps://github\.com/facebook/fbthrift/\fR into an extremely compact representation that can be used in\-place without the need for deserialization\. It is very well suited for persistent, memory\-mappable data\. With Frozen, you essentially only "pay for what you use": if fields are defined in the IDL, but they always hold the same value (or are not used at all), not a single bit will be allocated for this field even if you have a list of millions of items\. .P Frozen metadata has relatively low redundancy and doesn't compress well, but you can still save around 30\-50% by enabling compression\. However, this means that upon reading the filesystem, you will first have to fully decompress the metadata block and keep it in memory\. An uncompressed block could simply be mapped into memory and would be instantly usable\. So, if e\.g\. mounting speed is a concern, it would make sense to disable metadata compression, in particular for large filesystems\. .P However, there are several options to choose from that allow you to further reduce metadata size without having to compress the metadata\. These options are controlled by the \fB\-\-pack\-metadata\fR option\. .TP \fBauto\fR This is the default\. It will enable both \fBnames\fR and \fBsymlinks\fR\. .TP \fBnone\fR Don't enable any packing\. However, string tables (i\.e\. names and symlinks) will still be stored in "compact" rather than "plain" format\. In order to force storage in plain format, use \fBplain\fR\. .TP \fBall\fR Enable all packing options\. This does \fInot\fR force packing of string tables (i\.e\. names and symlinks) if the packing would actually increase the size, which can happen if the string tables are actually small\. In order to force string table packing, use \fBall,force\fR\. .TP \fBchunk_table\fR Delta\-compress chunk tables\. This can reduce the size of the chunk tables for large file systems and help compression, however, it will likely require a lot of memory when unpacking the tables again\. Only use this if you know what you're doing\. .TP \fBdirectories\fR Pack directories table by storing first entry pointers delta\- compressed and completely removing parent directory pointers\. The parent directory pointers can be rebuilt by tree traversal when the filesystem is loaded\. If you have a large number of directories, this can reduce the metadata size, however, it will likely require a lot of memory when unpacking the tables again\. Only use this if you know what you're doing\. .TP \fBshared_files\fR Pack shared files table\. This is only useful if the filesystem contains lots of non\-hardlinked duplicates\. It gets more efficient the more copies of a file are in the filesystem\. .TP \fBnames\fR,\fBsymlinks\fR Compress the names and symlink targets using the fsst \fIhttps://github\.com/cwida/fsst\fR compression scheme\. This compresses each individual entry separately using a small, custom symbol table, and it's surprisingly efficient\. It is not uncommon for names to make up for 50\-70% of the metadata, and fsst compression typically reduces the size by a factor of two\. The entries can be decompressed individually, so no extra memory is used when accessing the filesystem (except for the symbol table, which is only a few hundred bytes)\. This is enabled by default\. For small filesystems, it's possible that the compressed strings plus symbol table are actually larger than the uncompressed strings\. If this is the case, the strings will be stored uncompressed, unless \fBforce\fR is also specified\. .TP \fBnames_index\fR,\fBsymlinks_index\fR Delta\-compress the names and symlink targets indices\. The same caveats apply as for \fBchunk_table\fR\. .TP \fBforce\fR Forces the compression of the \fBnames\fR and \fBsymlinks\fR tables, even if that would make them use more memory than the uncompressed tables\. This is really only useful for testing and development\. .TP \fBplain\fR Store string tables in "plain" format\. The plain format uses Frozen thrift arrays and was used in earlier metadata versions\. It is useful for debugging, but wastes up to one byte per string\. .P To give you an idea of the metadata size using different packing options, here's the size of the metadata block for the Ubuntu 20\.04\.2\.0 Desktop ISO image\. There are just over 200,000 files in this image\. The ZSTD and LZMA columns show to what fraction it is possible to reduce the metadata size by additional compression\. That fraction is relative to the corresponding packing option\. .IP "" 4 .nf \-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\- Packing | Metadata Size | Relative | ZSTD | LZMA \-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\- auto | 5,301,177 | 100\.00% | 57\.33% | 49\.29% all | 4,952,859 | 93\.43% | 50\.46% | 46\.45% none | 6,337,294 | 119\.55% | 47\.70% | 41\.37% plain | 6,430,275 | 121\.30% | 48\.36% | 41\.37% \-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\- .fi .IP "" 0 .P So, the default (\fBauto\fR) is roughly 20% smaller than not using any packing (\fBnone\fR or \fBplain\fR)\. Enabling \fBall\fR packing options doesn't reduce the size much more\. However, it \fIdoes\fR help if you want to further compress the block\. So, if you're really desperately trying to reduce the image size, enabling \fBall\fR packing would be an option at the cost of using a lot more memory when using the filesystem\. .SS "Producing bit\-identical images" By default, images produced by \fBmkdwarfs\fR will not be identical over multiple runs\. This is due to time stamps that are being added to the file system image\. .P In order to produce bit\-identical images, you need to pass \fB\-\-no\-create\-timestamp\fR and either \fB\-\-no\-history\-timestamps\fR or \fB\-\-no\-history\fR\. .SH "FILTER RULES" The filter rules have been inspired by the \fBrsync\fR utility\. These look very similar, though there are differences\. These rules are quite powerful, yet they're somewhat hard to get used to\. .P There are only 3 different kinds of rules: .TP \fB+\fR\fIpattern\fR An "include" rule\. .TP \fB\-\fR\fIpattern\fR An "exclude" rule\. .TP \fB\.\fR\fIfile\fR A merge file rule\. Rules are read (recursively) from the specified file\. .P Ultimately, only include and exclude rules remain in the rule set as file rules are merged in at the place where they occur\. .P The most important rule to remember when building a rule set is that all rules are applied strictly in order and processing stops at the first matching rule\. If no rules match, the default is to include the entry\. .P Patterns can be anchored or floating\. Anchored patterns are patterns that start with a \fB/\fR\. These patterns match relative to the file system root (i\.e\. the \fB\-\-input\fR path)\. Floating patterns match in any directory in the hierarchy\. .P Patterns ending with a \fB/\fR only match directories\. All other patterns only match non\-directories\. .P Note that regardless of the preferred native directory separator, filter rules will always use UNIX\-style directory separators (\fB/\fR)\. The only exception is the root path component in floating matches, which will always use native directory separators\. .P Patterns support \fB?\fR and \fB*\fR wildcards matching a single character and any number of characters, respectively\. These patterns don't match across directory separators (\fB/\fR)\. .P Patterns also support the \fB**\fR wildcard, which matches across directory separators\. .P Patterns also support character classes\. .P Here's an exemplary rule set: .IP "" 4 .nf + File/Spec/[EM]*\.pm \- unicore/**\.pl + *\.pl \- * .fi .IP "" 0 .P This set of rules will include all files matching \fBFile/Spec/[EM]*\.pm\fR anywhere in the hierarchy\. It will also include all \fB*\.pl\fR files, except for those anywhere below a \fBunicore\fR directory\. The last rule excludes all other files\. .P This will likely leave a lot of empty directories around, but these can be removed using \fB\-\-remove\-empty\-dirs\fR\. .P You can use the \fB\-\-debug\-filter\fR option to show the sets of included and excluded files without building an actual file system\. .SH "INTERNAL OPERATION" Internally, \fBmkdwarfs\fR runs in two completely separate phases\. The first phase is scanning the input data, the second phase is building the file system\. Both phases try to do as little work as possible, and try to run as much of the remaining work as possible in parallel, while still making sure that the file system images produced are reproducible (see the \fB\-\-order\fR option documentation for details on reproducible images)\. .SS "Scanning" The scanning process is driven by the main thread which traverses the input directory recursively and builds an internal representation of the directory structure\. Traversal is breadth\-first and single\-threaded\. Filter rules as specified by \fB\-\-filter\fR are handled immediately during traversal\. .P When a regular file is discovered, its hardlink count is checked and if greater than one, its inode is looked up in a hardlink cache\. Another lookup is performed to see if this is the first file/inode of a particular size\. If it's the first file, we just keep track of the file\. If it's not the first file, we add a job to a pool of \fB\-\-num\-scanner\-workers\fR worker threads to compute a hash (which hash function is used is determined by the the \fB\-\-file\-hash\fR option) of the file\. We also add a hash\-computing job for the first file we found with this size earlier\. These hashes will then be used for de\-duplicating files\. If \fB\-\-order\fR is set to one of the similarity order modes, for each unique file, a further job is added to the pool to compute a similarity hash\. This happens immediately for each inode of a unique size, but it is guaranteed that duplicates don't trigger another similarity hash scan (the implementation for this is actually a bit tricky)\. .P Once all file contents have been scanned by the worker threads, all unique files will be assigned an internal inode number\. .P This behaviour can be customized\. When using \fB\-\-file\-hash=none\fR, de\-duplication is completely disabled\. Using \fB\-\-max\-similarity\-size\fR, it is possible to prevent computation of similarity hashes for huge files\. These huge files will then be stored separately before all other files in the image\. .SS "Building" Building the filesystem image uses a \fB\-\-num\-workers\fR separate threads\. .P If \fBnilsimsa\fR ordering is selected, the ordering algorithm runs in its own thread and continuously emits file inodes\. These will be picked up by the segmenter thread, which scans the inode contents using a cyclic hash and determines overlapping segments between previously written data and new incoming data\. The segmenter will look at up to \fB\-\-max\-lookback\-blocks\fR previous filesystem blocks to find overlaps\. .P Once the segmenter has produced enough data to fill a filesystem block, the block is added to a queue where from which the blocks will be picked up by a pool of \fB\-\-num\-workers\fR worker threads whose only job is to compress the block using the \fB\-\-compression\fR algorithm\. .P Blocks that have been compressed will be added to the next queue, in the original order, and will be picked up by the filesystem writer thread that will ultimately produce the final filesystem image\. .P When all data has been segmented, the filesystem metadata is being finalized and frozen into a compact representation\. If metadata compression is enabled, the metadata is sent to the worker thread pool for compression\. .P When using different ordering schemes, the file inodes will be either sorted upfront, or just sent to the segmenter in the order in which they were discovered\. .SS "Nilsimsa Ordering" The actual ordering step for nilsimsa ordering uses a recursive divide\-and\-conquer approach in order for the algorithm to be both parallelizable and deterministic\. In the following description, a "node" is typically equivalent to a "unique file", although that's not a requirement for the algorithm\. .IP "1." 4 Nodes are clustered by distance to centroids into up to \fBmax\-children\fR clusters\. With \fBmax\-children\fR set to 1, all nodes end up in the same cluster\. If \fBmax\-children\fR is larger than 1, a new cluster is created as soon as all existing clusters are further away than a "maximum distance" that gets smaller as recursion depth increases\. .IP "2." 4 After the nodes have been clustered, each cluster that is larger than \fBmax\-cluster\-size\fR is recursively clustered again with a smaller "maximum distance" as per (1)\. These recursive clustering steps can potentially run in parallel\. .IP "3." 4 As soon as a cluster is smaller than \fBmax\-cluster\-size\fR, its nodes will be ordered by performing a nearest neighbour search\. Note that this only happens for leaf clusters in the tree\. The ordering of each leaf cluster can also run parallel with clustering / ordering of other clusters\. .IP "4." 4 Once all clustering / ordering is done, the nodes are "collected" from the clusters in the tree\. There is currently no similarity ordering between individual clusters, but this is something that can be explored further in the future\. .IP "" 0 .P By setting \fBmax\-children\fR to 1 and \fBmax\-cluster\-size\fR to a really large number, only a single cluster will be created and the nearest neighbour search will be performed on the set of all nodes\. Since the algorithm is O(n^2), this does not scale well for \fBmax\-cluster\-size\fR beyong a few 100,000\. Also, since the algorithm does not minimize the global distance between all nodes, there's no guarantee that the result will be better if you use only a single cluster\. .SH "AUTHOR" Written by Marcus Holland\-Moritz\. .SH "COPYRIGHT" Copyright (C) Marcus Holland\-Moritz\. .SH "SEE ALSO" dwarfs(1), dwarfsextract(1), dwarfsck(1), dwarfs\-format(5)